Monday, September 15, 2014

RSpec appears to stop prematurely without any all test output running feature test with Capybara


I recently ran into an issue where a particular feature test (using RSpec and Capybara) was prematurely exiting to the command prompt and not reporting any error.   Or at least that is what I thought was happening until I dug into the issue a bit more.  As it turns out the normal console output from RSpec wasn't showing completely and then the test would just stop.   In reality that test and all other tests were running to completion and this was obvious once I looked in my log files.   After I realized that the tests kept running then the other explanation was that something stole $stdout from RSpec.

This post on is where I found my answer to the problem.  The problem described on this post matched what I was seeing.  I inserted the following code:

Capybara.server do |app, port|
  require 'rack/handler/thin', :Port => port)

near the top of my rails_helper.rb to trigger the use of Thin instead of the default web server for Capybara.  After this change I started to see all the test output.

I've made this post because it was particularly tricky to figure out what was happening and my search results kept turning up things that didn't help.  Hopefully this will help you out!