0
votes

I am creating a series of scripts that use Ruby and Watir. Some of them use gems.

One particular gem I use is "numbers and words" which lets you change the value of "5" to "five" or change "1,000,000" to "One Million" etc.

I am experiencing my first conflict of gems and have not been able to sort out if I can make these gems work together or if I will have to give up and use one or the other.

I'm doing this on a Mac Airbook with Yosemite, but have seen the same issue on Mavericks.

Here are my initial local gems when I started.

Initial list of gems:

  • ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
  • bigdecimal (1.2.6)
  • bundler (1.7.9)
  • bundler-unload (1.0.2)
  • executable-hooks (1.3.2)
  • gem-wrappers (1.2.7)
  • io-console (0.4.3)
  • json (1.8.1)
  • minitest (5.4.3)
  • power_assert (0.2.2)
  • psych (2.0.8)
  • rake (10.4.2)
  • rdoc (4.2.0)
  • rubygems-bundler (1.4.4)
  • rvm (1.11.3.9)
  • test-unit (3.0.8)

I added the gem: watir-webdriver (watir-webdriver-0.6.11)

which also installed:

  • websocket-1.2.1
  • ffi-1.9.6
  • childprocess-0.5.5
  • rubyzip-1.1.6
  • multi_json-1.10.1
  • selenium-webdriver-2.44.0

I also installed the gem: numbers_and_words (numbers_and_words-0.10.0)

which also installed:

  • i18n-0.7.0
  • thread_safe-0.3.4
  • tzinfo-1.2.2
  • activesupport-4.2.0

The error only happens in scripts that require "numbers and words", if I take that out and remove code that calls it, all works fine.

Here is some ruby code that will set off the error:

#!/usr/bin/ruby
require 'watir-webdriver'
require 'numbers_and_words'
account_num = 12
last_name = "Smith"
account_num_in_words = account_num.to_i.to_words
last_name = "#{last_name}, #{account_num_in_words}"
@browser = Watir::Browser.new :chrome
@browser.goto ("https://github.com/kslazarev/numbers_and_words")

When I try to run this I get the following: (note, I've tried this both with and without rvm and with different gem sets.)

/Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/activesupport-4.2.0/lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder': uninitialized constant ActiveSupport::JSON (NameError)
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/multi_json-1.10.1/lib/multi_json/adapters/json_common.rb:21:in `dump'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/multi_json-1.10.1/lib/multi_json/adapter.rb:24:in `dump'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/multi_json-1.10.1/lib/multi_json.rb:136:in `dump'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/json_helper.rb:23:in `json_dump'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/http/common.rb:27:in `call'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:640:in `raw_execute'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:101:in `create_session'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/remote/bridge.rb:68:in `initialize'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/chrome/bridge.rb:29:in `initialize'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:37:in `new'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver/common/driver.rb:37:in `for'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/selenium-webdriver-2.44.0/lib/selenium/webdriver.rb:67:in `for'
from /Users/HOME/.rvm/gems/ruby-2.2.0@watir/gems/watir-webdriver-0.6.11/lib/watir-webdriver/browser.rb:46:in `initialize'

This specifically fails at the line that tries to create a new browser.

if I remove references to "numbers and words" it all works fine, but as soon as I require it, code that calls a new Web-driver browser fails.

I'm new enough to where the errors to not immediately point me to how to solve the issue and would appreciate help in finding a solution to keep both gems (though I will also consider alternative gems).

If I remove all code related to numbers_and_words but retain the "require numbers and words" the error will still happen. So just requiring it will prevent me from making a new browser window.

Currently I'll be looking for how to do without it, but hope someone can show me how I can resolve the differences and make it work. Take care and thanks in advance.

1

1 Answers

0
votes

One possible answer is to just change gems or write my own function. However I've decided to use the gem "to words" https://github.com/taimur-akhtar/to_words instead.

However I would still appreciate feedback on why this collision happened and what can and can't be done about it.