运行 RSpec 时 Mac 上的 rvm'd Ruby 出现分段错误
我在大学时正在开发一些东西,保存到我的 Dropbox 中,打算在家继续使用。这是迎接我的消息:
$ spec graph_spec.rb
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/gems/PriorityQueue-0.1.2/ext/priority_queue/CPriorityQueue.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
但是,
$ `which spec` graph_spec.rb
...........................................................................
Finished in 0.046973 seconds
75 examples, 0 failures
这里到底发生了什么?
供参考:
$ which spec
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/bin/spec
更新:我刚刚注意到那里有 1.8.7...它是如何到达那里的?规范文件的顶部写着:
$ head `which spec`
#!/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
哪里写着“run 1.8.7”?!?
I was developing something at the uni, saved to my Dropbox intending to continue at home. This is the message that greeted me:
$ spec graph_spec.rb
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/gems/PriorityQueue-0.1.2/ext/priority_queue/CPriorityQueue.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
However,
$ `which spec` graph_spec.rb
...........................................................................
Finished in 0.046973 seconds
75 examples, 0 failures
What the heck is going on here?
For the reference:
$ which spec
/Users/amadan/.rvm/gems/ruby-1.9.2-rc1/bin/spec
UPDATE: I just noticed the 1.8.7 there... how did it get there? The top of the spec file says:
$ head `which spec`
#!/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'rspec' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Where does it say "run 1.8.7"?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RVM 很可能会弄乱您的宝石和红宝石。我建议在清理后的 RVM 安装上进行测试(仅安装 1.9)。
/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby真的是 ruby 1.9.2 吗?
其他测试方法是显式运行 ruby spec,这样您就可以确定调用的确实是 1.9.2。
总而言之,段错误确实在 ruby 中发生(尤其是在 1.8 上),有时可以通过稍微重新组织 ruby 代码来避免。祝你好运 !
It's likely that RVM is messing your gems and rubies. I would recommend testing on a cleaned up RVM installation (with only 1.9 installed).
Is
/Users/amadan/.rvm/rubies/ruby-1.9.2-rc1/bin/ruby
really ruby 1.9.2 ?Other way to test would be to explicitely run
ruby spec
so you are sure this is really 1.9.2 which is called.To conclude, Segfaults do happen in ruby (esp. on 1.8) and are sometimes avoided by reorganizing slightly the ruby code. Good Luck !