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