私はRSpecコントローラ仕様を持っていますが、私の例では正確な経路がどのように呼び出されているかを知る方法を理解しようとしています。 services_controller_spec.rbでRSpecコントローラ仕様で呼び出されている経路を特定する方法
:
describe 'create comment' do
let!(:service) { FactoryGirl.create(:service) }
describe 'with valid comment' do
it 'creates a new comment' do
expect {
post :add_comment, id: service.id
}.to change(service.service_comments, :count).by(1)
expect(response).to redirect_to(service_path(service))
end
end
end
ポストを経由して送信されているpp
またはputs
ルートに方法はありますか?
post
には/services/:id/add_comment
のルートに欲しいと頼んでいて、正確にルートがどこに行くのか確認したいと思っています。
このルートのマイroutes.rbを:
routes.formatter.send(
:match_route,
nil,
controller: ServicesController.controller_path,
action: 'add_comment', # what you passed to the get method, but a string, not a symbol
id: service.id # the other options that you passed to the get method
) { |route| puts route.name }
RSpecのレール:あなたはこのような何かをRSpecのレールコントローラの仕様で使用されるルートの名前を印刷することができ
resources :services do
member do
post 'add_comment'
end
end
'describe ServicesController'ブロックを表示すると役に立ちます。 –