2014-06-24 61 views
2

在RSpec 3請求測試遷移後失敗。 這裏是我的測試RSpec 3錯誤在請求測試中未定義方法'get'

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 

這裏是rspec的日誌

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> 

這裏是什麼地方?

回答

5

好的,遷移到RSpec3是造成這個問題的原因。 我會通過遷移到RSpec的2.99.0解決它,我收到了提示添加以下代碼到我的spec_helper

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

現在,它的工作原理。歡呼!

0

嘗試添加助手來請求規格。在spec_helper.rb

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

此外,我假設你有type: :request你spec定義。

+0

我在'spec_helper'' config.include Requests :: JsonHelpers,type :: request'中有這個字符串,是不是一樣?此外,我已經找到了可以幫助我的解決方案,但是我沒有足夠的信譽來同時發佈它。您如何看待我和您的解決方案是相對的? –

1

我已經有infer_spec_type_from_file_location!集,但我們仍然在這裏使用了水豚功能語法,這可能會將類型設置爲功能。一旦我將feature更改爲describe,它就起作用了。

相關問題