Question: Rspec ArgumentError, object not defined

Question

Rspec ArgumentError, object not defined

Answers 1
Added at 2017-07-20 03:07
Tags
Question

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
Answers to

Rspec ArgumentError, object not defined

nr: #1 dodano: 2017-07-20 03:07

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 } }
Source Show
◀ Wstecz