Poltergeist 和 RSpec 的水豚错误

Capybara error with Poltergeist and RSpec

我正在尝试使用 RSpec 中的 Poltergeist 驱动程序为 Capybara 编写一个简单的规范。当测试失败时似乎没有问题,但是当我期待通过测试时,我收到以下错误:

   ~/.rbenv/versions/2.2.3/lib/
    ruby/gems/2.2.0/gems/poltergeist-1.6.0/lib/capybara/poltergeist/errors.rb:17:in 
   `initialize': wrong number of arguments (0 for 2) (ArgumentError)

我导航到错误指示的代码行所在的位置:

class JSErrorItem
      attr_reader :message, :stack

      def initialize(message, stack)
        @message = message
        @stack   = stack
      end 

      def to_s
        [message, stack].join("\n")
      end 
    end 

但我无法找到我应该与此构造函数交互的任何地方。

这是我正在编写的规范

describe 'Sign Up', type: :feature do
  it 'should allow user creation through the signup form' do  
    visit new_user_url host: 'http://localhost:3000'
    within('.form') do
      fill_in('user[username]', with: 'Example')
      fill_in('user[password]', with: 'Password')
      fill_in('user[password_confirmation]', with: 'Password')
      find(".submit-button").click   
      puts page.body
      expect(page).to have_content('Welcome')
      User.last.destroy!
    end 
  end 
end

puts page 按预期打印页面内容,但在发生错误之后,规范中的其余行不是 运行。奇怪的是,错误仅在我期望规范通过时才会发生。当我期待整个规范 运行s 没有错误的测试失败时。

我的规范助手设置如下:

RSpec.configure do |config|
    require 'capybara/rspec'
    require 'capybara/poltergeist'
    require 'capybara/dsl'

    Capybara.register_driver :poltergeist do |app|
      Capybara::Poltergeist::Driver.new(app, time_out: 120, phantomjs_options: ['--ignore-ssl-errors=yes'], js_errors: false)
    end 

    Capybara.configure do |c| 
      c.javascript_driver = :poltergeist
      c.default_driver = :poltergeist
      c.app_host = 'http://localhost:3000'
    end 


    config.expect_with :rspec do |expectations|
      expectations.include_chain_clauses_in_custom_matcher_descriptions = true
    end 

    config.mock_with :rspec do |mocks|
      mocks.verify_partial_doubles = true
    end 
  end

我按照评论中的建议将 Poltergeist 升级到 1.9,将 PhantomJS 升级到 2.1,并解决了这个问题。