【问题标题】:minitest: undefined method `get'minitest:未定义的方法“get”
【发布时间】:2012-07-26 10:41:42
【问题描述】:

我需要用 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'”错误

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 testing minitest


    【解决方案1】:

    您应该按照文档中列出的步骤添加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
    

    【讨论】:

    • 我相信您可以在上面的第一个示例中使用must_respond_with :success 期望。
    • 取决于您使用的 minitest-rails 的版本,是的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多