【发布时间】:2015-03-02 13:16:29
【问题描述】:
我在运行我无法弄清楚的测试时遇到错误。
#The error
Failure/Error: get post_path, {id: 1}
ActionController::UrlGenerationError:
No route matches {:action=>"show", :controller=>"posts"} missing required keys: [:id]
以下是规格。
#spec/requests/visitor_interaction_spec.rb
require 'rails_helper'
RSpec.describe 'Visitor', :type => :request do
context 'following a post link' do
it 'should redirect to the post' do
get post_path, {id: 1}
expect(response).to render_template(:show)
end
end
end
如果我将get post_path, {id: 1} 替换为get "posts/1",那么测试会按预期通过
【问题讨论】:
标签: ruby-on-rails rspec