Skip to content

Commit

Permalink
double.as_null_object always returns true for respond_to?
Browse files Browse the repository at this point in the history
- Closes #16.
  • Loading branch information
dchelimsky committed Sep 12, 2010
1 parent 9003244 commit 972deb5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rspec/mocks/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def to_s

alias_method :to_str, :to_s

def respond_to?(sym, incl_private=false)
__mock_proxy.respond_to?(sym, incl_private)
end

private

def method_missing(sym, *args, &block)
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/mocks/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def initialize(object, name=nil, options={})
def null_object?
@null_object
end

def respond_to?(sym, incl_private=false)
null_object? ? true : super
end

# Tells the object to ignore any messages that aren't explicitly set as
# stubs or message expectations.
Expand Down
4 changes: 4 additions & 0 deletions spec/rspec/mocks/null_object_mock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ module Mocks
@mock.message(:expected_arg)
@mock.message(:unexpected_arg)
end

it "responds to everything" do
@mock.should respond_to(:any_message_it_gets)
end
end

describe "#null_object?" do
Expand Down

0 comments on commit 972deb5

Please sign in to comment.