+1

I prefer that Watir conform as closely as possible to Ruby standards.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Bret Pettichord
Sent: Thursday, November 10, 2005 9:37 PM
To: [email protected]
Subject: Re: [Wtr-general] IE.contains_text and assert

At 02:48 PM 11/10/2005, Jeff Wood wrote:
>Actually, I would say changing the existing function to actually return 
>true or false would be appropriate.  Add the ? to the end of the function 
>name, and then let people use ie.text.index etc to get the index of
occurance.
>
>j.

Hmm. That was how it originally was coded, but it was changed to the 
current behavior (without updating the rdoc) based on an earlier request on 
this list. Changing it back will break scripts.

Originally, we made several attempts to shield Watir users from Ruby, and 
in the end, this only created more confusion -- the best of example of this 
was how we decided to use 1-based indexing in Watir. The lesson i learned 
is that we are much better off if we follow the Ruby conventions in Watir, 
explaining them when they may not be intuitive to new users, rather than 
trying to put together a separate set of conventions that are possibly more 
intuitive.

The suggestion that this method end in a question mark, therefore a good 
one, since this is the Ruby convention for this kind of thing.

But the Ruby way would be to do ie.text.contains? rather than 
ie.contains_text. And in fact, to do ie.text.contain? since the Ruby 
convention is to not use the final s (another convention we haven't yet 
followed very closely with Watir, but would be good to move towards).

That suggests ie.text.contain? The biggest qualm i have with this is that 
implementing this means adding a method to the string class. I don't object 
to this in principle, but will this confuse users? Looking at the String 
API, i see that it already provides the method string.include? which does 
exactly what we want with string arguments. But users would have to use 
ie.string.match() if they wanted to use regular expressions.

A little awkward, but then that is the awkwardness of Ruby and i think the 
principle that we should follow is not to avoid this.

Another reason for my attention to this issue is that we also have 
TextField#verify_contains which really should have the same method name as 
IE#contains_text -- it does the same thing. This is another Watir 
inconsistency that needs to be addressed -- it would be best to move things 
correctly.

Therefore, my proposal:

Slowly, deprecate IE#contains_text(), starting with removing it from the 
intro user documentation, instead encouraging users to use 
IE#text.include?() instead. (And also introducing IE#text.match() when 
regular expressions are used.) In the mean time, we update the rdoc for 
IE#contains_text() to be more accurate, as suggested by the OP.

Both the rdoc for IE#contains_text and TextField#verify_contains would be 
suggest that these more direct forms be used instead.

Bret


_____________________
  Bret Pettichord
  www.pettichord.com

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to