我的 routes.rb 中有一条路由定义为
scope ':prefix', as: :foo, controller: 'foo_paths', action: :placeholder do
get 'foo/:id', as: 'result'
end
问题是在运行我的测试时总会返回
Failure/Error: subject { get :placeholder }
ActionController::UrlGenerationError:
No route matches {:action=>"placeholder", :controller=>"foo_paths"}
这是我的所有代码我找不到任何错误在浏览器中一切正常并且rake路由返回预期的路径。
foo_paths_controller.rb
class FooPathsController < ApplicationController
def placeholder
render nothing: true, status: :service_unavailable
end
end
foo_paths_controller_spec.rb
describe FooPathsController, type: :controller do
describe "GET 'placeholder'" do
subject { get :placeholder }
it 'renders an empty page with service unavailable http error' do
subject
it { expect(subject).to have_http_status(503) }
it { expect(subject.body).to be_blank }
end
end
end
佣金路线
foo_result GET /:prefix/foo/:id(.:format) foo_paths#placeholder
答案 0 :(得分:1)
正如您所说,它有:prefix
和:id
。您需要指定主题中的那些。
subject { get :placeholder, prefix: 1, id: 11 }
下一个问题我觉得it
在it
块中无效。所以你需要改变它。
it 'renders an empty page with service unavailable http error' do
subject
expect(subject).to have_http_status(503)
expect(subject.body).to be_blank
end