在rspec中运行所有项目规范时出错:`formatted_backtrace&#39 ;: undefined method`backtrace'

时间:2015-05-07 12:07:41

标签: ruby-on-rails ruby testing rspec

每当我在完成所有测试用例后尝试为整个项目运行rspec(有超过1000个测试)时,我会收到以下错误:

/home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:183:in `formatted_backtrace': undefined method `backtrace' for nil:NilClass (NoMethodError)
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:191:in `colorized_formatted_backtrace'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:276:in `formatted_message_and_backtrace'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:199:in `fully_formatted'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:122:in `block in fully_formatted_pending_examples'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `each'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `each_with_index'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/notifications.rb:121:in `fully_formatted_pending_examples'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/formatters/base_text_formatter.rb:50:in `dump_pending'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:146:in `block in notify'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:145:in `each'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:145:in `notify'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:123:in `finish'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/reporter.rb:64:in `report'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:108:in `run_specs'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:86:in `run'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:70:in `run'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/lib/rspec/core/runner.rb:38:in `invoke'
from /home/borisano/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.2/exe/rspec:4:in `<top (required)>'
from /home/borisano/.rbenv/versions/2.1.5/bin/rspec:23:in `load'
from /home/borisano/.rbenv/versions/2.1.5/bin/rspec:23:in `<main>'

当我只运行有限数量的测试用例时,例如,一个文件或单个文件夹,一切正常。

这是我的.rspec文件

--color
--require rails_helper

spec_helper.rb

require "rack_session_access/capybara"
RSpec.configure do |config|
end

所以没有什么可疑的,就像我一样

关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:1)

将此添加到您的.rspec文件中:

--require spec_helper

这可以保证在每个规范之前都需要spec_helper。