开发者

Watir changes highline's "ask" method

开发者 https://www.devze.com 2022-12-31 07:03 出处:网络
I\'ve encoutered some strange functionality, when using Watir and Highline together. Here is simple example:

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?  |MySuperCo开发者_运维百科mpany|
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 :-(


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

0

精彩评论

暂无评论...
验证码 换一张
取 消