4

我正在尝试将 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
4

1 回答 1

5

要注册您的裸应用程序,您需要将应用程序设置为 Sinatra::Application:

specApiDocumentation.configure do |config|
#  config.app = App 
end

到:

specApiDocumentation.configure do |config|
   config.app = Sinatra::Application
end 
于 2012-05-10T15:15:37.810 回答