Skip to content

Instantly share code, notes, and snippets.

@jrafanie
Forked from tenderlove/boom.rb
Last active December 18, 2015 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrafanie/5f45ce478a024621ff14 to your computer and use it in GitHub Desktop.
Save jrafanie/5f45ce478a024621ff14 to your computer and use it in GitHub Desktop.
minitest-stub_any_instance fails with ruby 2.3.0-preview2
# 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