Reputation: 1074
After migration on RSpec 3 request test fails. Here is my test
describe 'GET /api/v1/activities' do
let!(:user) { create(:user) }
subject { json['activities'] }
context 'when not authenticated' do
let(:token) { user.authentication_token }
let(:email) { '[email protected]' }
before :each do
get '/api/v1/activities', {}, {token: token, email: email}
end
it { expect(response).to_not be_success }
end
end
Here is rspec log
Activities GET /api/v1/activities when not authenticated
Failure/Error: get '/api/v1/activities', {}, {token: token, email: email}
NoMethodError:
undefined method `get' for #<RSpec::ExampleGroups::Activities::GETApiV1Activities::WhenNotAuthenticated:0x0000000becfaf8>
What can it be?
Upvotes: 3
Views: 1599
Reputation: 17392
I already had infer_spec_type_from_file_location!
set, but we still used the capybara feature syntax here, which probably sets the type to feature. Once I changed feature
to describe
, it worked.
Upvotes: 1
Reputation: 1074
Ok, migration to RSpec3 was the cause of this issue. I'd resolved it by migrating to RSpec 2.99.0 and I received a hint to add this code to my spec_helper
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
Now it works. Hurray!
Upvotes: 6
Reputation: 10825
Try to add helper to request specs. In spec_helper.rb
:
config.include RSpec::Rails::RequestExampleGroup, type: :request
Also i assume that you have type: :request
in you spec definition.
Upvotes: 0