Including common routines in test_helper.rb

I should have done this earlier. To do a number of tests, I have to repeat the same actions like create a user, log a user in, etc. I was putting these actions at the top of each test file, but have wised up and moved them to the test_helper.rb file. Here’s how that looks now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Test::Unit
  class TestCase
    ...
 
    def create_user(user_hash={})
      post '/user/signup', {:user=>{:username=>"testuser",:email=>"test@test.com",:password=>"pass1",:password_confirmation=>"pass1"}.merge(user_hash)}
    end
 
    def login(user_hash={})
      post "/user/login", :user=>{:username_or_email=>'testuser',:password=>'pass1'}.merge(user_hash)
    end
 
  end
end
Posted: March 24th, 2010 | Author: jay | Filed under: Code | Tags: , , , , | 1 Comment »

One Comment on “Including common routines in test_helper.rb”

  1. 1 Ned said at 7:13 pm on March 25th, 2010:

    Test cases… love it!


Leave a Reply