Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tag: v2.4.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
README.md
simple_return_value.feature
stub_chain.feature
stub_implementation.feature

README.md

We're working on improving these docs. In the mean time, here's a cheat sheet to cover the basics.

# create a double
obj = double()

# stub a method
obj.stub(:message) # returns obj

# specify a return value
obj.stub(:message) { 'this is the value to return' }

Argument constraints

Explicit arguments

obj.stub(:message).with('an argument')
obj.stub(:message).with('more_than', 'one_argument')

Argument matchers

obj.stub(:message).with(anything())
obj.stub(:message).with(an_instance_of(Money))
obj.stub(:message).with(hash_including(:a => 'b'))

Regular expressions

obj.stub(:message).with(/abc/)

Raising/Throwing

obj.stub(:message) { raise "this error" }
obj.stub(:message) { throw :this_symbol }

Arbitrary handling

obj.stub(:message) do |arg1, arg2|
  # set expectations about the args in this block
  # and set a return value
end
Something went wrong with that request. Please try again.