我试图清理我在Rails应用程序中得到的回溯。这是我现在正在进行的工作:
Failure/Error: attributes_for :bookmark, :invalid
ArgumentError:
Trait not registered: invalid
# /Users/amandacrawford/.rvm/gems/ruby-2.3.1@autocato/gems/factory_girl-4.8.0/lib/factory_girl/registry.rb:24:in `find'
# /Users/amandacrawford/.rvm/gems/ruby-2.3.1@autocato/gems/factory_girl-4.8.0/lib/factory_girl/decorator.rb:10:in `method_missing'
# (... more lines from Factory Girl ...)
# /Users/amandacrawford/.rvm/gems/ruby-2.3.1@autocato/gems/factory_girl-4.8.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method'
# ./spec/controllers/bookmarks_controller_spec.rb:9:in `block (2 levels) in <top (required)>'
# ./spec/controllers/bookmarks_controller_spec.rb:39:in `block (4 levels) in <top (required)>'
我希望从堆栈跟踪中删除除最后两行之外的所有行。到目前为止,这是我的配置:
# config/initializers/backtrace_silencers.rb
Rails.backtrace_cleaner.add_silencer { |line| line =~ /spring/ }
Rails.backtrace_cleaner.add_silencer { |line| line =~ /factory_girl\/registry/ }
我知道如果在应用消音器后应用程序堆栈跟踪为空,它将显示所有内容,但在这种情况下,应该仍然有最后两行。
答案 0 :(得分:1)
我今天遇到了自己问题的答案 - 当我的一个规格删除了完整的回溯时,我意识到RSpec正在清理这种情况下的回溯。
RSpec has a way to remove gems from the backtrace - 将以下内容添加到rails_helper.rb
:
config.filter_gems_from_backtrace('spring', 'factory_girl')