[测试控制器usinf Rspec时出现UrlGenerationError

问题描述 投票:0回答:1

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

我的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=>"test_meth", :controller=>"test"}

我不确定我是否会错过一些非常基本的内容,因为这看起来非常简单。非常感谢您的帮助。

ruby-on-rails rspec rspec-rails controller-tests
1个回答
0
投票

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

您必须拥有。

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

© www.soinside.com 2019 - 2024. All rights reserved.