Controller spec unknown keyword: id
HTTP request methods will accept only the following keyword arguments
params, headers, env, xhr, format
According to the new API, you should use keyword arguments, params
in this case:
it 'should show field' do
get :show, params: { id: field.id }
expect(response.status).to eq(200)
end
Failure/Error: get :show, id: @user.id, format: :json
You should be passing a params
hash containing the parameters you're interested in submitting:
get :show, params: { id: @user.id }
rspec post:create action ArgumentError: unknown keyword: post
The code have to be like this
describe 'POST create' do
it 'creates a new Post' do
expect {
post :create, params: {topic_id: @topic, post: @post_attributes}
}.to change(Post, :count).by(1)
end
And this works now
Rspec post :create 'unknown keyword: '
The way you're calling post
does not work anymore in Rails 5.
This is the deprecation warning of the previous version:
ActionController::TestCase HTTP request methods will accept only keyword arguments in future Rails versions.
Now you have to add the params
key, like this:
post :create, params: { protocol: params }
Notice that post :create, :params => { :protocol => params }
means the same, it's just a different syntax.
adding headers to a rspec get
Unfortunately, rspec doesn't allow to set request headers, so you'll need to workaround it like this:
it "returns albums" do
request.headers.merge!(authenticated_header("admin", "123"))
get "/index", params: {}
puts response.body
end
Related Topics
How to Monitor Delayed_Job With Monit
Can't Install Rails on MAC Os Catalina
In Ruby on Rails, Are '#Encoding: Utf-8' and 'Config.Encoding = "Utf-8"' Different
Looping in a Spiral Outside-In
What's the 'Ruby Way' to Iterate Over Two Arrays at Once
Why Is Sum So Much Faster Than Inject(:+)
Using Rvm on Ubuntu 12.04 to Use Rails. the Program 'Rails' Is Currently Not Installed
How to Install Ruby-Debug When Needing Necessary Libraries And/Or Headers
In Ruby, Why Does Nil[1]=1 Evaluate to Nil
Ruby: What Does the Comment "Frozen_String_Literal: True" Do
Error: Mime-Types-Data Requires Ruby Version >= 2.0
Is There a "Phpmyadmin" for Ruby on Rails
Test If Variable Matches Any of Several Strings W/O Long If-Elsif Chain, or Case-When
Running Command Line Commands Within Ruby Script
Change the Name of the :Id Parameter in Routing Resources for Rails
Best Practices to Handle Routes For Sti Subclasses in Rails
In Ruby Why Won't 'Foo = True Unless Defined(Foo)' Make the Assignment