Permalink
Browse files

Return stubbed value rather than original value from stub_const.

This allows chaining:

  stub_const("Foo", double).stub(:foo)
  • Loading branch information...
1 parent 22c2049 commit f94e6b25b5cb4fe876922c7c94ceb36c0f5758f1 @myronmarston myronmarston committed Jun 7, 2012
Showing with 6 additions and 7 deletions.
  1. +1 −1 lib/rspec/mocks/example_methods.rb
  2. +1 −1 lib/rspec/mocks/stub_const.rb
  3. +4 −5 spec/rspec/mocks/stub_const_spec.rb
@@ -55,7 +55,7 @@ def allow_message_expectations_on_nil
# what nested constants, if any, will be transferred from the original value
# of the constant to the new value of the constant. This only works if both
# the original and new values are modules (or classes).
- # @return [Object] the original value of the constant if it was already defined
+ # @return [Object] the stubbed value of the constant
#
# @example
#
@@ -44,7 +44,7 @@ def self.stub(constant_name, value, options = {})
stubber.stub
ensure_registered_with_mocks_space
- stubber.original_value
+ value
end
# Contains common functionality used by both of the constant stubbers.
@@ -56,10 +56,9 @@ def change_const_value_to(value)
const.should be(original_value)
end
- it 'returns the original value' do
+ it 'returns the stubbed value' do
orig_value = const
- returned_value = stub_const(const_name, 7)
- returned_value.should be(orig_value)
+ stub_const(const_name, 7).should eq(7)
end
end
@@ -89,8 +88,8 @@ def change_const_value_to(value)
recursive_const_defined?(const_name).should be_false
end
- it 'returns nil since it was not originally set' do
- stub_const(const_name, 7).should be_nil
+ it 'returns the stubbed value' do
+ stub_const(const_name, 7).should eq(7)
end
it 'ignores the :transfer_nested_constants option if passed' do

0 comments on commit f94e6b2

Please sign in to comment.