Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minitest: undefined method `get'

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

like image 514
cnaize Avatar asked Feb 10 '26 15:02

cnaize


1 Answers

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
like image 58
blowmage Avatar answered Feb 13 '26 14:02

blowmage