找不到我的test_helper文件(LoadError)

时间:2014-04-28 17:31:07

标签: ruby-on-rails ruby

尝试查找test_helper文件时,我的测试失败。

我的档案:

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

    #Re-raise errors caugth by the controller 
    class Admin::SupplierController; def rescue_action(e) raise e end; end

    class Admin::SupplierControllerTest < ActionController::TestCase 
      fixtures :suppliers

      def setup
        @controller = Admin::SupplierController.new
        @request = ActionController::TestRequest.new
        @response = ActionController::TestResponse.new
      end

      def test_new
        get :new
        assert_template 'admin/supplier/new'
        assert_tag 'h1', :content => 'Create new supplier'
        assert_tag 'form', :attributes => {:action => '/admin/supplier/create'}
      end 
    end 

1 个答案:

答案 0 :(得分:0)

无需这样做:

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

只需在测试文件顶部require 'test_helper',然后添加-Itest选项即可运行测试。 (假设test_helper.rb位于test /目录中)