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.

​​gist:665226 · GitHub

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:
http://groups.google.com/group/rspec/browse_thread/thread/a38932d19fffee49/915d609d3a0d2862?lnk=gst&q=stub+method+chain#915d609d3a0d2862

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)
http://wiki.hedgehogshiatus.com

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:

http://groups.google.com/group/rspec/browse_thread/thread/a38932d19fffee49/915d609d3a0d2862?lnk=gst&q=stub+method+chain#915d609d3a0d2862

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?

http://groups.google.com/group/cukes

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

Cheers,
David