Search code examples
ruby-on-railsrspectddbdd

Show only fail reasons when running rspec tests


When running a test on the command line which fails usually it shows something like this example:

(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'
....

Is it possible to show only the fail error, by a config setting or something? so the test would show only this

F

Failures:

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

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

without all that paths showing at the bottom. I think sometimes its easier to detect the error


Solution

  • Interestingly, I don't think there's a way to get what you want. At first, I believed you could use backtrace filtering, but evidently when you filter everything, RSpec forces a full backtrace.

    Sadly, the best I can offer is:

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

    But you lose all color in your output. =\