Created
March 21, 2011 04:33
-
-
Save andyl/879029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# test2_spec.rb - call using 'rspec test2_spec.rb' | |
require 'rspec' | |
require 'mocha' | |
RSpec::configure do |config| | |
config.mock_with :mocha | |
end | |
class Test2 | |
attr_accessor :msg | |
def initialize | |
@msg = sayhi | |
end | |
def sayhi | |
"hi" | |
end | |
end | |
describe Test2 do | |
describe Test2, "stubbing methods used during object construction" do | |
it "should assign the stub value to the instance variable" do | |
Test2.any_instance.stubs(:sayhi).returns("first") | |
Test2.new.msg.should == "first" | |
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.stubs(:sayhi).returns("second") | |
obj.sayhi.should == "second" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment