简体   繁体   中英

test_helper don't load when I make a test

I need make a test of a model, but when I do this:

ruby test/unit/user_test.rb 

I have also tried with other methods:

ruby -I test test/unit/user_test.rb
rake test:units TEST=test/unit/user_test.rb

But anyone make the test and said:

test/unit/user_test.rb:1:in `require': no such file to load -- test_helper (LoadError)

Or like.

This is part of the code (only the beginning):

require 'test_helper'

class UserTest < Test::Unit::TestCase
  self.use_instantiated_fixtures  = true
  fixtures :users

  def test_auth 
    #check that we can login we a valid user 
    assert_equal  @bob, User.authenticate("bob", "test")    
    #wrong username
    assert_nil    User.authenticate("nonbob", "test")
    #wrong password
    assert_nil    User.authenticate("bob", "wrongpass")
    #wrong login and pass
    assert_nil    User.authenticate("nonbob", "wrongpass")
  end

Yours sincerely

试试这个要求:

require File.dirname(__FILE__) + '/../test_helper'

With Ruby 1.9.3 and Rails 3.2.8, if you run your test cases with

$ rake test

it won't be an issue.

for a single file

$ rake test TEST=test/unit/glosentry_test.rb

for all file

$ rake test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM