views:

992

answers:

3

Everyone is talking about TDD (BDD) in Rails (and not just Rails) development world today. It's easy to find plenty of good general information about it, there are quite a few tools you can use for this purpose and there are many (good) examples of how to use them.

Now, I'm already on the train. I like the idea (never did TDD before) and I decided to go for Shoulda (because it seems to me quite easy to understand). I read plenty of examples and have done some first tests. My problem is this: I'm just not sure if I'm doing it right. As I said, there are many tiny examples all over the net, but I haven't found any comprehensive guide covering overall workflow of TDD with Shoulda.

Here are my questions:

  • What is your way of practising TDD with Shoulda? (What is your usual workflow throughout one iteration?)
  • What other tools do you use (except of Shoulda itself)?
  • Any other tips?
+2  A: 

I'm using RSpec instead of shoulda, (although I believe that shoulda can be used with RSpec) and the biggest improvement to my workflow has come from using Autotest and then RSpactor.

These tools automatically monitor your source tree for changes and execute the relevant tests if update either the test or implementation file. A pretty small change to the testing practice but the immediate feed back has increased my discipline in writing tests for every piece of functionality.

derfred
"autotest" is now "autospec" with recent RSpec versions.
Christian Lescuyer
+2  A: 

+1 for Autotest.

If you have a large test suite and only want to run the test you are working on (as opposed to the whole test suite) check out this monkey patch for Autotest.

As for other tools you should check out Factory Girl as a fixtures replacement.

Most of what I know about using Shoulda came by reading others test code. Check out some of Thoughtbot's projects on github, such as Clearance and Pacecar.

Mike Breen
A: 

I totally agree that there is a significant gap in the rails BDD documentaion. Lots of little examples but no big ones giving an overall picture of how to do it. Even the books that have chapters on testing are guilt of this. The only full examples I have seen are peepcode's three part screencast on rspec and a video on confreaks about flex mock.

I'd love to hear about other good resources on BDD that go beyond minor examples of syntax and I'd really like see a book on the topic.

srboisvert