[rspec-users] arbitrary handling of received messages in mocks
cremes.devlist at mac.com
Tue Aug 25 15:59:33 EDT 2009
I am trying to process a message sent to a mock to verify it contains
the correct keys. In my case I am sending a JSON string to the mock
built from data passed in via the test. The object internally builds a
hash and then constructs the JSON string from it.
I can't get my mock to fail though. Here's an example similar to what
it "should match the json string" do
# setup stubs & mocks
hsh = ... # keys and values used inside the method
@api.should_receive(:publish_to_bus) do |message|
false # should always fail
The documentation says the expectation passes or fails based upon the
return value of the block. I can't even force it to fail by returning
false. Once I figure this out, I plan to decode the JSON string in the
mock block and compare the resulting collection with the data I
originally passed in to the object. This behavior will likely become a
helper method (if that matters).
What am I doing wrong?
ruby 1.8.6 patch 287, Windows
Running under Netbeans 6.7.1
Thank you for your help.
More information about the rspec-users