MINITEST:未定义的方法`得到”(minitest: undefined method `ge

2019-09-20 06:21发布

我需要测试我与MINITEST控制器。 我试过了:

describe 'CommentsController' do
  it "should get index" do
    get :index
    assert_response :success
  end
end

class CommentsControllerTest < MiniTest::Unit::TestCase
  def test_should_get_index
    get :index
    assert_response :success
  end
end

但我有“未定义的方法'得到'”错误

Answer 1:

您应该添加MINITEST护栏宝石,下面的文档中列出的步骤。 然后你的测试应该是这样的:

require "minitest_helper"

describe CommentsController do
  it "should get index" do
    get :index
    assert_response :success
  end
end

或者说,是这样的:

require "minitest_helper"

class CommentsControllerTest < MiniTest::Rails::ActionController::TestCase
  test "should get index" do
    get :index
    assert_response :success
  end
end


文章来源: minitest: undefined method `get'