Accept code as block in ActionsHandler#evaluate

This commit is contained in:
Thibault Jouan 2015-04-21 11:34:01 +00:00
parent e8dacfa4ac
commit cc66b6a760
2 changed files with 12 additions and 3 deletions

View File

@ -10,8 +10,12 @@ module Uh
@env, @events = env, events
end
def evaluate code
instance_eval &code
def evaluate code = nil, &block
if code
instance_exec &code
else
instance_exec &block
end
end
def quit

View File

@ -6,10 +6,15 @@ module Uh
subject(:actions) { described_class.new env, events }
describe '#evaluate' do
it 'evaluates given code' do
it 'evaluates code given as Proc argument' do
expect { actions.evaluate proc { throw :action_code } }
.to throw_symbol :action_code
end
it 'evaluates code given as block' do
expect { actions.evaluate { throw :action_code } }
.to throw_symbol :action_code
end
end
describe '#quit' do