[mocha-developer] mock framework ethics question

David Chelimsky dchelimsky at gmail.com
Wed Aug 22 10:46:44 EDT 2007


Hi James, Jim, and everyone else who's listening.

I've been investigating an interesting bug related to mocks and rails
AssociationProxies. See
http://rubyforge.org/tracker/?func=detail&atid=3149&aid=12547&group_id=797
for details.

The crux is that if you do this (rspec mock syntax):

  obj.should_receive(:msg).with(mock_of_a_model)

and the implementation does this:

  obj.msg(containing_model.association_proxy)

the expectation fails. This is because the comparison that rspec mocks make is:

  expected == actual

which, in this case ends up being:

  mock_of_a_model == association_proxy

As it turns out, mocha and flexmock do this the same way, which means
that this will fail in any of the three frameworks.

So here's the mock-ethics question of the week:

Should the comparison be changed to:

  actual == expected

or

  actual == expected || expected == actual

or ... neither?

I have arguments for all three - I'd like to hear your thoughts.

Cheers,
David


More information about the mocha-developer mailing list