This document provides an overview of RSpec, a testing framework for Ruby. It discusses key RSpec concepts like describe/it blocks for defining example groups and examples, expectations for specifying expected behavior, matchers for making assertions, and mocks for isolating tests from other systems. It also covers RSpec features like before/after hooks, helper methods, nested groups, auto-generated descriptions, and integration with Rails applications.
7. expectation
An expression of how an object is expected to
behave
code example
An executable example of how the code can be
used, and its expected behaviour (expressed with
expectations) in a given context
example group A group of code examples
spec or spec file A file contains one or more example groups
Rspec
8. Test::Unit Rspec
class DogTest describe Dog
def test_bark It 'should bark'
assert_xxx object.should_be xxx
def setup before(:each) {}
def teardown dfter(:each){}
Rspec
12. Before and After
before
grouping?things?by?initial?state
?before(:each){}?executed?before?executing?every?
example
before(:all){}?executed?before?executing?all?the?
examples?in?the?example?group
after
?after(:each){}?executed?after?executing?every?example
?after(:all){}?executing?after?executing?all?the?examples?
in?the?example?group
13. Before and After
useful?to?remove?duplicates
improving?the?clarity
making?the?examples?easier?to?understand