运行 rspec 测试时仅显示失败原因

Show only fail reasons when running rspec tests

当 运行 命令行上的测试失败时,通常会显示如下示例:

(See full trace by running task with --trace)
F

Failures:

  1) Creating Post A user creates a new post
     Failure/Error: visit '/'

     ActionController::RoutingError:
       No route matches [GET] "/"
     # /home/user/.rvm/gems/ruby-2.3.3/gems/railties-5.0.3/lib/rails/rack/logger.rb:36:in `call_app'
     # /home/user/.rvm/gems/ruby-2.3.3/gems/railties-5.0.3/lib/rails/rack/logger.rb:24:in `block in call'
     # /home/user/.rvm/gems/ruby-2.3.3/gems/railties-5.0.3/lib/rails/rack/logger.rb:24:in `call'
     # /home/user/.rvm/gems/ruby-2.3.3/gems/rack-2.0.2/lib/rack/method_override.rb:22:in `call'
....

是否可以通过配置设置或其他方式显示失败错误?所以测试只会显示这个

F

Failures:

  1) Creating Post A user creates a new post
     Failure/Error: visit '/'

     ActionController::RoutingError:
       No route matches [GET] "/"

底部没有显示所有路径。我认为有时更容易检测到错误

有趣的是,我认为没有办法得到你想要的。起初,我认为你可以使用 backtrace filtering, but evidently when you filter everything, RSpec forces a full backtrace.

遗憾的是,我能提供的最好的是:

$ rspec spec/models/customer_spec.rb | grep -Ev '^\s+# '

但是您在输出中丢失了所有颜色。 =\