rspeccapybarapoltergeistzeus

zeus rspec doesn't return to shell when js:true and driver=:poltergeist_debug


After running zeus rspec spec/, the command doesn't return control back to the bash shell if there is an example that uses js:true. It runs the test and reports the result, but it doesn't exit. However, it runs fine if I just run rspec without zeus

I can recreate the problem with this trivial spec:

require 'spec_helper'

describe "users index" do
  before { visit root_path }

  it "should not hang", js: true do
    expect(page).to have_content("Welcome")
  end  
end

Here are the salient sections of my spec_helper.rb:

require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, inspector: true)
end

RSpec.configure do |config|

  config.use_transactional_fixtures = false
  config.before(:each) do
    DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
    DatabaseCleaner.start
  end
  config.after(:each) do
    DatabaseCleaner.clean
  end

  config.infer_base_class_for_anonymous_controllers = false

  config.include Capybara::DSL
end

I tried removing database_cleaner but that didn't seem to affect anything.

Here are my gems of interest

ruby '2.0.0'
gem 'rails', '4.0.2'

group :development, :test do
  gem 'rspec-rails', '2.14.1'
  gem 'guard-rspec', '4.2.3'
  gem 'teaspoon', '0.7.7'
  gem 'guard-teaspoon', '0.0.4'
  gem 'poltergeist', '1.5.0'
  gem 'database_cleaner', '1.2.0'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.3.0'
end

I am using phantomjs 1.9.0 via brew


Solution

  • Per https://github.com/jonleighton/poltergeist#remote-debugging-experimental, this code is experimental:

    Capybara.register_driver :poltergeist do |app|
      Capybara::Poltergeist::Driver.new(app, inspector: true)
    end
    

    If I remove it, then zeus rspec spec/ returns control back to the shell.

    The solution is to register the experimental code as a separate driver called :poltergeist_debug:

    Capybara.register_driver :poltergeist_debug do |app|
      Capybara::Poltergeist::Driver.new(app, inspector: true)
    end
    
    Capybara.javascript_driver = :poltergeist
    

    and only use that driver on an ad hoc basis when I need to inspect the state of the web browser

    require 'spec_helper'
    
    Capybara.javascript_driver = :poltergeist_debug
    
    describe "users index" do
      before { visit root_path }
    
      it "should not hang", js: true do
        page.driver.debug
        expect(page).to have_content("Welcome")
      end  
    end
    

    and debug the spec outside of zeus