kurenn / market_place_api

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

Chapter 3: User controller spec error with `respond_with` #56

Closed SpacyRicochet closed 8 years ago

SpacyRicochet commented 8 years ago

Right before listing 3.2.1, the following line in users_controller_spec.rb gives a NoMethodError.

https://github.com/kurenn/market_place_api/commit/59daf641120b75fa79dd064a07d80fdc31d3bc1e#commitcomment-15067079

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

Some searching on the internet suggests this is because the spec doesn't handle the route as an API which does implement respond_with. However, I'm at a loss why this currently is the case.

This issue suggested that the configuration might be off, but following that suggestion pops up other errors.

Any ideas why that spec line fails?

SpacyRicochet commented 8 years ago

I seem to have fixed it by adding the following to spec_helper.rb as suggested in this comment.

  Shoulda::Matchers.configure do |config|
        config.integrate do |with|
            # Choose a test framework:
            with.test_framework :rspec
            with.library :rails
        end
    end
SpacyRicochet commented 8 years ago

Additionally, I had to change the validate_uniqueness_of test to be case insensitive;

it { should validate_uniqueness_of(:email).case_insensitive }

All passes now.