thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 428 forks source link

warning: constant ::Fixnum is deprecated in Ruby 2.4.0 #1015

Closed ckundo closed 6 years ago

ckundo commented 7 years ago

We're running into a deprecation warning running our tests with capybara-webkit, using Ruby 2.4.0:

.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/capybara-webkit-1.1.0/lib/capybara/webkit/browser.rb:84: warning: constant ::Fixnum is deprecated

The warning is raised when calling page.driver.browser.frame_focus without any arguments. The call to Fixnum is here: https://github.com/thoughtbot/capybara-webkit/blob/master/lib/capybara/webkit/browser.rb#L87.

Fixnum and Bignum were deprecated with the release of Ruby 2.4.0, in favor of Integer, as announced here: https://www.ruby-lang.org/en/news/2016/12/25/ruby-2-4-0-released/

Here's the new function that doesn't throw a deprecation warning:

def frame_focus(selector=nil)
  if selector.respond_to?(:base)
    selector.base.invoke('focus')
  elsif selector.is_a? Integer
    command("FrameFocus", "", selector.to_s)
  elsif selector
    command("FrameFocus", selector)
  else
    command("FrameFocus")
  end
end

Happy to open a PR, but first wanted to know if/how we can drive out the implementation with a test.

twalpole commented 7 years ago

Quick question -- any reason you're running such an old capybara-webkit (the issue is still in the current release - although probably wouldn't show up if using the current Capybara APIs). v 1.1.0 was released in 2013.

mhoran commented 7 years ago

Seems like a refactor to me, @ckundo. Go ahead and send a PR. As soon as Ruby removes Fixnum, this will test itself!

DannyBen commented 7 years ago

This issue is still present with version 1.14.0, and the culprit is in this line.

The error:

/usr/lib/ruby/gems/2.4.0/gems/capybara-webkit-1.14.0/lib/capybara/webkit/browser.rb:87: warning: constant ::Fixnum is deprecated

As triggered by this cucumber stepdef:

Then(/^(?:the )?iframe should contain "([^"]*)" (?:selector|element)$/) do |selector|
  expect(page).to have_selector 'iframe'
  within_frame find('iframe') do
    expect(page).to have_selector selector
  end
end
twalpole commented 6 years ago

Fixed in master