views:

77

answers:

1

Hello! I've encoutered some strange functionality, when using Watir and Highline together.

Here is simple example:

require 'highline/import'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

require 'watir'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

Here is an output:

Company?  |MySuperCompany|
MySuperCompany
[Company?  ] =>
Company?

Maybe it's a bug? I've also found in documentation for highline, that

If @question is set before ask() is called, parameters are ignored and that object (must be a HighLine::Question) is used to drive the process instead.

Sorry, I'm not a ruby guru :-(

+1  A: 

Confirmed. It really behaves like that.

Željko: http://highline.rubyforge.org/

grundic: The problem is not related with Watir itself, but it is related with another library called s4t-utils (http://s4t-utils.rubyforge.org/), which also has a "ask" method behaving similar to HighLine's "ask". s4t-utils is a dependendent of gem "user-choices", which in turn is dependent of "commonwatir" which is a Watir's dependency. So, after you issue "require 'watir'", then s4t-utils is loaded thus "ask" method is overridden.

You could use HighLine.new.ask instead of just "ask" to solve the problem:

require "highline/import"
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

require 'watir'
comp = ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

comp = HighLine.new.ask("Company?  ") { |q| q.default = "MySuperCompany" }
puts comp

Produces:

Company?  |MySuperCompany|  my
my
[Company?  ] => my
my
Company?  |MySuperCompany|  my
my

Jarmo Pertman

Jarmo Pertman