Skip to content

Commit

Permalink
Adds failing example demonstrating regression with #264
Browse files Browse the repository at this point in the history
  • Loading branch information
alindeman committed Aug 16, 2013
1 parent 6aa9bcc commit 07aa1d0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/rspec/mocks/stub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ def existing_private_instance_method
expect(@instance.existing_instance_method).to eq(:original_value)
end

it "restores existing singleton methods with the appropriate context" do
klass = Class.new do
def self.say_hello
@hello if defined?(@hello)
end
end

subclass = Class.new(klass)

subclass.instance_variable_set(:@hello, "Hello")
expect(subclass.say_hello).to eq("Hello")

klass.stub(:say_hello) { "Howdy" }
expect(subclass.say_hello).to eq("Howdy")

reset klass
expect(subclass.say_hello).to eq("Hello")
end

it "restores existing private instance methods" do
# See bug reports 8302 and 7805
@instance.stub(:existing_private_instance_method) { :stub_value }
Expand Down

0 comments on commit 07aa1d0

Please sign in to comment.