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

Yar*_*veh 1 ruby ruby-on-rails

我运行这个单元测试:

require 'test_helper'

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

我收到此错误:

NoMethodError: undefined method 'request=' for #<MyController:0x5150896>
Run Code Online (Sandbox Code Playgroud)

任何的想法?

编辑此操作只有POST而不是GET但是当我在单元测试中更改为post时,我看到相同的resutls

Bre*_*ers 10

我已经看到,当测试中控制器的名称拼写错误时会发生这种情况.你确定在这个例子中控制器名为MyController吗?


pau*_*aul 8

如果您忘记继承ApplicationController或其衍生产品,就会发生这种情况......