本文介绍了minitest:未定义的方法`get'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要用minitest测试我的控制器.我尝试过:
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
和
class CommentsControllerTest < MiniTest::Unit::TestCase
def test_should_get_index
get :index
assert_response :success
end
end
但是我遇到未定义的方法'get'"错误
but I have "undefined method `get'" error
推荐答案
您应添加 minitest-rails gem,按照文档中概述的步骤进行.然后您的测试应如下所示:
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
或者,看起来像这样:
require "minitest_helper"
class CommentsControllerTest < MiniTest::Rails::ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end
这篇关于minitest:未定义的方法`get'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!