【问题标题】:When using Capybara/Poltergeist, how to access application thread with pry使用 Capybara/Poltergeist 时,如何使用 pry 访问应用程序线程
【发布时间】:2013-11-08 15:05:20
【问题描述】:

我正在 Rails 和 emberjs 应用程序上运行测试,并且在我的测试中设置了 :js => true 。我可以在规范中删除 binding.pry 并且它会弹出打开 REPL 就好了,但是如果我在应用程序中删除 binding.pry,REPL 将显示在控制台中,但规范继续。我相信,这是因为使用 poltergeist 作为驱动程序,capybara 在一个线程中运行规范,而在另一个线程中运行应用程序。有没有办法进行设置,以便我可以在应用程序代码中使用 binding.pry 打开 REPL 并暂停应用程序和规范?

下面是一个运行良好的 binding.pry 语句示例,并且被遗忘的语句:

作品:

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

被抛在后面:

sessions_controller.rb

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

  respond_to :json

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

【问题讨论】:

  • 有趣...我们成功地在 selenium 和 poltergeist 驱动的规范中使用 binding.pry,没有任何问题。您能否提供一个可以重现该问题的最小代码示例?
  • @ChrisCashwell,在上面添加了一些示例代码,但不是您可以轻松复制它的东西;周末有时间我会创建一个基本的 ruby​​/ember 应用程序并将其放在 github 上用于说明目的。
  • @ChrisCashwell 您是否将 binding.pry 放入应用程序代码和规范文件中?
  • 我们可以将绑定放在规范或实现中。两种方式都没有问题。

标签: ruby-on-rails multithreading capybara pry poltergeist


【解决方案1】:

在分叉的进程中使用 pry 不起作用。

您需要使用PryRemote 连接到另一个远程进程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多