Frankly when I heard about BDD (Behavior Driven development) I did not believe in it. OK whats BDD? Lets see about it. Below is a diagram of an agile development methodology.
Here (in Rails) we hear the client’s blah blah and then we immediately offer him a prototype and get his feed back. That is we code, we test it to our satisfaction and give it to the client. To know more about Rails testing click here. But the problem here is we might leave off some test cases which might not be caught by us till the last day when we have embarrassing failure. Its here where we have this BDD pop in.
In BDD we use some methodology where we make (almost) sure that there are no bugs in our code. For behavior driven development the image is as shown
Note that in this diagram, the thumb pin has moved from development to test. Here in BDD we write stories first. That is what the client wants to have in the software. Next we write test cases, in which we write code that would test our application. but wait, we haven’t stared our application yet!! ( SOUNDS CRAZY EH?) Then we run the code and watch all test cases fail (lol, the people who made BDD must be nuts). Then comes the magic, the developer writes code to make the tests pass one by one. So when the developer finishes coding he would have tested everything that should have been tested.
Rails itself is a disciplined way to use Ruby for web development and Behavior Driven Development adds another safety net. Though it takes time, I strongly feel its worth it and any Rails consultant should encourage it.
To know more visit Cucumber , a way to do BDD.
And read this excellent book : Rails in Action