没有使用Rspec的请求规格的Backtrace

时间:2014-08-13 07:52:03

标签: testing ruby-on-rails-4 rspec rspec3

我有这样的请求规范

require 'rails_helper'

describe 'People API' do

  describe 'GET /api/v1/people/lookup.json?phone_number=PHONE_NUMBER', :wip do
    it 'returns a 200 status code' do
      auth_get '/api/v1/people/lookup.json', phone_number: '91900199'
      expect(response.status).to eq(200)
    end
  end
end

如果规格因某种原因失败,我只会在响应中获得500状态代码,就是这样,所以我必须检查log/test.log文件才能知道出了什么问题,这很烦人

为什么rspec没有像其他类型的规格一样显示回溯?

以下是我运行规范的方法,请注意我包含-b选项

$ rspec -b -t wip -f documentation                                                                                                                                                                                                                                                                     
Run options: include {:wip=>true}

People API
  GET /api/v1/people/lookup.json?phone_number=PHONE_NUMBER
    returns a 200 status code

Failures:

  1) People API GET /api/v1/people/lookup.json?phone_number=PHONE_NUMBER with an empty phone number returns a empty response
     Failure/Error: expect(response.status).to eq(200)

       expected: 200
            got: 500

       (compared using ==)
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.0.1/lib/rspec/expectations/fail_with.rb:30:in `fail_with'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.0.1/lib/rspec/expectations/handler.rb:35:in `handle_failure'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.0.1/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-expectations-3.0.1/lib/rspec/expectations/expectation_target.rb:54:in `to'
     # ./spec/requests/api/v1/people_spec.rb:15:in `block (4 levels) in <top (required)>'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:148:in `instance_exec'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:148:in `block in run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `call'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-rails-3.0.1/lib/rspec/rails/adapters.rb:68:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:294:in `instance_exec'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:294:in `instance_exec'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:430:in `block (2 levels) in run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `call'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:210:in `block (2 levels) in <class:Procsy>'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:432:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/hooks.rb:485:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:303:in `with_around_example_hooks'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example.rb:145:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:494:in `block in run_examples'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:490:in `map'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:490:in `run_examples'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:457:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `block in run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `map'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `block in run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `map'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/example_group.rb:458:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `block (2 levels) in run_specs'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `map'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:112:in `block in run_specs'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/reporter.rb:54:in `report'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:108:in `run_specs'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:86:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:70:in `run'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/lib/rspec/core/runner.rb:38:in `invoke'
     # /Users/fespinoza/.rbenv/versions/2.1.1/lib/ruby/gems/2.1.0/gems/rspec-core-3.0.1/exe/rspec:4:in `<top (required)>'
     # /Users/fespinoza/.rbenv/versions/2.1.1/bin/rspec:23:in `load'
     # /Users/fespinoza/.rbenv/versions/2.1.1/bin/rspec:23:in `<main>'

Finished in 0.46863 seconds (files took 3.59 seconds to load)
1 examples, 1 failures

但它不包含500错误的真正原因

1 个答案:

答案 0 :(得分:0)

您的请求规范与您的完整堆栈交互,包括中间件。当您的某个控制器方法内部发生错误时,它会被捕获到堆栈的更高位置,以便可以将500错误返回给客户端。这就是你在断言失败中所看到的。

您可能可以编写自己的中间件用于测试目的,如果您真的需要,可以将错误打印到stderr