Search code examples
rspecrspec2rspec-railsguard

How can you get rspec to print failed test backtraces *as* it is running?


Our test quite takes a while to run, and there is always this 5-10 minute period where we know which test has failed, but we can't see the failure message or backtrace until the suite finishes. It would be more efficient to see the backtraces as they happen. Is this possible?


Solution

  • You have two options:

    1) fail fast

    # spec/spec_helper.rb
    RSpec.configure do |c|
      c.fail_fast = true
    end
    

    ..or use it from the command line

    $ bundle exec rspec spec/ --fail-fast
    .F
    
    Failures:
      1) Swinger should set the Capybara driver
         Failure/Error: Capybara.current_driver.should_not == :rack_test
    
    Finished in 0.00479 seconds
    2 examples, 1 failure
    

    Basically this option on error will stop the test suite and it will print the error.

    2) use rspec-instafail gem

    https://github.com/grosser/rspec-instafail

    This gem will show failing spec instantly and it will continue running specs.