我正在尝试将 rspec_api_documentation (https://github.com/zipmark/rspec_api_documentation) 集成到我的 sinatra 应用程序中。我遇到了下面的错误。我显然已经将错误简化为一个简单的测试,因为我认为一旦我找出配置中的错误,它就会在重新集成到我更大的应用程序中后工作。
谢谢!
在 app.rb 中:
require 'rubygems'
require 'sinatra'
get '/index' do
"hewoah!"
end
在 spec.rb 中:
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"
RspecApiDocumentation.configure do |config|
# config.app = App
end
resource "Users" do
get "/index" do
example "Returns text" do
do_request
status.should be_ok
end
end
end
rspec spec/acceptance/spec.rb --require ./app.rb
的结果F
Failures:
1) Users GET /index Returns text
Failure/Error: do_request
NoMethodError:
undefined method `call' for nil:NilClass
# ./spec/acceptance/spec.rb:11:in `block (3 levels) in <top (required)>'
Finished in 0.02234 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/acceptance/spec.rb:10 # Users GET /index Returns text
最佳答案
要注册您的裸应用程序,您需要将应用程序设置为 Sinatra::Application:
specApiDocumentation.configure do |config|
# config.app = App
end
至:
specApiDocumentation.configure do |config|
config.app = Sinatra::Application
end
关于ruby - 为什么这个 rspec 测试会为 nil :NilClass"error? 抛出 "undefined method ` 调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10536846/