Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Always restore original constants.

The original logic from rspec-fire did not restore original constants
if the user changed them in the example after stubbing them, but after
talking it over with @dchelimsky and @garyberhnardt we've decided to
be consistent and always restore them.

For #144.
  • Loading branch information...
commit 9a7c90dc15c7ad2b4261779f17e31c6454b7940b 1 parent 9c44b28
@myronmarston myronmarston authored
View
10 lib/rspec/mocks/stub_const.rb
@@ -41,10 +41,8 @@ def stub!
end
def rspec_reset
- if recursive_const_get(@full_constant_name).equal?(@stubbed_value)
- @context.send(:remove_const, @const_name)
- @context.const_set(@const_name, @original_value)
- end
+ @context.send(:remove_const, @const_name)
+ @context.const_set(@const_name, @original_value)
end
def transfer_nested_constants(constants)
@@ -118,9 +116,7 @@ def stub!
end
def rspec_reset
- if recursive_const_get(@full_constant_name).equal?(@stubbed_value)
- @deepest_defined_const.send(:remove_const, @const_to_remove)
- end
+ @deepest_defined_const.send(:remove_const, @const_to_remove)
end
end
View
20 spec/rspec/mocks/stub_const_spec.rb
@@ -56,13 +56,6 @@ def change_const_value_to(value)
const.should be(original_value)
end
- it 'does not reset the value to its original value when rspec clears its mocks if the example modifies the value of the constant' do
- stub_const(const_name, :a)
- change_const_value_to(new_const_value = Object.new)
- reset_rspec_mocks
- const.should be(new_const_value)
- end
-
it 'returns the original value' do
orig_value = const
returned_value = stub_const(const_name, 7)
@@ -101,19 +94,6 @@ def change_const_value_to(value)
recursive_const_defined?(const_name).should be_false
end
- it 'does not remove the constant when the example manually sets it' do
- begin
- stub_const(const_name, 7)
- stubber = RSpec::Mocks::ConstantStubber.stubbers.first
- change_const_value_to(new_const_value = Object.new)
- reset_rspec_mocks
- const.should equal(new_const_value)
- ensure
- change_const_value_to(7)
- stubber.rspec_reset
- end
- end
-
it 'returns nil since it was not originally set' do
stub_const(const_name, 7).should be_nil
end
Please sign in to comment.
Something went wrong with that request. Please try again.