last update: 2009-05-01 04:55:14 GMT This book is a work in progress; feel free to contribute.
Reference website: http://rspec.info
RSpec is a Behavior Driven Development1 (BDD) framework for Ruby. It provides two frameworks for writing and executing examples of how your Ruby application should behave2:
RSpec was influenced by Dan North and his Java-based BDD testing framework called JBehave.
Initially, BDD was just a discussion between Aslak Hellesøy and Dan North in the ThoughtWorks London office. Dave Astels joined the conversation with a blog post, suggestinging that these ideas could be easily implemented in Smalltalk or Ruby. Steven Baker jumped in with an initial implementation, released as RSpec 0.1. Later in 2006, maintenance was handed over to David Chelimsky.4
Behavior Driven Development is an Agile development process that incorporates aspects of Acceptance Test Driven Planning, Domain Driven Design, and Test Driven Development.
Behaviour-driven development is an “outside-in” methodology. It starts at the outside by identifying business outcomes, and then drills down into the feature set that will achieve those outcomes. Each feature is captured as a “story”, which defines the scope of the feature along with its acceptance criteria. - Dan North
By focusing on the expected behaviors rather than the technical details, developers can have better communication with the project owner and other stakeholders.
RSpec is a Domain-Specific Language (DSL) for describing the expected behavior of a system, using a collection of executable examples.
Here is a very simple RSpec example.
describe "Reader" do
it "should have a browser" do
reader = Reader.new
reader.browser.should_not be_nil
end
end