3

我需要用 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

但我有“未定义的方法‘get’”错误

4

1 回答 1

4

您应该按照文档中概述的步骤添加minitest-rails gem。然后你的测试应该是这样的:

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
于 2012-07-27T01:51:24.193 回答