回溯过滤
以下配置设置将过滤掉来自 Rails gem 的回溯中的行,以减少测试失败输出中的噪音
RSpec.configure do |config|
config.filter_rails_from_backtrace!
end
rspec
在使用--backtrace
命令行选项运行时,始终会显示完整的回溯输出。
背景(使用filter_rails_from_backtrace!
)
假设有一个名为“spec/failing_spec.rb”的文件,其中包含
require "rails_helper"
RSpec.configure do |config|
config.filter_rails_from_backtrace!
end
RSpec.describe "Controller", type: :controller do
controller do
def index
raise "Something went wrong."
end
end
describe "GET index" do
it "raises an error" do
get :index
end
end
end
使用裸rspec
命令
当我运行rspec
时
那么输出应该包含“1 个示例,1 个失败”。
并且输出不应包含“actionpack”。
使用rspec --backtrace
当我运行rspec --backtrace
时
那么输出应该包含“1 个示例,1 个失败”。
并且输出应该包含“actionpack”。