Last active
August 29, 2015 14:21
-
-
Save malpinder/d50a9985a74e53743303 to your computer and use it in GitHub Desktop.
Hopelessly egocentric objects that make Rspec mock expectations explode.
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
require 'spec_helper' | |
# https://github.com/raganwald-deprecated/homoiconic/blob/master/2009-02-02/hopeless_egocentricity.md | |
class HopelesslyEgocentric < BasicObject | |
def method_missing(*args, &block) | |
self | |
end | |
# These methods are required to make the tests output their failures normally. | |
#def to_str | |
# 'HopelesslyEgocentric' | |
#end | |
#def to_ary | |
# [self] | |
#end | |
#def to_int | |
# 0 | |
#end | |
end | |
describe 'A test case for hopelessly egocentric objects' do | |
let(:string) { 'a string' } | |
let(:hopelessly_egocentric_object) { HopelesslyEgocentric.new } | |
it 'can be used in successful expectations' do | |
expect(string).to receive(:include?).with(hopelessly_egocentric_object) | |
string.include? hopelessly_egocentric_object | |
end | |
it 'cannot be used as an argument in failing expectations' do | |
expect(string).to receive(:include?).with(hopelessly_egocentric_object) | |
end | |
it 'cannot be involved in failing expectations' do | |
expect(string).to receive(:include?).with(nil) | |
string.include?(hopelessly_egocentric_object) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment