I have the following code
开发者_开发知识库class SomeClass
def initialize(opts)
if opts[:should_load]
load
else
setup(opts[:path])
end
end
def load; end
def setup; end
end
And I want to test that the appropriate method is being called, but I cannot figure out how to do this with RSpec. Any tips?
Play with Object#any_instance
(rspec >= 2.6.0):
SomeClass.any_instance.should_receive(:load)
SomeClass.new(:should_load => true)
SomeClass.any_instance.should_receive(:setup).with("mypath")
SomeClass.new(:path => "mypath")
精彩评论