[rspec-users] How best to intercept one method in the midst of a chain

Hedge Hog hedgehogshiatus at gmail.com
Sat Nov 6 20:10:08 EDT 2010


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.

​​https://gist.github.com/665226

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


More information about the rspec-users mailing list