Skip to content

Commit

Permalink
Merge d9121a2 into 331b4b3
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviershay committed Sep 25, 2013
2 parents 331b4b3 + d9121a2 commit ee9dbec
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/rspec/mocks/verifying_double.rb
Expand Up @@ -23,6 +23,11 @@ def __build_mock_proxy
:instance_method
)
end

def method_missing(message, *args, &block)
__mock_proxy.verify_method_missing(message)
super
end
end

# Similar to an InstanceVerifyingMock, except that it verifies against
Expand Down Expand Up @@ -51,6 +56,11 @@ def as_stubbed_const(options = {})
ConstantMutator.stub(@doubled_module.name, self, options)
self
end

def method_missing(message, *args, &block)
__mock_proxy.verify_method_missing(message)
super
end
end

end
Expand Down
7 changes: 7 additions & 0 deletions lib/rspec/mocks/verifying_proxy.rb
Expand Up @@ -41,6 +41,13 @@ def add_message_expectation(location, method_name, opts={}, &block)
super
end

def verify_method_missing(message)
# Null object conditional is an optimization. If not a null object,
# validity of method expectations will have been checked at definition
# time.
ensure_implemented(message) if null_object?
end

# A custom method double is required to pass through a way to lookup
# methods to determine their arity. This is only relevant if the doubled
# class is loaded.
Expand Down
14 changes: 14 additions & 0 deletions spec/rspec/mocks/verifying_double_spec.rb
Expand Up @@ -107,6 +107,13 @@ def prevents(&block)
o = instance_double(LoadedClass, :defined_instance_method => 1)
expect(o.defined_instance_method).to eq(1)
end

it 'only allows defined methods for null objects' do
o = instance_double('LoadedClass').as_null_object

expect(o.defined_instance_method).to eq(o)
prevents { o.undefined_method }
end
end
end

Expand Down Expand Up @@ -186,6 +193,13 @@ def prevents(&block)
expect(dbl1).to receive(:undefined_class_method)
}
end

it 'only allows defined methods for null objects' do
o = class_double('LoadedClass').as_null_object

expect(o.defined_class_method).to eq(o)
prevents { o.undefined_method }
end
end
end

Expand Down

0 comments on commit ee9dbec

Please sign in to comment.