rspec上的Ruby分段错误

时间:2013-06-18 20:17:38

标签: ruby ruby-on-rails-3 rspec-rails

这真的很奇怪。我在这个Rails 3.2.11应用程序中做得很好,之前运行了rspec这是我创建了一个新的分支,更改了一个文件,已经提交,并且当我遇到大量的Segmentation错误和堆栈跟踪时,运行了rspec spec /正如我所见。

我已经更新了rvm并尝试安装早期版本的ruby 1.9.3。我一直挂在原始宝石上,并通过重新启动来保护。重新启动OS X 10.8.3后,我能够干净地安装ruby 1.9.3-p429。但是rspec仍然保释。完整堆栈跟踪为https://gist.github.com/sam452/5808849。因为它们被清理干净,所以我已经捆绑了宝石。我还尝试再次运行rspec生成器,但它似乎只覆盖了一个支持文件。铁路,耙子,黄瓜似乎运行正常。 Rake在进入rspec命令时失败。

我试图从堆栈跟踪中提取看似相关的部分:

    Happenstance:tickat sam$ rspec spec/
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/better_errors-0.8.0/lib/better_errors/core_ext/exception.rb:9: [BUG] Segmentation fault
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.3.0]

控制框架信息

c:0064 p:---- s:0204 b:0204 l:000203 d:000203 CFUNC  :callers
c:0063 p:0064 s:0201 b:0201 l:000290 d:0026c0 LAMBDA /Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/better_errors-0.8.0/lib/better_errors/core_ext/exception.rb:9
c:0062 p:---- s:0198 b:0198 l:000197 d:000197 FINISH

Ruby级别回溯信息

/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:17:in `block in autorun'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/runner.rb:80:in `run'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/command_line.rb:22:in `run'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load_spec_files'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `each'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `block in load_spec_files'
/Users/sam/.rvm/gems/ruby-1.9.3-p429/gems/rspec-core-2.13.1/lib/rspec/core/configuration.rb:819:in `load'
/Users/sam/apps/tickat/spec/controllers/admin/events_controller_spec.rb:1:in `<top (required)>'

C级回溯信息

   See Crash Report log file under ~/Library/Logs/CrashReporter or
   /Library/Logs/CrashReporter, for the more detail of.

其他运行时信息

* Loaded script: /Users/sam/.rvm/gems/ruby-1.9.3-p429/bin/rspec
* Loaded features:
    0 enumerator.so
    1 /Users/sam/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/x86_64-darwin12.3.0/enc/encdb.bundle
    2 /Users/sam/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/1.9.1/x86_64-darwin12.3.0/enc/trans/transdb.bundle
    3 /Users/sam/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/defaults.rb

一直到2030行。

3 个答案:

答案 0 :(得分:16)

Rspec 会在某些情况下导致分段错误,例如,如果您以递归方式let!定义变量。这可以在RSpec核心中生成vm_call_cfunc - cfp consistency error,Ruby崩溃报告和Segmentation fault: 11

let!(:some_var) { "Some value" }

describe '.method' do
  ...
  let!(:some_var) { create(:model, some_var: some_var) }
end

答案 1 :(得分:4)

确保从Gemfile中的测试组中删除better_errors和可能binding_of_caller,这就是导致错误的原因。如果您查看报告分段错误的行,则better_errors报告它:

.../better_errors/core_ext/exception.rb:9: [BUG] Segmentation fault 

所以你的Gemfile应该是这样的:

group :development do
  gem 'better_errors'
  gem 'binding_of_caller'
end

# for testing to work with rspec
group :test do
  gem 'rspec-rails'
  gem 'factory_girl_rails'
  gem 'ffaker'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'launchy'
end

答案 2 :(得分:0)

虽然我仍然不知道为什么rspec在'分离的HEAD'状态下工作,但是在提交时却没有,我最终得到了gem uninstall better_errors,我讨厌这样做。在堆栈跟踪的前几行中,似乎出于某种原因与Ruby和better_errors存在冲突。我会提交一份报告。谢谢你的帮助。