ruby-on-rails - 请求测试中的 RSpec 3 错误未定义方法 `get'

标签 ruby-on-rails testing rspec 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

这是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/

相关文章:

ruby-on-rails - rails : Self referential parent/child hierarchy without through table

ruby-on-rails - rails Controller 的速率限制

java - 如何更好地测试具有公共(public)队列的多线程程序?

java - 在 Windows 中运行 JAR 的问题,在 Ubuntu 中运行良好

java - 什么是测试预言机,它有什么用?

ruby-on-rails - 寻找RSpec的GUI

ruby-on-rails - rake 分贝 :migrate always outputs SELECT "schema_migrations". * 来自 "schema_migrations"

ruby-on-rails - 如何通过 gem OmniAuth Facebook/Twitter 注销社交网站

ruby-on-rails - 命名空间路由缺失模板错误

ruby-on-rails - 使用 FactoryGirl 包含在验证和 Rspec 中