Created
September 26, 2012 13:28
-
-
Save deepak/3788035 to your computer and use it in GitHub Desktop.
contrived example to show that at_least(0) does not work
This file contains 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
# contrived example to show that at_least(0) does not work | |
require 'rspec/mocks' | |
class DevOps | |
attr_reader :monitor | |
def initialize | |
@monitor = Monitor.new | |
end | |
def check | |
monitor.ping('DS1') | |
end | |
def noop | |
end | |
end | |
class Monitor | |
def ping(name) | |
"pong #{name}" | |
end | |
end | |
describe DevOps do | |
let(:devops) { DevOps.new } | |
let(:proxy) do | |
mock = mock('Monitor') | |
mock.should_receive(:ping).with('DS1').and_return(stub.as_null_object) | |
mock | |
end | |
# TODO: does not work | |
# let(:proxy) { mock('Monitor').should_receive(:ping).with('DS1').and_return(stub.as_null_object) } | |
# it "#monitor called" do | |
# # proxy is asserted even though it is not returned anywhere | |
# proxy = mock('Monitor').should_receive(:ping).with('DS1').and_return(stub.as_null_object) | |
# devops.should_receive(:monitor).and_return(stub.as_null_object) | |
# devops.check | |
# end | |
it "#monitor called", :wip => true do | |
# DevOps.any_instance | |
devops.should_receive(:monitor).and_return(proxy) | |
devops.check | |
end | |
it "#monitor not called" do | |
#DevOps.any_instance.should_receive(:monitor).any_number_of_times.and_return(proxy) | |
# TODO: at_least(0) does not work | |
devops.should_receive(:monitor).at_least(0).and_return(proxy) | |
devops.noop | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment