wrong number of arguments in initialize

A

Arti Singh

I tried to initalize my methods and I get an error
def initialize(name,browser,username)
@s_name=name
@browser=browser
@username=username
end #def initialize(dc)
attr_accessor :name,:browser,:username




C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/testcase.rb:59:in
`initialize': wrong number of arguments (1 for 3) (ArgumentError)


I honestly dont get it now, this is silly
 
K

Kyle

[Note: parts of this message were removed to make it a legal post.]

but what's the test code you're executing that raises the error?
 
B

Brian Candler

Arti said:
I tried to initalize my methods and I get an error
def initialize(name,browser,username)
@s_name=name
@browser=browser
@username=username
end #def initialize(dc)
attr_accessor :name,:browser,:username

C:/RubyInstall/ruby/lib/ruby/1.8/test/unit/testcase.rb:59:in
`initialize': wrong number of arguments (1 for 3) (ArgumentError)

Open that file in a text editor, go to line 59, and you'll see

catch:)invalid_test) do
suite << new(test) #### ERROR RAISED HERE
end

Then scroll up and you'll see you're inside the 'suite' class method of
class Test::Unit::TestCase, and higher up you'll see

def initialize(test_method_name)
...

That is, when a Test::Unit::TestCase instance is created, it takes a
single argument which is the test method name.

Almost certainly you should not be meddling with the 'initialize' method
of Test::Unit::TestCase. What exactly are you trying to do? I guess you
want to be able to run the same test suite multiple times with different
parameters? The simplest way may be

def setup
@s_name=ENV['TEST_S_NAME']
@browser=ENV['TEST_BROWSER']
@username=ENV['TEST_USERNAME']
end

Then you can do

rake test TEST_S_NAME=xxx TEST_BROWSER=yyy TEST_USERNAME=zzz

An alternative way is to have a separate class for each of your
scenarios, and share the test methods using subclassing or module
mixins. Then running the suite will run all of the variations in one go.

require 'test/unit'

class TestFoo < Test::Unit::TestCase
def setup
@browser = "foo browser"
end
def test_it
puts "Browser is #{@browser}"
assert true
end
end

class TestBar < TestFoo
def setup
@browser = "bar browser"
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top