为什么这个rspec测试为nil:NilClass错误抛出了一个“未定义的方法'调用'?

时间:2012-05-10 15:03:10

标签: ruby rspec

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

1 个答案:

答案 0 :(得分:4)

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

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

要:

specApiDocumentation.configure do |config|
   config.app = Sinatra::Application
end