diff --git a/foo.rb b/foo.rb new file mode 100644 index 00000000..b32465e7 --- /dev/null +++ b/foo.rb @@ -0,0 +1,26 @@ +require 'bundler/setup' +require 'minitest/autorun' +require 'mocha/minitest' + +class TestMeme < Minitest::Test + class Klass + def self.foo; end + end + + def test_foo_never_called # should fail, but doesn't + Klass.stubs(:foo) + Klass.expects(:foo).never + Klass.foo + end + + def test_foo_called_once # correctly passes + Klass.stubs(:foo) + Klass.expects(:foo).once + Klass.foo + end + + def test_no_stubs # correctly fails + Klass.expects(:foo).never + Klass.foo + end +end diff --git a/lib/mocha/mock.rb b/lib/mocha/mock.rb index 03c9c1c1..ef5d02b8 100644 --- a/lib/mocha/mock.rb +++ b/lib/mocha/mock.rb @@ -321,7 +321,7 @@ def handle_method_call(symbol, arguments, block) check_expiry check_responder_responds_to(symbol) invocation = Invocation.new(self, symbol, arguments, block) - if (matching_expectation_allowing_invocation = all_expectations.match_allowing_invocation(invocation)) + if (matching_expectation_allowing_invocation = all_expectations.match(invocation)) matching_expectation_allowing_invocation.invoke(invocation) elsif (matching_expectation = all_expectations.match(invocation, ignoring_order: true)) || (!matching_expectation && !@everything_stubbed) raise_unexpected_invocation_error(invocation, matching_expectation)