Tet*_*yna 2 testing rspec ruby-on-rails request rspec3
在RSpec 3上迁移后,请求测试失败.这是我的测试
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
Run Code Online (Sandbox Code Playgroud)
这是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>
Run Code Online (Sandbox Code Playgroud)
它能是什么?
好的,迁移到RSpec3是导致此问题的原因.我通过迁移到RSpec 2.99.0来解决它,我收到一个提示,将此代码添加到我的spec_helper
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
Run Code Online (Sandbox Code Playgroud)
现在它有效.欢呼!
归档时间: |
|
查看次数: |
1320 次 |
最近记录: |