Skip to content

Instantly share code, notes, and snippets.

@composerinteralia
Last active September 29, 2017 11:57
Show Gist options
  • Save composerinteralia/5dbfa7fdbe9b9add361f4f5a575c8562 to your computer and use it in GitHub Desktop.
Save composerinteralia/5dbfa7fdbe9b9add361f4f5a575c8562 to your computer and use it in GitHub Desktop.
Ruby bug causing weirdness in RSpec
RUBY_VERSION='2.1.10'
# Fails with 2.0.0 and 2.1.10
# Passes with 2.3.1 and 2.4.1
# Have not tried with any other versions
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do
source "https://rubygems.org"
gem "rspec"
end
class Parent
def method_in_parent
'wtf'
end
end
class Child < Parent
def method_in_child
method_in_parent
end
end
describe 'an unrelated test' do
it 'should have no effect on the next test' do
allow_any_instance_of(Child).to receive(:method_in_parent)
end
end
describe 'but in ruby 2.1.10' do
before do
allow_any_instance_of(Parent).to receive(:method_in_parent)
end
it 'this test fails' do
expect(Child.new.method_in_child).not_to eq('wtf')
end
end
# If you change both allows to Parent, both to Child,
# or swap them so Parent is stubbed first, the test
# will pass regardless of Ruby version.
RSpec::Core::Runner.invoke
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment