堆栈级别太深(SystemStackError)时使用rspec和黄瓜与ruby和rails [英] stack level too deep (SystemStackError) when using both rspec and cucumber with ruby and rails
问题描述
这是一个关于当使用Ruby和Rails遇到堆栈层太深(SystemStackError)时应该使用什么调试策略的问题。
我看到这些错误使用rspec或cucumber
perrys-MacBook-Pro:pc perry_mac $ cucumber
堆栈级别太深(SystemStackError)
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240
perrys-MacBook -Pro:pc perry_mac $ rspec
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240:stack level too deep(SystemStackError)
perrys-MacBook-Pro:pc perry_mac $
我这里介绍的是独立的rspec和黄瓜。我不知道如何缩小问题。
我已尝试过 bundle update
,运行正常。
应用程序在 rails s
下运行良好,但我想使用我编写的rspec和黄瓜测试。
ADDENDUM:
我用最简单的测试看到这个,例如:
perrys-MacBook-Pro:pc perry_mac $ cat ./spec/controllers/page_controller_spec.rb
require'spec_helper'
describe PageController do
end
perrys-MacBook-Pro:pc perry_mac $ rspec ./spec/controllers/page_controller_spec.rb
/Users/perry_mac/.rvm/ gems / ruby-1.9.3-p327 / gems / activesupport-3.2.13 / lib / active_support / dependencies.rb:240:stack level too deep(SystemStackError)
perrys-MacBook-Pro:pc perry_mac $
ADDENDUM 2:
spec_helper的pastebin在这里: http://pastebin.com/ePdGyHQh
附录3:
Gemfile的pastebin这里: http://pastebin.com/xkLYGjsY
ADDENDUM 4:我确定这是在spec_helper.rb中导致错误的行
require File.expand_path ../../config/environment,__FILE__)
如果我把一个故意的语法错误在这行之前,我得到一个'语法错误'如果我把相同的语法错误后的行,我得到'堆栈太深的错误。
看起来像一些进步。应该需要File.expand_path(../../ config / environment,__FILE __)
以其他方式编写吗?
ADDENDUM 5:
我将它添加到了spec_helper.rb:
puts File.path ./../config/environment)
puts __FILE__
require File.expand_path(../../ config / environment,__FILE__)
现在可以看到:
perrys-MacBook -Pro:pc perry_mac $ rspec ./spec/controllers/page_controller_spec.rb
../../config/environment
/Users/perry_mac/rails_projects/pc/spec/spec_helper.rb
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240:栈级太深(SystemStackError)
perrys- MacBook-Pro:pc perry_mac $
...但不知道什么是输出。
ADDENDUM 6:
使用pry,我走过了代码。失败之前的输出的粘贴在此处: http://pastebin.com/c6ZfPmVn 这是有帮助的,或应该我包括别的东西?看起来像执行一直持续到这一点:/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327 /gems/rspec-core-2.13.1/lib/rspec/core.rb @ line 69 RSpec.reset
ADDENDUM 7:
我刚刚确认,我可以检出一个较旧的git分支,有工作rspec和黄瓜。可以有一个工作分支帮助我以任何方式调试更近的折断分支?
附录8:根据Pry执行追踪,调用Rspec.reset后会立即发生错误
解决方案我发现原因使用
git bisect
和
git show [commitID ]
我能够回到我的提交日志,找到一个工作版本。然后,使用git bisect
这里,我能够找到提交堆栈太深的错误。然后,我使用git show [commitID]
来查看两个潜在的代码行。它们是:#file:app / controllers / thisControllerFileIhave.rb
需要'dicom'
包括DICOM
进行此更改似乎已解决问题:
require'dicom'
#include DICOM
$ b坦白地说,我不记得为什么我添加了包括DICOM(提交是在2012年10月),我也不知道为什么或如何这会导致rspec和黄瓜失败,如此壮观和神秘。我也不知道如何运行应用程序在
rails s
适用于这个代码,但测试套件不。我会感谢建议git bisect
的海报,但他们的评论似乎已被移除。
答案和评论我得到的这个问题没有直接解决调试策略,因为他们提供了第一手帐户,当作者看到和纠正这样的错误。我很感谢遇到
git bisect
和git show
,我觉得他们是真正强大的选择,精确定位源的问题,像这一个。This is a question about what debugging strategy I should use when encountering a stack level too deep (SystemStackError) using Ruby and Rails.
I am seeing these errors when using either rspec or cucumber
perrys-MacBook-Pro:pc perry_mac$ cucumber stack level too deep (SystemStackError) /Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240 perrys-MacBook-Pro:pc perry_mac$ rspec /Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240: stack level too deep (SystemStackError) perrys-MacBook-Pro:pc perry_mac$
I suspect the problem I have introduced here is independent of both rspec and cucumber. I'm not sure how to narrow down the problem. What should I try next?
I have already tried
bundle update
, which ran fine.The app runs fine under
rails s
, but I'd like to make use of the rspec and cucumber tests I've written.ADDENDUM:
I see this with the simplest of tests, for instance:
perrys-MacBook-Pro:pc perry_mac$ cat ./spec/controllers/page_controller_spec.rb require 'spec_helper' describe PageController do end perrys-MacBook-Pro:pc perry_mac$ rspec ./spec/controllers/page_controller_spec.rb /Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240: stack level too deep (SystemStackError) perrys-MacBook-Pro:pc perry_mac$
ADDENDUM 2: pastebin of spec_helper is here: http://pastebin.com/ePdGyHQh
ADDENDUM 3: pastebin of Gemfile is here: http://pastebin.com/xkLYGjsY
ADDENDUM 4: I have determined that this is the line in spec_helper.rb that leads to the error
require File.expand_path("../../config/environment", __FILE__)
If I put a deliberate syntax error right before that line, I get a 'syntax error' If I put the same syntax error after the line, I get the 'stack too deep error.'
Seems like some progress. Should
require File.expand_path("../../config/environment", __FILE__)
be written some other way?ADDENDUM 5: I added this to spec_helper.rb:
puts File.path("../../config/environment") puts __FILE__ require File.expand_path("../../config/environment", __FILE__)
and now see this:
perrys-MacBook-Pro:pc perry_mac$ rspec ./spec/controllers/page_controller_spec.rb ../../config/environment /Users/perry_mac/rails_projects/pc/spec/spec_helper.rb /Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:240: stack level too deep (SystemStackError) perrys-MacBook-Pro:pc perry_mac$
... but am not sure what the implications are based on the output.
ADDENDUM 6:
Using pry, I stepped through the code. A pastebin of the output just before failure is here: http://pastebin.com/c6ZfPmVn Is this helpful or should I include something else? Looks like execution continues up until this point:/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/rspec-core-2.13.1/lib/rspec/core.rb @ line 69 RSpec.reset
ADDENDUM 7: I just confirmed I can checkout an older git branch that has working rspec and cucumber. Could having a working branch help me debug the more recent broken branch in any way?
Addendum 8: According to the Pry execution trace, the error happens immediately after a call to Rspec.reset
解决方案I found the cause using
git bisect
and
git show [commitID]
I was able to go back through my log of commits and find a working version. Then, using the instructions for
git bisect
here, I was able to find the commit that introduced the stack too deep error. I then usedgit show [commitID]
to see two potential lines of code that were to blame. They were:# file:app/controllers/thisControllerFileIhave.rb require 'dicom' include DICOM
making this change seems to have fixed the problem:
require 'dicom' #include DICOM
Quite honestly, I do not recall why I added 'include DICOM' (commit was in Oct,2012) nor do I understand why or how this would cause both rspec and cucumber to fail so spectacularly and cryptically. Nor do I understand how running the app under
rails s
works fine with this code, but the test suite does not. I would thank the poster who suggestedgit bisect
, but their comment seems to have been removed.Most of the answers and comments I got for this question did not directly address a debugging strategy as much as they offered first hand accounts of when the authors had seen and corrected an error like this. I am grateful to have come across
git bisect
andgit show
and I feel they are really powerful options for pinpointing the source of problems like this one.这篇关于堆栈级别太深(SystemStackError)时使用rspec和黄瓜与ruby和rails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!