Created
December 17, 2015 23:50
-
-
Save tenderlove/183d0d7244f2f2da32aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this with rspec 2 or 3, it will randomly fail in ruby 2.3.0-preview2 when the ".new" example runs last. | |
# It fails with | |
# 1) SmallCircle .new | |
# Failure/Error: | |
# def area | |
# super(2) | |
# | |
# ArgumentError: | |
# wrong number of arguments (given 1, expected 0) | |
# inline_spec.rb:23:in `area' | |
# inline_spec.rb:24:in `area' | |
# inline_spec.rb:38:in `block (2 levels) in <main>' | |
# | |
# Maybe something in here doesn't like ruby 2.3.0-preview2: https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/any_instance/recorder.rb | |
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', ">= 3" | |
end | |
require 'rspec' | |
require 'rspec/autorun' | |
class Shape | |
def area(value) | |
value | |
end | |
end | |
class Circle < Shape | |
def area | |
super(2) | |
end | |
end | |
class SmallCircle < Circle | |
end | |
RSpec.describe SmallCircle do | |
it "stub method, then .new" do | |
allow_any_instance_of(described_class).to receive(:area).and_return(1) | |
expect(described_class.new.area).to eq 1 | |
end | |
it ".new" do | |
p described_class.instance_method(:area) | |
expect(described_class.new.area).to eq 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Variation also has the same problem with minitest-stub_any_instance: https://gist.github.com/jrafanie/5f45ce478a024621ff14