Tuesday 15. of January 2008
Tags:agile, BDD, code, RSpec, Ruby on Rails     By:  Posted in BDD, Ruby

I am new to Behavior Driven Development (BDD) but the concept is rapidly growing on me. With my recent love of agile development I am constantly looking for better, faster ways to code and create new applications. After the release of Rails 2.0 I decided it was time to investiage RSpec and what it had to offer for agile development. RSpec has recently release version 1.1.1 which is designed to coincide with Rails 2.0.

In that past I have mainly resorted to testing in a methodic fashion by hand. Basically I had to alot just as much time for QA if not more. With RSpec, I should be able to decrease the QA time drastically. BDD is a refined version of unit testing. With BDD the idea is to write the tests first, and then implement code to make the tests pass as true. This is a fantastic solution to the testing process.

RSpec Breaks down into a few step

  1. Write a behavior(test) - This will describe what the code should do
  2. Run the behavior test - The test will fail at this point as you have not yet written the code and verifies that the test is valid as it should fail with no code to go with it.
  3. Write code to make the behavior test pass as true but not a line more.
  4. Run the behavior tests again and verify the tests pass.

The key to proper BDD is to write only as much code as is necessary to pass the behavior test, helping to keep the codebase clean and to ensure that the test passes properly. Refactoring Code:

If an application utilizes BDD testing it will enable developers much is ease in cleaning up the code base. Every time they want to refactor and cleanse the code they can run the tests to ensure that they have not damaged the application in any ways. Unit Testing Arguments

Unit testing a vague method that has been used int eh past and its a term that puts some coders off. It often signifies to them some division of code that requires test classes or test methods. What we really need to be testing are behaviors that match the user stories for the application. Unit test can have a negative connotation and lead coders/developers often think that “we don’t need to write tests“, ” testing this early is a waste of time“, or “this something simple, why test it?”

RSpec and BDD are here to break these negative connotations and to hopefully provide to be useful. BDD is about testing on a smaller scale and implementing code after each and every behavior has been written. This will also help write good code as you will be familiar with the behavior for which the code is solving for. Put Simply:

RSpec is fantastic way to implement Behavior Driven Development for Ruby on Rails swiftly and effectively and I strongly urge developers to implement its use immediately.

You can leave a trackback from your own site.
Sorry, comments are closed for this post.