spec/rspec/mocks/stub_const_spec.rb in rspec-mocks-2.11.2 vs spec/rspec/mocks/stub_const_spec.rb in rspec-mocks-2.11.3

- old
+ new

@@ -10,10 +10,14 @@ class NestedEvenMore end end end +class TestSubClass < TestClass + P = :p +end + module RSpec module Mocks describe "Constant Stubbing" do include RSpec::Mocks::RecursiveConstMethods @@ -117,9 +121,27 @@ stub = Module.new stub_const("TestClass", stub, :transfer_nested_constants => true) stub::M.should eq(:m) stub::N.should eq(:n) stub::Nested.should be(tc_nested) + end + + it 'does not transfer nested constants that are inherited from a superclass' do + stub = Module.new + stub_const("TestSubClass", stub, :transfer_nested_constants => true) + stub::P.should eq(:p) + defined?(stub::M).should be_false + defined?(stub::N).should be_false + end + + it 'raises an error when asked to transfer a nested inherited constant' do + original_tsc = TestSubClass + + expect { + stub_const("TestSubClass", Module.new, :transfer_nested_constants => [:M]) + }.to raise_error(ArgumentError) + + TestSubClass.should be(original_tsc) end it 'allows nested constants to be selectively transferred to a stub module' do stub = Module.new stub_const("TestClass", stub, :transfer_nested_constants => [:M, :N])