Created
May 8, 2011 06:37
-
-
Save macks/961171 to your computer and use it in GitHub Desktop.
local variables in eval
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
require 'rubygems' | |
require 'rspec' | |
describe 'Local variable in eval' do | |
context 'Assignment in eval' do | |
it 'works' do | |
expect { | |
eval <<-EOS | |
var = true | |
raise unless var | |
EOS | |
}.not_to raise_error | |
end | |
end | |
context 'Assignment in eval in eval' do | |
it 'fails with NameError' do | |
expect { | |
eval <<-EOS | |
eval "var = true" | |
var | |
EOS | |
}.to raise_error(NameError) | |
end | |
it 'succeeds if assigned in advance' do | |
expect { | |
eval <<-EOS | |
var = false | |
eval "var = true" | |
raise unless var | |
EOS | |
}.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