6

这真的很奇怪。我在这个 Rails 3.2.11 应用程序中做得很好,早些时候运行了 rspec,我创建了一个新分支,更改了一个文件,提交,然后运行 ​​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 生成器,但它似乎只覆盖了一个支持文件。Rails、rake、cucumber 似乎运行良好。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 行。

4

3 回答 3

20

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

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

describe '.method' do
  ...
  let!(:some_var) { create(:model, some_var: some_var) }
end
于 2015-07-15T14:50:51.570 回答
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
于 2013-09-16T15:14:32.913 回答
0

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

于 2013-06-21T22:23:23.587 回答