【问题标题】:UrlGenerationError when testing controller usinf Rspec使用inf Rspec测试控制器时出现UrlGenerationError
【发布时间】:2020-08-04 14:36:50
【问题描述】:

我正在尝试运行基本的控制器测试。

我的 controller_spec.rb 看起来像:

class Test < ActionController::Base
  def test_meth
    puts 'hello for test meth'
    head 200
  end
end

describe Test do
  it 'responds with 200' do
    get :test_meth
    expect(response.status).to eq(200)
  end
end

当我运行这个规范时,我最终会遇到一个错误

ActionController::UrlGenerationError: No route matches {:action=&gt;"test_meth", :controller=&gt;"test"}

我不确定我是否在这里遗漏了一些非常基本的东西,因为这看起来非常简单。非常感谢任何帮助。

【问题讨论】:

    标签: ruby-on-rails rspec rspec-rails controller-tests


    【解决方案1】:

    错误很明显,在您的routes.rb 文件中您没有正确编写操作。

    你必须有。

    get "test", to: "test#test_meth"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多