Permalink
Browse files

Merge pull request #615 from rspec/issue-603

Allow verifying partial doubles to expect private methods.
  • Loading branch information...
2 parents ad30d03 + 2891fbb commit f3941638cf14e529f35a7fa7de23e30c71e20d76 @xaviershay xaviershay committed Mar 1, 2014
View
@@ -20,6 +20,7 @@ Bug Fixes:
* Fix bug in `expect(dbl).to receive_message_chain(:foo, :bar)` where it was
not setting an expectation for the last message in the chain.
(Jonathan del Strother)
+* Allow verifying partial doubles to have private methods stubbed. (Xavier Shay)
### 3.0.0.beta2 / 2014-02-17
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.0.0.beta1...v3.0.0.beta2)
@@ -69,7 +69,7 @@ def raise_expectation_error(message, expected_received_count, argument_list_matc
# @private
def raise_unimplemented_error(doubled_module, method_name)
- __raise "%s does not implement:\n %s" % [
+ __raise "%s does not implement: %s" % [
doubled_module.description,
method_name
]
@@ -145,7 +145,7 @@ class VerifyingExistingMethodDouble < VerifyingMethodDouble
def initialize(object, method_name, proxy)
super(object, method_name, proxy, self)
- @valid_method = object.respond_to?(method_name)
+ @valid_method = object.respond_to?(method_name, true)
# Trigger an eager find of the original method since if we find it any
# later we end up getting a stubbed method with incorrect arity.
@@ -245,6 +245,12 @@ def method_missing(method_name, *args)
super
end
end
+
+ private
+
+ def defined_private_method
+ "works"
+ end
end
end
@@ -259,6 +265,11 @@ def method_missing(method_name, *args)
expect(object.implemented).to eq("works")
end
+ it 'allows private methods to be expected' do
+ expect(object).to receive(:defined_private_method).and_call_original
+ expect(object.send(:defined_private_method)).to eq("works")
+ end
+
it 'does not allow a non-existing method to be expected' do
prevents { expect(object).to receive(:unimplemented) }
end

0 comments on commit f394163

Please sign in to comment.