Yaron Naveh
Yaron Naveh

Reputation: 24406

rails unit test fails "undefined method 'request='"

When I run this unit test:

require 'test_helper'

class MyControllerTest < ActionController::TestCase
   test "my action works" do
     get(:my_action, {'url' => "http://localhost:8090/"})
   end
end

I get this error:

NoMethodError: undefined method 'request=' for #<MyController:0x5150896>

Any idea?

EDIT this action only has POST and not GET but I see the same results when I change to post in the unit test

Upvotes: 1

Views: 3730

Answers (3)

rahul patil
rahul patil

Reputation: 697

There are basically two reasons:

  1. It means you haven't required the controllers file. or

  2. You have a typo in the name that is instantiating the a non controller for the @controller variable in the test.

Cross check at your test file, this will surly solve your problem.

Upvotes: 0

paul
paul

Reputation: 452

This will happen if you've forgotten to inherit from ApplicationController or some derivative thereof...

Upvotes: 10

Brent Sowers
Brent Sowers

Reputation: 663

I've seen this happen when the name of the controller in the test is misspelled. Are you sure that for this example the controller is named MyController?

Upvotes: 11

Related Questions