How best to intercept one method in the midst of a chain

Hi Group,
I’m back to Rspec after some time away, and was a little curious about
why the following example does not return the value zero.


I have tried @repo.status.send{type.to_sym}.size and got the same
result, and I suspected the send was maybe bypassing rspec
doubles/stubs, so I used the eval and got the same result.

That said, I have used stub_chain to get this to pass, but would
appreciate any insight into what I’ve done wrong.
The side effect of stub_chain is that it seems to clobber the contents
of .status, so I have to create a new @repo instance, which just feels
wrong when I’m actually trying to stub the method ‘type’.

In fact since, in the gist, I use should_receive I expected that this
would break the example altogether. Rather it is as if the method
‘type’ is unaffected.
This post left me with the impression that ‘type’ should be overridden
after the use of should_receive (in the way status is after using the
stub_chain), but I’ve obviously misunderstood:

Appreciate any insights
Best wishes

πόλλ’ οἶδ ἀλώπηξ, ἀλλ’ ἐχῖνος ἓν μέγα
[The fox knows many things, but the hedgehog knows one big thing.]
Archilochus, Greek poet (c. 680 BC – c. 645 BC)

On Nov 6, 2010, at 7:10 PM, Hedge H. wrote:

That said, I have used stub_chain to get this to pass, but would
stub_chain), but I’ve obviously misunderstood:

I have some thoughts for you, but this is really a Cucumber question
(even though you’re using rspec-mocks in the context of Cucumber). Are
you aware there is a separate Cucumber list?

I’d recommend moving this conversation there, at which point I’ll be
glad to respond.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs