Created
March 3, 2015 05:25
-
-
Save gabehollombe/1b351d4aba54aa916fe6 to your computer and use it in GitHub Desktop.
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 'ostruct' | |
def thing | |
OpenStruct.new(foo: 'FOO') | |
end | |
context 'foo' do | |
it 'returns foo' do | |
expect(thing.foo).to eq('FOO') | |
end | |
context 'shadowing the method with a local variable and using the method in the assignment' do | |
specify 'throws an error if you call the method without parens in the assignment' do | |
expect { thing = thing.foo }.to raise_error(NoMethodError) | |
# Failure/Error: thing = thing.foo | |
# NoMethodError: | |
# undefined method `foo' for nil:NilClass | |
end | |
specify 'works if you use parens to call the method in the assignment' do | |
expect { thing = thing().foo }.not_to raise_error | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment