rspec-mocks
rspec-mocks copied to clipboard
Errors rolling back stubbed any_instance methods if they were aliases from included modules
If I stub out a method created by alias_method
in an included module, using any_instance, the next spec to call it raises NoMethodError
.
Probably related to the fix for #1042 !
This fails on ruby 2.2.3 + rspec-mocks 3.4.1, but passes in 3.4.0:
module Area
def self.included(base)
base.class_eval do
alias_method(:size, :area)
end
end
def area
1
end
end
class Circle
include Area
end
describe Circle do
it "stubbed" do
allow_any_instance_of(Circle).to receive(:size).and_return(2)
expect(Circle.new.size).to be(2)
end
it "not stubbed" do
expect(Circle.new.size).to be(1) # => raises NoMethodError (!)
end
end
Running it under rspec-mocks 3.4.1:
1) Circle not stubbed
Failure/Error: expect(r.size).to be(1)
NoMethodError:
undefined method `size' for #<Circle:0x007fc81c4f1aa0>
This bit me because I was stubbing out an alias added by acts_as_votable (this seems like a pretty common pattern for "act_as_*" libraries that don't use Concern)