test_helper don't load when I make a test

霸气de小男生 提交于 2021-02-08 01:53:14

问题


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


回答1:


Try this require:

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



回答2:


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.




回答3:


for a single file

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

for all file

$ rake test



来源:https://stackoverflow.com/questions/5520484/test-helper-dont-load-when-i-make-a-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!