Skip to content

Commit

Permalink
Verified null object doubles should implement respond_to? correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
myronmarston committed Nov 23, 2013
1 parent 4cd26ac commit bec8f14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rspec/mocks/verifying_double.rb
Expand Up @@ -5,6 +5,14 @@ module Mocks

# @api private
module VerifyingDouble
def respond_to?(message, include_private=false)
if null_object?
__mock_proxy.method_reference[message].when_unimplemented { return false }
end

super
end

def method_missing(message, *args, &block)
# Null object conditional is an optimization. If not a null object,
# validity of method expectations will have been checked at definition
Expand Down
3 changes: 3 additions & 0 deletions spec/rspec/mocks/verifying_double_spec.rb
Expand Up @@ -188,7 +188,10 @@ module Mocks
o = instance_double('LoadedClass').as_null_object

expect(o.defined_instance_method).to eq(o)
expect(o).to respond_to(:defined_instance_method)

prevents { o.undefined_method }
expect(o).not_to respond_to(:undefined_method)
end
end

Expand Down

0 comments on commit bec8f14

Please sign in to comment.