Skip to content

Instantly share code, notes, and snippets.

@jamesbebbington
Created October 9, 2009 14:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jamesbebbington/206073 to your computer and use it in GitHub Desktop.
# 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