minitest: undefined method `get'

做~自己de王妃 提交于 2019-12-10 17:49:09

问题


I'm need to test my controller with minitest. I've tried:

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

and

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

but I have "undefined method `get'" error


回答1:


You should add the minitest-rails gem, following the steps outlined in the documentation. Then your tests should look like this:

require "minitest_helper"

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

Or, look like this:

require "minitest_helper"

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


来源:https://stackoverflow.com/questions/11667552/minitest-undefined-method-get

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