Write tests to test functionality you’re pretty confident works because you’ve been using it for awhile without tests. This is a good way to learn because, if a test fails, it’s apt to be due to your test and not your code. Try to write as many cases as you can to test as many nuances...
That said, early Rails books and tutorials focused more on speed (build a blog in 15 minutes!) than on good practices like testing. If testing were covered at all, it was generally reserved for a chapter toward the end. Newer works on Rails have addressed this shortcoming, and now dem...
If you’ve been using Reek to help in refactoring your Rails applications , you might run across warnings of Irresponsible Modules — that is, code with no comments to help explain what it does. A common knock on the Rails community is that we don’t document our code. I hate to admit it...
Everyday Rails Testing with RSpec: Updates for April, 2013 April 24, 2013 Last week I released another round of updates to Everyday Rails Testing with RSpec , and subsequently released a couple of minor updates since. For those of you who may have missed it: This is it, the final upda...
Diary of a Rails rescue project, part 2: Testing April 16, 2013 As mentioned previously , I’ve been spending spare cycles getting an outdated Rails application up to speed. Aside from the outdated versions of Rails and pretty much every gem used by the app, there’s a glaring problem: ...
Rescue projects are unique challenges. Chances are, you’re working with someone else’s code. (Or maybe you’re working with your own code, but it’s been so long you don’t remember the work or it represents a former self’s skill set.) If a project hasn’t been touched in awhile, you may ...
Everyday Rails Testing with RSpec, the book now covers Capybara 2.0, RSpec's new syntax, and more February 13, 2013 Hey everyone, thanks again to all of you who have purchased Everyday Rails Testing with RSpec . I hope it’s gotten you on your way to better-tested apps. Sales have been...
The Rails ecosystem moves quickly–too quickly, some might say–and as a result a given library’s API from just a few months ago may be deprecated today–or worse, it may just no longer work. Running bundle install with the Gemfile as-is, I could get gem versions that are no longer compa...
Behind the scenes, I’ve built a simple little blogging application with an articles scaffold and an authentication system. See Authentication from Scratch (Revised) from Railscasts (subscription required) to see the basic approach I followed to set up logins for the application. One p...
I actually got started by learning how to create generators in Rails 3 (used to create custom code in an existing Rails application), then extended that to Rails templates (used to create new Rails applications, pre-baked with my favorite gem installations and other tweaks). The best ...
I live in a town dominated by Python, PHP , and Java developers, so hiring someone who can come in and write Ruby code from day one is a challenge. I’ve been thinking about how I learned Ruby myself, how I’ve gone about helping others learn it, and what I would do differently if I had...
Everyday Rails Testing with RSpec: The Book is complete June 13, 2012 On Monday I posted the final, edited version of Everyday Rails Testing with RSpec , available now on Leanpub for $9 US. First, let me again thank everyone who purchased the early access, beta version of the book. I ...
? I mean it’s not done yet, but I wanted to go ahead and get the book out there for people to start reading. (If you’ve ever purchased a beta book from Pragmatic Programmers you know what I’m talking about.) I’ve got updated versions of the original RSpec articles from this blog in pl...
Rails authentication today: Options for 3.0 and 3.1 September 21, 2011 Early on in Everyday Rails , I outlined three options for adding authentication to your Rails applications . It’s still a popular subject—and with two major releases of Rails and a number of new authentication opti...
Keep it simple: If you don’t get request specs right away, don’t worry about it. They require some additional setup and thinking to not just work, but actually test what you need to test. Don’t stop testing your models and controllers, though—building skills at that level will help yo...
lets you call methods on an object without having to worry about the possibility of that object being nil and thus raising an exception. I know I sometimes forget about it, and I’ve looked at enough code from other developers to know that I’m not the only one. So today I’d like to giv...
If you’re just getting into Ruby or Rails now, and looking for some light reading, you’re in luck. Publishers like the Pragmatic Programmers, O’Reilly, Manning Publications, and others have tons of books available to help you learn. You could easily spend a few hundred dollars buildin...
Controllers are models too, as Piotr Solnica indicated in an excellent blog post . And in Rails applications, they’re pretty important models—so it’s a good idea to put them on equal footing, spec-wise, as your Rails models. Controller specs can be written more quickly than their inte...
I won’t spend a lot of time bad-mouthing fixtures—frankly, it’s already been done. Long story short, there are two issues presented by fixtures I’d like to avoid: First, fixture data can be brittle and easily broken (meaning you spend about as much time maintaining your test data as y...
How I learned to test my Rails applications, Part 1: Introduction March 12, 2012 Ruby on Rails and automated testing go hand in hand. Rails ships with a built-in test framework; if it’s not to your liking you can replace it with one of your liking (as I write this, Ruby Toolbox lists ...
To start, I recommend reading through Jarod Santo’s excellent introduction to using jQuery Mobile with Rails 3 . It goes through the steps of integrating the mobile framework into a standard CRUD scaffold. However, to make your app both mobile and desktop-savvy, you’ll probably want t...
Everyday Rails is about using the Ruby on Rails web application framework to get stuff done as a web developer. Learn more. More advice on legacy data migration in Rails What do you do if your legacy data defies convention or is just generally complex? Here are some notes from my rece...
Moving from beginner to intermediate Rails development July 05, 2010 I believe that Rails is an excellent way to get started on server-side web development. The framework provides a good structure that’s easy to understand, and provided you follow some fairly basic rules, you can have...