在终端中运行bundle exec时出错

时间:2015-09-05 18:02:18

标签: ruby-on-rails ruby rubygems

当我运行bundle exec rake test时,它会在终端中出现错误。它似乎无法通过这一步

# Running:

.......EEE.......

Finished in 0.420936s, 40.3862 runs/s, 61.7672 assertions/s.

  1) Error:
StaticPagesControllerTest#test_should_get_help:
NameError: uninitialized constant ApplicationController::TestCase
    app/controllers/static_pages_controller.rb:1:in `<top (required)>'


  2) Error:
StaticPagesControllerTest#test_should_get_home:
NameError: uninitialized constant ApplicationController::TestCase
    app/controllers/static_pages_controller.rb:1:in `<top (required)>'


  3) Error:
StaticPagesControllerTest#test_should_get_about:
NameError: uninitialized constant ApplicationController::TestCase
    app/controllers/static_pages_controller.rb:1:in `<top (required)>'

17 runs, 26 assertions, 0 failures, 3 errors, 0 skips

我尝试将问题解决到代码中,但没有提出解决方案。

class StaticPagesControllerTest < ActionController::TestCase

  test "should get home" do
    get :home
    assert_response :success
    assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
  end

  test "should get help" do
    get :help
    assert_response :success
    assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
  end

  test "should get about" do
    get :about
    assert_response :success
    assert_select "title", "About | Ruby on Rails Tutorial Sample App"

  end

end

1 个答案:

答案 0 :(得分:0)

测试代码的第一行应该是:

class StaticPagesControllerTest < ActionController::TestCase

它的ActionController - 而不是ApplicationController。