Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Passing the module name into the method definition
Max Russell
12/5/2006 3:53:00 PM
I've been building a harness for running watir tests it looks lke this
currently-
module CVLibrary
def CVLibrary.cv_login(testinstance, testaddress, testuser,
testpass, testldap)
# opens ie, goes to Central Vision and logs in with the
# specified address, username, password and domain
testinstance.goto(testaddress)
testinstance.frame("main").text_field(:name,
"username").set(testuser)
testinstance.frame("main").text_field(:name,
"password").set(testpass)
testinstance.frame("main").select_list(:name,
"ldapDir").select(testldap)
testinstance.frame("main").button(:name, "Login").click
end
The test script includes the following
require 'watir'
require 'test/unit/assertions'
require 'CVlibrary'
include Test::Unit::Assertions
ie = Watir::IE.start()
CVLibrary.cv_login(ie,'
http://address.html','name','pass','d...
)
What I don't understand is why, in the module, I'm explicitly having to
pass in it's own name? e.g. CVLibrary.cv_login
None of the examples
--
Posted via
http://www.ruby-...
.
2 Answers
Vassilis Rizopoulos
12/6/2006 9:51:00 AM
0
Max Russell wrote:
> I've been building a harness for running watir tests it looks lke this
> currently-
>
> module CVLibrary
> def CVLibrary.cv_login(testinstance, testaddress, testuser,
> testpass, testldap)
....
> What I don't understand is why, in the module, I'm explicitly having to
> pass in it's own name? e.g. CVLibrary.cv_login
You're defining a class method (e.g. static in other regions of the
programming world).
You actually don't have to pass the module name, and in the interests of
refactoring it is also not advised.
You are better off doing:
def self.cv_login(...)
If you define
module CVLibrary
def cv_login
end
end
then you have an instance method, so you need to include the module in a
class and then call the method from an instance of that class.
Cheers,
V.-
--
http://www.braveworl...
Max Russell
12/8/2006 3:15:00 PM
0
I don't believe I am defining a class at all... I had a look at the
Pragmattic Guide and it seems to do it the same way as I have, and I've
got my head round the instantiation bit now.
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Passing the module name into the method definition
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password