[Rspec-devel] Mock feature thoughts

Judson Lester nyarly-rspec at redfivellc.com
Mon Aug 28 15:44:35 EDT 2006


Given the discussion elsewhere on the list about Mocks and Rails, I
thought I'd briefly raise a couple of feature thoughts that I'm not
positive about in terms of philosophy.  Basically these all come out of
a basic frustration I've always had with every mock package.  That mocks
don't behave like the objects they're mocking.

Specifically, if I write something like

thing_mock=mock("thing")
thing_mock.should_receive(:a_message).and_return("message received")

I'd love to have thing_mock implicitly do something like
thing_mock.should_receive(:respond_to?).with(:a_message).and_return(true).any_number_of_times

Unless, of course I were to explicitly specify some other behavior for
#respond_to?

Relatedly, I'd love to be able to say (and _please_ don't read this as a
request for auto-mocking or whatever - assume that there is no "MyClass"
defined anywhere)

thing_mock=mock("thing")
thing_mock.mock_ancestors(["Object", "MyParentClass", "MyClass"])

and have it respond intelligently to #class, #kind_of, etc. 

This is especially useful when specifying a behavior that relies on
another library.  For instance, DRb. 

Does this seem useful, or does it expose an underlying misapprehension
about BDD on my part?

Judson


More information about the Rspec-devel mailing list