views:

249

answers:

3

I just get started using BDD in Rails application, but I'm not sure what are best practices and workflows? And what other things that I really need for testing for my project such as step definitions, controllers, models, and views? Do I need to test all of those?

+3  A: 

I generally think of Cucumber as a way to do integration testing on your application. Combined with Webrat, you can test user workflows, views and so on in a great way. For unit tests, you'll want to go down to a lower level and test your models just with rspec. You may also want to do some functional tests on the controllers, and I probably wouldn't use Cucumber for that either.

Here are a couple of videos:

dylanfm
+1  A: 

This may be a matter of taste, but having tried out Rspec I prefer using the built-in Rails testing framework along with a gem called Shoulda. In my opinion, that combination lets you write much clearer, more succinct and understandable tests than Rspec by far. But not everyone would agree.

Shoulda's contexts let you organize your tests into logical hierarchies which really helps when you're trying to test all the possible paths some crazy, branching situation, like user logs in with right pw, wrong pw, right pw but registration not confirmed, etc.

In addition be sure to install the ZenTest gem. That lets you just execute the command $ autotest and your tests will run automatically every time you change a file.

Ethan
+2  A: 

Ryan Bates has some good Railscasts on these topics:

John Topley