-
-
Save jrafanie/5f45ce478a024621ff14 to your computer and use it in GitHub Desktop.
minitest-stub_any_instance fails with ruby 2.3.0-preview2
This file contains 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
# Fork of the rspec boom.rb: https://gist.github.com/tenderlove/183d0d7244f2f2da32aa from https://github.com/rspec/rspec-mocks/issues/1042 | |
# This one is for minitest. | |
# Run this with minitest/minitest-stub_any_instance, it will randomly fail in ruby 2.3.0-preview2 when the ".new" example runs last. | |
# It passes if the stub any instance test method happens last with: | |
# | |
# Running | |
# <UnboundMethod: SmallCircle(Circle)#area> | |
# .. | |
# | |
# It fails with | |
# Running: | |
# | |
# .#<UnboundMethod: SmallCircle#area> | |
# E | |
# 1) Error: | |
# TestSmallCircle#test_new: | |
# ArgumentError: wrong number of arguments (given 1, expected 0) | |
# inline_spec.rb:49:in `area' | |
# inline_spec.rb:50:in `area' | |
# inline_spec.rb:66:in `test_new | |
# | |
# https://github.com/codeodor/minitest-stub_any_instance/blob/bd333d8049e6bd5fe964b1cf9ff994a00e22eaee/lib/minitest/stub_any_instance.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 'minitest' | |
gem 'minitest-stub_any_instance' | |
end | |
require 'minitest' | |
require 'minitest/stub_any_instance' | |
require 'minitest/autorun' | |
class Shape | |
def area(value) | |
value | |
end | |
end | |
class Circle < Shape | |
def area | |
super(2) | |
end | |
end | |
class SmallCircle < Circle | |
end | |
class TestSmallCircle < Minitest::Test | |
def test_stub_then_new | |
SmallCircle.stub_any_instance(:area, 1) do | |
assert_equal SmallCircle.new.area, 1 | |
end | |
end | |
def test_new | |
p SmallCircle.instance_method(:area) | |
assert_equal SmallCircle.new.area, 2 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment