在 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
这是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>
它可以是什么?
最佳答案
好的,迁移到 RSpec3 是导致此问题的原因。 我通过迁移到 RSpec 2.99.0 解决了这个问题,我收到了将这段代码添加到我的 spec_helper 的提示
RSpec.configure do |config|
config.infer_spec_type_from_file_location!
end
现在可以了。欢呼!
关于ruby-on-rails - 请求测试中的 RSpec 3 错误未定义方法 `get',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24382038/