RR
RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. xunitpatterns.com/Test%20Double.html
Currently RR implements mocks, stubs, and probes. It is a goal of RR to support a wide range of double techniques and patterns.
Mocking
xunitpatterns.com/Mock%20Object.html
view = controller.template
mock(view).render(:partial => "user_info") {"Information"}
Stubbing
xunitpatterns.com/Test%20Stub.html
jane = User.new
stub(User).find('42') {jane}
mock(jane).valid? {true}
Probing
Add verifications that a method was called while actually calling it. The following example verifies render partial will be called and renders the partial.
view = controller.template
probe(view).render(:partial => "user_info")
Block Syntax
script = MyScript.new
mock(script) do |m|
m.system("cd #{RAILS_ENV}") {true}
m.system("rake foo:bar") {true}
m.system("rake baz") {true}
end
Terse Syntax
One of the goals of RR is to make doubles more scannable. This is accomplished by removing words from a double declaration. Here is RR compared to other mock frameworks:
flexmock(User).should_receive(:find).with('42').and_return(jane) # Flexmock
User.should_receive(:find).with('42').and_return(jane) # Rspec
User.expects(:find).with('42').returns {jane} # Mocha
mock(User).find('42') {jane} # RR