gpt4 book ai didi

ruby-on-rails - rspec_api_documentation - 未定义方法 `call' 为 nil :NilClass

转载 作者:行者123 更新时间:2023-12-04 02:14:33 25 4
gpt4 key购买 nike

我刚开始使用 rspec_api_documentation 并且无法让它与我的 api 一起工作。创建了简单的规范,与自述文件中的第一个示例一样基本,但它一直向我抛出 undefined method 'call' for nil:NilClass 错误,我不知道是什么导致了问题。

这是完整的堆栈跟踪:

  1) Users GET /api/v1/users Listing users
Failure/Error: do_request
NoMethodError:
undefined method `call' for nil:NilClass
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/mock_session.rb:30:in `request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/test.rb:244:in `process_request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rack-test-0.6.3/lib/rack/test.rb:58:in `get'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/rack_test_client.rb:38:in `do_request'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/client_base.rb:42:in `process'
# /home/swistak/.rvm/gems/ruby-2.2.2/gems/rspec_api_documentation-4.7.0/lib/rspec_api_documentation/client_base.rb:12:in `get'
# ./spec/acceptance/users_spec.rb:7:in `block (3 levels) in <top (required)>

这是规范

require 'spec_helper'
require 'rspec_api_documentation/dsl'

RSpec.resource 'Users' do
get '/api/v1/users' do
example 'Listing users' do
do_request

status.should == 200
end
end
end

这是 Controller

class Api::V1::UsersController < ApplicationController
skip_before_action :authenticate_with_token, only: %i(index show create)

expose(:users)

def index
render json: users, each_serializer: ::V1::UserSerializer
end
end

我的 api 在 localhost:3000/api/v1/users 下

感谢任何帮助

最佳答案

似乎需要配置 block ,所以我刚刚创建了acceptance_helper.rbexample application并在规范中导入它。

关于ruby-on-rails - rspec_api_documentation - 未定义方法 `call' 为 nil :NilClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35080994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com