I trying to get a backtrace with rspec but I can't get it working for some reason.
This is the test file:
require 'spec_helper'
describe ActivityReport do
it "should create a new instance given valid attributes" do
activity = Factory(:activity_report)
end
This is the command I run:
rspec --backtrace spec/models/activity_report_spec.rb
And this is what I get:
No examples matched {:focus=>true}. Running all.
ActivityReport
should create a new instance given valid attributes (FAILED - 1)
Failures:
1) ActivityReport should create a new instance given valid attributes
Failure/Error: Unable to find matching line from backtrace
SystemStackError:
stack level too deep
# /Users/pbartels/.rvm/gems/ruby-1.9.2-p290@brothelking/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:206
Finished in 40.76 seconds
1 example, 1 failure
Failed examples:
rspec ./spec/models/activity_report_spec.rb:16 # ActivityReport should create a new instance given valid attributes
My .rspec:
--format nested
--color
--drb
--backtrace
And my RSpec part in spec_helper.rb:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
require 'database_cleaner'
require 'active_record/fixtures'
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.start
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
config.backtrace_clean_patterns = [
/\/lib\d*\/ruby\//,
/bin\//,
#/gems/,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
end
I tried it with and without "backtrace_clean_patterns".
Anyone knows what's wrong here?
There's no backtrace because it isn't a given line of code that's failing, it's actually the structure of your code. The ruby interpreter is literally running out of room to store further method calls on the stack.
Stack level too deep
typically means that you've got recently added/modified code that is calling itself, and going into a infinitely recursive black hole. Look at the code that you've recently added (including tests) for the clue. See if you're calling a method from within itself.
For example, this code will cause stack overflow:
def recursive_method
recursive_method
end
You've probably got a method call or field that shares the name of a method, and when you reference it, it's going into this infinite loop/recursive call.
If that doesn't point you in the right direction, you may be forced to incrementally revert you recent code changes until the problem goes away. When you get back to a state in your code where the problem goes away, you'll know that the issue has something to do with that change, though the specifics may not be immediately clear.
The other option, if you're really not getting anywhere with that (or it's not feasible to revert changes in an intelligent way), is to start adding debug lines to your code where you suspect the problem might be. Somehow you'll need to get your app to write to a log file or something so you can figure out what it is that it's doing right before it dies.