1

我遇到了一个奇怪的无限递归,它只出现在 Rspec 测试中。奇怪的是,这是由于向我的用户对象添加了审核,即使它失败的规范实际上与我的用户对象无关

这是它失败的测试。像所有无限递归一样,我没有得到实际的 stracktrace,只有堆栈级别太深失败:

 1) Spree::CheckoutController order in address state #update payment to complete step should set the address id on a newly created credit card; does not regress https://www.pivotaltracker.com/story/show/84864964
     Failure/Error: Unable to find matching line from backtrace
     SystemStackError:
       stack level too deep
     # /Users/jason/.rvm/gems/ruby-2.1.5/gems/activerecord-4.1.11/lib/active_record/connection_adapters/abstract/database_statements.rb:212
4

1 回答 1

1

我将其隔离到 Rspec 中的 after 挂钩,该挂钩是根据数据库清理器设置进行配置的,如下所示:

  config.after(:each) do
    DatabaseCleaner.clean
    Warden.test_reset!
  end

修复只是关闭对我的用户模型的审核,如下所示:

  config.after(:each) do
    Spree::User.auditing_enabled = false # disable acts_as_audited during database cleanup
    DatabaseCleaner.clean
    Warden.test_reset!
  end
于 2015-09-03T14:43:45.167 回答