Skip to content

Instantly share code, notes, and snippets.

@RobertDober
Created November 23, 2010 15:13
Show Gist options
  • Save RobertDober/711904 to your computer and use it in GitHub Desktop.
Save RobertDober/711904 to your computer and use it in GitHub Desktop.
We are setting an instance variable in a stub, easy but a little bit doubtful.
# This is an adapted example from http://relishapp.com/rspec/rspec-mocks/v/2-1/dir/stubs/stub-with-substitute-implementation
describe "a stubbed implementation" do
it "works" do
object = Object.new
object.stub(:foo) do |arg|
if arg == :set then
@x = 42
elsif arg == :inc
@x += 1
end
end
object.foo(:set).should == 42
object.foo(:inc).should == 43
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment