Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting undefined method `get' for #<RSpec::ExampleGroups in my rspec

Rails 4.2.5, rspec-rails 3.0.2

I want to test my API. So I created requests directory inside /spec. There is a file called projects_spec.rb

Here is the code:

describe 'Projects API' do
  describe 'GET /projects' do
    it 'should return 401 HTTP code' do
      get '/api/v1/projects'
      expect(response.status).to eq(401)
    end
  end
end

And when I run this test I'm getting

NoMethodError: undefined method `get' for #RSpec::ExampleGroups::ProjectsAPI::GETProjects:0x007fee73ad9b48>

What's wrong?

# rails_helper.rb
config.infer_spec_type_from_file_location!
like image 608
Meliborn Avatar asked Nov 17 '25 11:11

Meliborn


1 Answers

describe 'Projects API', type: :request do
  # ...
end

Also, make sure you've included require 'rails_helper' in your projects_spec.rb.

like image 57
Andrey Deineko Avatar answered Nov 20 '25 05:11

Andrey Deineko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!