Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Doesn't work when user arg is a reference to variable in an outer context
class Test::Unit::TestCase
def self.logged_in_as(user, &block)
context "logged in as #{user}" do
setup do
UserSession.create(user)
end
merge_block(&block) if block_given?
end
end
end
# The Fix: Passing in var name as a string i.e. logged_in_as('@user') do ...
class Test::Unit::TestCase
def self.logged_in_as(user, &block)
context "logged in as #{user}" do
setup do
UserSession.create(eval(user))
end
merge_block(&block) if block_given?
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment