Skip to content

Instantly share code, notes, and snippets.

@andyl
Created March 21, 2011 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyl/878911 to your computer and use it in GitHub Desktop.
Save andyl/878911 to your computer and use it in GitHub Desktop.
# test2_spec.rb - call using 'rspec test2_spec.rb'
require 'rspec'
class Test2
attr_accessor :msg
def initialize
@msg = sayhi
end
def sayhi
"hi"
end
end
describe Test2, "stubbing methods used during object construction" do
it "should assign the stub value to the instance variable" do
Test2.stub!(:sayhi).and_return("bye")
Test2.new.msg.should == "bye"
end
end
describe Test2, "stubbing methods after the object is created" do
it "should redefine the return value of a stubbed method" do
obj = Test2.new
obj.stub!(:sayhi).and_return("bye")
obj.sayhi.should == "bye"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment