[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

other way to send message to parent class in unit testing

akbarhome

12/4/2006 4:18:00 AM

Hi, I have 8 class that need to be tested. They all have some same
method to be tested. So I make parent class to do the duplicate work.

This is the parent class:

class BaseElementControllerTest < Test::Unit::TestCase

def setup
# notice this line
@controller = @con_name.new
# end of notice this line

@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

def test_new
get :new
assert_response :success
end

end

The 8 class have same method that need to be tested, that is test_new.
The child class is like this:

require File.dirname(__FILE__) + '/../test_helper'
require 'thermo_detector_controller'

# Re-raise errors caught by the controller.
class ThermoDetectorController; def rescue_action(e) raise e end; end

# notice this line
@con_name = ThermoDetectorController
# end of notice this line

class ThermoDetectorControllerTest < BaseElementControllerTest
fixtures :thermo_detector_order_letters, :workers

# specific method to be tested
....
end

Another child class:

require File.dirname(__FILE__) + '/../test_helper'
require 'quartz_heater_controller'

# Re-raise errors caught by the controller.
class QuartzHeaterController; def rescue_action(e) raise e end; end

# notice this line
@con_name = QuartzHeaterController
# end of notice this line

class QuartzHeaterControllerTest < BaseElementControllerTest
fixtures :quartz_heater_order_letters, :workers

# specific method to be tested
....
end

In this case, I send message to parent class using @con_name variable,
instantiated before child class definition. I have to send message
because in parent class, @controller variable must be instantiated
according to child class. So I wonder if there is another way to send
message to parent in unit testing? I try to use initialize method, but
unit testing "forbid" it. Or this is the only way to send message to
parent class in unit testing?

Thank you.

2 Answers

akbarhome

12/4/2006 4:24:00 AM

0

Edit message:
My mistake. @con_name should be $con_name and you can put $con_name in
child class definition

akbarhome wrote:
> Hi, I have 8 class that need to be tested. They all have some same
> method to be tested. So I make parent class to do the duplicate work.
>
> This is the parent class:
>
> class BaseElementControllerTest < Test::Unit::TestCase
>
> def setup
...<snip>...
> # specific method to be tested
> ....
> end
>
> In this case, I send message to parent class using @con_name variable,
> instantiated before child class definition. I have to send message
> because in parent class, @controller variable must be instantiated
> according to child class. So I wonder if there is another way to send
> message to parent in unit testing? I try to use initialize method, but
> unit testing "forbid" it. Or this is the only way to send message to
> parent class in unit testing?
>
> Thank you.

Bit O' Wiseman

3/12/2013 11:19:00 PM

0

THE COLONEL brought next idea :
> "Bit O' Wiseman" <bow@nomail.invalid> wrote in message
>> Wiseman (AB8MQ)
>> and keep reading these froups while you sober up,
>> shitrot, ya clOOless wankstain.
>>> alt.asshole.roger-wiseman
>>> alt.cocksucker.roger-wiseman
>>> alt.fag-lamer.roger-wiseman.chucklehead
>>> alt.fan.fatassed.woger.wiseman-dicksucker
>>> alt.idiot.roger-wiseman alt.pedophile.roger-wiseman
>>> alt.binaries.pictures.erotica.gaymen.ab8mq
>>> alt.fan.AB8MQ
>> <sniggles>
>>
> LOL! WV? Is that Worst Vagina?
>
>
Yea, down in the holler west by gawd.

Google AB8MQ and you'll get GPS directions
to his WV shack, although bit rot has already
posted his address several times so it's easy
to find either way.

Thanks bit rot, ya RLing shitstain. You've
become what you k'lame to hate so my work
is almost done here.

Someone should forward this shit to Roger
in the mean time.
<snigglez>