I’m new using rspec, so please forgive me if I’m barking up the wrong
tree, but…
I’d expect this to pass (using rspec 2.5.1)
describe ‘stub_chain’ do
it “returns expected value from two chains with hash” do
subject = Object.new
subject.stub_chain(:msg1, :msg2 => :first)
subject.stub_chain(:msg1, :msg3 => :second)
subject.msg1.msg2.should equal(:first)
subject.msg1.msg3.should equal(:second)
end
end
But it doesn’t - subject.msg1.msg3 returns nil
I think this is because in stub_chain (in
rspec-mocks/lib/rspec/mocks/methods.rb, line 43) there is
if matching_stub = __mock_proxy.send(:find_matching_method_stub,
chain[0].to_sym)
chain.shift
matching_stub.invoke.stub_chain(*chain)
else
ie blk isn’t used in any way. Changing this to
matching_stub.invoke.stub_chain(*chain, &blk) makes my example pass
Is this true or am I just misusing rspec?
I’m new using rspec, so please forgive me if I’m barking up the wrong tree,
but…
I’d expect this to pass (using rspec 2.5.1)
describe ‘stub_chain’ do
it “returns expected value from two chains with hash” do
subject = Object.new
subject.stub_chain(:msg1, :msg2 => :first)
subject.stub_chain(:msg1, :msg3 => :second)
If that works, feel free to submit a feature request to support the format you
were using.
Fair enough. I’d been reading stub_chain_spec.rb (which does do stuff
like @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value))
rather than stub_chain.feature and had taken that (as well as
) to mean that subject.stub_chain(:msg1, :msg2 => :first) was official
Fair enough. I’d been reading stub_chain_spec.rb (which does do stuff
like @subject.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value))
rather than stub_chain.feature and had taken that (as well as
) to mean that subject.stub_chain(:msg1, :msg2 => :first) was official
I was wrong. I’d consider this documented, and that what you are
experiencing is a bug.