Skip to content

Instantly share code, notes, and snippets.

@gabehollombe
Created March 3, 2015 05:25
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 gabehollombe/1b351d4aba54aa916fe6 to your computer and use it in GitHub Desktop.
Save gabehollombe/1b351d4aba54aa916fe6 to your computer and use it in GitHub Desktop.
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