fractious (owner)

Revisions

gist: 206073 Download_button fork
public
Public Clone URL: git://gist.github.com/206073.git
Embed All Files: show embed
logged_in_as.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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