Rspec return 使用作用域路由时没有路由匹配
Rspec return No route matches when using scoped route
我的 routes.rb 中有一条如此定义的路线
scope ':prefix', as: :foo, controller: 'foo_paths', action: :placeholder do
get 'foo/:id', as: 'result'
end
问题是 运行 我的测试总是 returns
Failure/Error: subject { get :placeholder }
ActionController::UrlGenerationError:
No route matches {:action=>"placeholder", :controller=>"foo_paths"}
这是我的所有代码,我找不到任何错误,在浏览器中一切正常,并且耙路由 return 预期的路由。
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
正如你所说的那样,它有 :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
我的 routes.rb 中有一条如此定义的路线
scope ':prefix', as: :foo, controller: 'foo_paths', action: :placeholder do
get 'foo/:id', as: 'result'
end
问题是 运行 我的测试总是 returns
Failure/Error: subject { get :placeholder }
ActionController::UrlGenerationError:
No route matches {:action=>"placeholder", :controller=>"foo_paths"}
这是我的所有代码,我找不到任何错误,在浏览器中一切正常,并且耙路由 return 预期的路由。
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
正如你所说的那样,它有 :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