3

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) { 'unregistered.user@mail.com' }
      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?

4

3 回答 3

6

好的,迁移到 RSpec3 是导致此问题的原因。我通过迁移到 RSpec 2.99.0 解决了这个问题,我收到了将此代码添加到我的 spec_helper 的提示

RSpec.configure do |config|
  config.infer_spec_type_from_file_location!
end

现在它起作用了。欢呼!

于 2014-06-25T07:51:31.587 回答
1

我已经infer_spec_type_from_file_location!设置好了,但是我们这里仍然使用 capybara 的特征语法,它可能将类型设置为 feature。一旦我更改featuredescribe,它就起作用了。

于 2014-11-19T11:10:01.583 回答
0

尝试添加助手以请求规格。在spec_helper.rb

config.include RSpec::Rails::RequestExampleGroup, type: :request

我也假设你有type: :request你的规范定义。

于 2014-06-24T15:07:52.053 回答