kurenn / market_place_api

The API on Rails tutorial application
142 stars 68 forks source link

Chapter 7: Tests Failing with "undefined method 'respond_with' #50

Closed godzilla74 closed 9 years ago

godzilla74 commented 9 years ago

I made the changes in section 7.9 to product_controllers_spec.rb and product_controllers.rb and now my tests are failing. Before doing these steps, my tests were green.

 Failures:
 1) Api::V1::ProductsController GET #show 
  Failure/Error: it { should respond_with 200 }
  NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fd2e33762f8>
 # ./spec/controllers/api/v1/products_controller_spec.rb:21:in `block (3 levels) in <top (required)>'

 2) Api::V1::ProductsController POST #create when is successfully created 
 Failure/Error: it { should respond_with 201 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_1:0x007fd2e2eb0c28>
 # ./spec/controllers/api/v1/products_controller_spec.rb:81:in `block (4 levels) in <top (required)>'

 3) Api::V1::ProductsController POST #create when is not created 
 Failure/Error: it { should respond_with 422 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_3::Nested_2:0x007fd2e339d2b8>
 # ./spec/controllers/api/v1/products_controller_spec.rb:102:in `block (4 levels) in <top (required)>'

 4) Api::V1::ProductsController GET #index when is not receiving any product_ids parameter 
 Failure/Error: it { should respond_with 200 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_1:0x007fd2e80fb1e0>
 # ./spec/controllers/api/v1/products_controller_spec.rb:46:in `block (4 levels) in <top (required)>'

 5) Api::V1::ProductsController PUT/PATCH #update when is successfully updated 
 Failure/Error: it { should respond_with 200 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4::Nested_1:0x007fd2e2f00f70>
 # ./spec/controllers/api/v1/products_controller_spec.rb:123:in `block (4 levels) in <top (required)>'

 6) Api::V1::ProductsController PUT/PATCH #update when is not updated 
 Failure/Error: it { should respond_with 422 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_4::Nested_2:0x007fd2e1526550>
 # ./spec/controllers/api/v1/products_controller_spec.rb:141:in `block (4 levels) in <top (required)>'

 7) Api::V1::ProductsController DELETE #destroy 
 Failure/Error: it { should respond_with 204 }
 NoMethodError:
   undefined method `respond_with' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_5:0x007fd2e0ce3118>
 # ./spec/controllers/api/v1/products_controller_spec.rb:153:in `block (3 levels) in <top (required)>'
kurenn commented 9 years ago

Are you using version 4.2 of rails?

godzilla74 commented 9 years ago

@kurenn I started matching your GemFile from Chapter 1, which had rails 4.0.2, I just changed to rails 4.2.0, ran bundle update & bundle install, still getting the same rspec errors.

kurenn commented 9 years ago

The respond_with method was taken out from Rails 4.2, you can still get this behavior with the responders gem.

Let me know how it goes!

godzilla74 commented 9 years ago

@kurenn Tried to add the responders gem, which indicated I only need to run bundle install to support backwards compatibility, didn't work!

Switched back to rails 4.0.2, removed responders, and still getting the same error. I'm stumped at this point.

kurenn commented 9 years ago

I did not notice, it as a Rspec error, which version are you using?

godzilla74 commented 9 years ago

@kurenn rspec-core 2.99.2

kurenn commented 9 years ago

Try using rspec-rails version 2.14, that should fix the problem

godzilla74 commented 9 years ago

@kurenn Changed Gemfile to:

 group :test do
   gem "rspec-rails", "2.14"
   gem 'shoulda-matchers'
end

Still no luck though!

 Api::V1::ProductsController GET #show 
   Failure/Error: it { should respond_with 200 }
   NoMethodError:
     undefined method `respond_with' for #     <RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fad924af4b0>
 # ./spec/controllers/api/v1/products_controller_spec.rb:21:in `block (3 levels) in <top (required)>'

I also grabbed your version of products_controller_spec.rb on the Chapter7 branch just to make sure I didn't have any misconfigs.

kurenn commented 9 years ago

It has to be then with Shoulda Matchers, you think you can match the version on the repo?

godzilla74 commented 9 years ago

That was it!

This is what my Gemfile to looks like, in case you want to update the tutorial:

 group :test do
  gem "rspec-rails", "2.14"
  gem 'shoulda-matchers', "2.6.1"
end

Thanks!

kurenn commented 9 years ago

Thanks to you! =)