Juan Pablo Genovese wrote:
> Buy "The RSpec Book" from Pragmatic. It's outstanding, and will give you
> extremely useful insight on TDD and BDD.

Take this really simple example of a spec (test) from "The RSpec Book."


greeter_spec.rb
----------------------------
describe "RSpec Greeter" do
  it "should say 'Hello RSpec!' when it receives the greet() message" do
    greeter = RSpecGreeter.new
    greeting = greeter.greet
    greeting.should == "Hello RSpec!"
  end
end
----------------------------

Now run that file with:

spec greeter_spec.rb

Obviously it will fail. There is no code to implement RSpecGreeter 
class. You now have a successful failure. Failure is what you expected 
at this point.

You are now at "Red."

You're next goal is to get to "Green." You do that by implementing just 
enough code to make the above spec pass. This involves creating the 
RSpecGreeter class and implementing a "greet" method that returns the 
string "Hello RSpec!" This is exactly what the spec says to implement. 
Nothing more, nothing less.

Now run the spec again, which should now pass. You are at "Green."

Next step is "Refactor." This is your opportunity to review the code you 
wrote and clean it up by removing duplication, improving formatting, 
etc. You can now do that refactoring with confidence because you have 
the spec that will tell you if you've broken anything, according to the 
specified requirement.

The next step in the process is to get back to "Red" by writing another 
spec (or test).

This is a basic BDD cycle. Keep repeating this cycle until you can't 
think of any more specs to write. At that point you should have 
something to release (or at least be able to complete a feature story).
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to