我的Rails应用程序中有一个Post
对象,我正在尝试为此编写请求测试。我不断收到ArgumentError: unknown keyword: post
错误。这是我的要求规格:
require 'rails_helper'
RSpec.describe "Post", :type => :request do
describe '#create' do
it "creates a Post and redirects to the Post's page" do
get "/posts/new"
expect(response).to render_template(:new)
### This is where the error is happening. On the `post` method.
post "/posts", :post => {:title => "My Post", :content => "My post content"}
expect(response).to redirect_to(assigns(:post))
follow_redirect!
expect(response).to render_template(:show)
expect(response.body).to include("Post was successfully created.")
end
it "does not render a different template" do
get "/posts/new"
expect(response).to_not render_template(:show)
end
end
end
中的代码
答案 0 :(得分:0)
API已更改,因此现在您需要将帖子传递到params
post "/posts", :params => { :post => {:title => "My Post", :content => "My post content"} }
请注意,您的引用指定了@ rails_pre_5,而其正下方的示例指定了@ rails_post_5