0
votes

I am trying to write a simple spec with Capybara using the Poltergeist driver in RSpec. There doesn't seem to be a problem when tests should fail , however when I am expecting a passing test I get the following error:

   ~/.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)

I navigated to where the the line of code the error was indicating:

class JSErrorItem
      attr_reader :message, :stack

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

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

But I was unable to find anywhere that I should be interacting with this constructor.

This is the spec that I am writing

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

The puts page prints the content of the page as expected but after the error occurs and the remainder of the lines in the spec are not run. Oddly enough the error only occurs when I am expecting the spec to pass. When I am expecting a failing test the entire spec runs without error.

My spec helper was set up as below:

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
1
Its causing an error when the test is about to pass because somewhere the JsErrorItem class in your code is being initialized but since there are no errors to throw into it (because the test is about to pass), it is giving you the 0 for 2 argument error. When it is going to fail it is passing in the errors as required. You could make the params optional in your initialization method to avoid errononeous erroring but this wouldn't be solving the issue directly.bkunzi01
poltergeist 1.6.0 is over a year old -- thats a long time when it comes to browser testing -- upgrade to 1.9.x and also make sure you're running phantomjs 2.1+ - then see if you still have the errorThomas Walpole
This seems to be an error that originates as a Javascript error on the tested page. Poltergeist by default raises JS errors so that the test fails. The fact that it's instead an internal error of poltergeist speaks for a too old poltergeist version as @TomWalpole suggested. But you might also try to disable raising JS errors by configuring the poltergeist driver with js_errors: false as documented in the readme.Matouš Borák
@BoraMa The spec helper listed above shows :js_errors is already set to falseThomas Walpole
@TomWalpole Ah, sorry, I missed that.Matouš Borák

1 Answers

1
votes

I upgraded Poltergeist to 1.9 and PhantomJS to 2.1 as suggested in the comments and it fixed the issue.