Checking method presence/arity?

15 views
Skip to first unread message

Jeff Winkler

unread,
Oct 9, 2013, 2:32:16 PM10/9/13
to mocha-d...@googlegroups.com
Hi-
 Recently watched Sandy Metz's video about testing magic tricks - http://www.youtube.com/watch?feature=player_detailpage&v=URSWYvyc42M#t=1670

 She talks about using a mocking library that protects against API drift by checking that the mock has the same contract. Is there any way to do this in Mocha? 

This test passes, but I'd like it to blow up saying you can't mock a method that's not on the underlying object. --

class Foo
end

describe Foo do
  it 'should mock' do
    f=Foo.new

    # mock a non-existent method.
    f.expects(:missing_method).with(1).returns(1)
    f.missing_method(1).must_equal 1
  end
end

Thanks

floehopper

unread,
Oct 9, 2013, 2:42:18 PM10/9/13
to mocha-d...@googlegroups.com
Hi Jeff,

I've certainly have it in mind for a while - https://github.com/freerange/mocha/issues/149If only I had the time to implement it!

If you're interested, perhaps you could submit a pull request with some suggested changes...? Or perhaps add some comments to that issue...?

Cheers, James.
----
Reply all
Reply to author
Forward
0 new messages