Skip to content

Commit

Permalink
Merge pull request #323 from tjvc/fix-delegation-warnings
Browse files Browse the repository at this point in the history
Define respond_to_missing? on Mocha::Mock
  • Loading branch information
floehopper committed Mar 20, 2018
2 parents 76aad9c + befb416 commit 9835454
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/mocha/mock.rb
Expand Up @@ -9,6 +9,7 @@
require 'mocha/argument_iterator'
require 'mocha/expectation_error_factory'
require 'mocha/deprecation'
require 'mocha/ruby_version'

module Mocha

Expand Down Expand Up @@ -314,7 +315,7 @@ def method_missing(symbol, *arguments, &block)
end

# @private
def respond_to?(symbol, include_private = false)
def respond_to_missing?(symbol, include_private = false)
if @responder then
if @responder.method(:respond_to?).arity > 1
@responder.respond_to?(symbol, include_private)
Expand All @@ -326,6 +327,13 @@ def respond_to?(symbol, include_private = false)
end
end

# @private
if PRE_RUBY_V19
def respond_to?(symbol, include_private = false)
respond_to_missing?(symbol, include_private)
end
end

# @private
def __verified__?(assertion_counter = nil)
@expectations.verified?(assertion_counter)
Expand Down
8 changes: 8 additions & 0 deletions test/unit/mock_test.rb
Expand Up @@ -334,6 +334,14 @@ def test_should_remove_expectation_for_unstubbed_method
assert_match(/unexpected invocation/, e.message)
end

unless PRE_RUBY_V19
def test_expectation_is_defined_on_mock
mock = build_mock
mock.expects(:method1)
assert defined? mock.method1
end
end

private

def build_mock
Expand Down

0 comments on commit 9835454

Please sign in to comment.