1

Why am I getting the error below? When running a rspec test in console, I get the error that 'post' is unknown. yet the line of code that is failing is structured as such:

post :create, valid_params

as such:

it "assigns the new post to @post" do
  post :create, post: {title: RandomData.random_sentence, body: RandomData.random_paragraph}
  expect(assigns(:post)).to eq Post.last
end

Here is the error

  1) PostsController POST create assigns the new post to @post
 Failure/Error: post :create, post: {title: RandomData.random_sentence, body: RandomData.random_paragraph}

 ArgumentError:
   unknown keyword: post

1 Answer 1

1

If you're using Rails 5, then you need to wrap your post object within a params keyword argument, try with:

post :create, params: { post: { title: RandomData.random_sentence, body: RandomData.random_paragraph } }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.