ruby - Alternative to rspec double that does not fail test even if allow receive is not specified for a function -
many times 1 outcome may have 2 different consequences need tested test double. example if network connection successful i'd log message, , pass resource object store internally. on other hand feels unclean put these 2 in 1 test. example code fails:
describe someclass let(:logger) { double('logger') } let(:registry) { double('registry') } let(:cut) { someclass.new } let(:player) { player.new } describe "#connect" context "connection successful" "should log info" logger.should_receive(:info).with('player connected successfully') cut.connect player end "should register player" registry.should_receive(:register).with(player) cut.connect player end end end end
i specify in each test function in other 1 might called, looks unnecessary duplication. in case i'd rather make 1 test.
i don't it's never explicit in test method should not called.
does know alternative has explicit 'should_not_receive' message instead of automatically rejecting calls not explicitly specified?
rspec supports should_not_receive
, equivalent should_receive(...).exactly(0).times
discussed in this message original author of rspec.
Comments
Post a Comment