I have a namespaced controller for an Api, and when i use the should respond_with matcher in the spec for the same , i get the message undefined methodrespond_with' for #
The spec i have is as follows :
describe Api::V1::UsersController, type: :controller do
describe "GET #show" do
before(:each) do
@user = create(:user)
get :show, id: @user.id, format: :json
end
it { should respond_with 200 }
end
end
I have added the rspec-rails gem before the shoulda-matchers gem in my Gemfile. Also, my users controller is located in app/controllers/api/v1/users_controller.rb and the spec in spec/controllers/api/v1/users_controller_spec.rb .
Had added the shoulda-matchers gem only to test group in Gemfile, instead of both development and test. It works after its added to both groups. Closing this ticket.
"instead of both development and test. It works after its added to both groups."
why should a rspec matcher be added to development group? that doesn't make any sense, it should be test only. Also I'm having this issue with rails 4.2.0 and adding to both groups does NOT solve it
I'm having the same error with rails 4.2.4 as well
I have found this error before
and found this one about configure (that I thinks newly add in new versions)
https://github.com/thoughtbot/shoulda-matchers#configuration
so I add this to spec_helper.rb
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end
hope this help
I was having the same problem and solve it using your method. Thank you
I added this and it worked!
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end
+1 for the fix
+1 for that fix Thanks!
+1
I needed this fix to get shoulda-matcher working with rspec as well
Thanks, fix the problem with respond_with o/
+1 馃槑
I also had same problem.. and solved it by adding
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end
to spec_helper.rb
thanks for the fix :)
Thanks! @fake-or-dead
Had the same problem, but following the tip from @fake-or-dead it was solved.
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end
But according to the link https://github.com/thoughtbot/shoulda-matchers#rspec it must go in rails_helper.rb
Same thing here. Like @GabrielCabrera said it has to go in rails_helper.rb
@GabrielCabrera yes gotta go in rails_helper
the @GabrielCabrera 's solution worked for me, thanks
@fake-or-dead , I appreciate your solutions. It helps me a lot. Have a great day.
Make sure to add outside of the Rspec.configure do block. Works like a charm!
Shoulda::Matchers.configure do |config|
config.integrate do |with|
# Choose a test framework:
with.test_framework :rspec
with.library :rails
end
end
Most helpful comment
I have found this error before
and found this one about configure (that I thinks newly add in new versions)
https://github.com/thoughtbot/shoulda-matchers#configuration
so I add this to spec_helper.rb
hope this help