Last active
December 16, 2015 19:49
-
-
Save jrafanie/c94e4c8a4f940e71c9e6 to your computer and use it in GitHub Desktop.
rspec any_instance doesn't rollback stub with ruby 2.3.0-preview2
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 | |
| 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