[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Inheriting test classes

aidy

8/31/2006 9:31:00 AM

Hi,

All my GUI test classes contain this code within the constructor.

class ST_MSE_33
def initialize

start_browser
login

................

rescue => e
p "test failed: #{e.message}"
p e.backtrace
ensure
log_out
close_window
end
end

That is, there is always the same start and same end, but a different
middle.
Is there any way I could use inheritance to avoid duplication?

Thank You

Aidy

1 Answer

Stefan Mahlitz

8/31/2006 10:09:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

aidy wrote:
> Hi,
>
> All my GUI test classes contain this code within the constructor.
>
> class ST_MSE_33
> def initialize
>
> start_browser
> login
>
> ................
>
> rescue => e
> p "test failed: #{e.message}"
> p e.backtrace
> ensure
> log_out
> close_window
> end
> end
>
> That is, there is always the same start and same end, but a different
> middle.
> Is there any way I could use inheritance to avoid duplication?

I would use the following construct:

class GeneralBehaviour
def initialize
start_browser
login

specific_behaviour

...
end

# this is only necessary if GeneralBehaviour can be used
# on its own
def specific_behaviour
end
end

class SpecifB1 < GeneralBehaviour
def specific_behaviour
# do sth specific ;)
end
end

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFE9rUj9S2Eui6zfdQRAtN5AKCcjVXYZeUi/Qh1iM3SOay52hLc8gCcDMgc
4FXA0QPUVqzhFVzr3C6icCY=
=arYe
-----END PGP SIGNATURE-----