John
John

Reputation: 13705

When using Capybara/Poltergeist, how to access application thread with pry

I am running tests on a rails and emberjs application and have :js => true set on my tests. I can drop a binding.pry in the spec and it pops open a REPL just fine, but if I drop a binding.pry in the app, the REPL will show up in the console, but the spec continues. This, I believe, happens because with poltergeist as the driver, capybara runs the spec in one thread and the application in another thread. Is there a way to set things up so that I can use binding.pry in the application code to open a REPL and pause both the app and the spec?

Here is an example of the binding.pry statement that works fine and the one that gets left behind:

Works:

employee_signs_in_spec.rb

require 'spec_helper'
feature 'Visitor signs in', :js => true do
  scenario 'Success' do
    visit '/sign_in'
    sign_in_as(FactoryGirl.create(:employee, confirmed_at: Time.now))
    binding.pry
    page.should have_content('Example Content')
  end
end

Gets left behind:

sessions_controller.rb

class SessionsController < Devise::SessionsController
  include Devise::Controllers::Helpers

  respond_to :json

  def create
    binding.pry
    # code for create action
  end
end

Upvotes: 1

Views: 941

Answers (1)

phoet
phoet

Reputation: 18835

Using pry in a forked process does not work.

You will need to use PryRemote to hook into another remote process.

Upvotes: 0

Related Questions