Forum: Ruby Ruby General Inheritance Question

F17e6076697008d0e3f14275fb3759ba?d=identicon&s=25 Joe Mart (danmartjoe)
on 2014-08-15 17:13
Hello,

I built a some-what large ruby cucumber test framework for one of our
applications.  It has not object-oritented attributes and there is tons
of repeat code.  Now I am trying to revise this by using
object-orientation and the design has been very hard for me.

The question I have is I am trying to setup cucumber so it asks and only
knows about one general_test_method class.  This general_test_methods
class knows about 15-20 other specifc_test classes so can I have the
general_test_methods class inherit from the other 15-20 specific_test
classes?  I hope that makes sense,

Right now I have cucumber call and know about all the other 15-20
specific_test classes and it seems like better practice to have a single
general_test_method class which will feed cucumber the correct classes.

Ex.  Cucumber -- test1, test2, test3, test4, test5... test20

What I want to do
      Cucumber -- "just knows" general_test_method    and
general_test_method knows --test1...test20

Thanks for your help,

Joe
E0d864d9677f3c1482a20152b7cac0e2?d=identicon&s=25 Robert Klemme (robert_k78)
on 2014-08-17 14:06
Joe Mart wrote in post #1155240:

> I built a some-what large ruby cucumber test framework for one of our
> applications.  It has not object-oritented attributes and there is tons
> of repeat code.  Now I am trying to revise this by using
> object-orientation and the design has been very hard for me.

Please note that there are other ways to get rid of redundancy than
using OO.

> The question I have is I am trying to setup cucumber so it asks and only
> knows about one general_test_method class.  This general_test_methods
> class knows about 15-20 other specifc_test classes so can I have the
> general_test_methods class inherit from the other 15-20 specific_test
> classes?  I hope that makes sense,

I'm afraid, no.  Ruby does not allow multiple inheritance with classes.

> Right now I have cucumber call and know about all the other 15-20
> specific_test classes and it seems like better practice to have a single
> general_test_method class which will feed cucumber the correct classes.
>
> Ex.  Cucumber -- test1, test2, test3, test4, test5... test20
>
> What I want to do
>       Cucumber -- "just knows" general_test_method    and
> general_test_method knows --test1...test20

I am not sure I understand what you want to achieve - but then I haven't
worked with Cucumber yet.  Wouldn't just be a single "test" method
sufficient that simply invokes other methods?  Or use your unit testing
framework's support for test suites?

Kind regards

robert
D4235c6c7f6f03581b5516b3950ae011?d=identicon&s=25 Michael Uplawski (batguano)
on 2014-08-22 22:12
Good evening.

Joe Mart wrote in post #1155240:
> Now I am trying to revise this by using
> object-orientation and the design has been very hard for me.

You try to apply directly what you only just have learned. This is a
very good approach to internalize new concepts. But it necessitates,
that the concepts are understood and can be reproduced *as intended*.

> What I want to do
>       Cucumber -- "just knows" general_test_method    and
> general_test_method knows --test1...test20

There is no simple answer to your question or many. To attack the
problem as I have understood it from your description, some simple
container-structure comes to my mind, that you have to iterate over and
execute the tests.

On the other hand, test-frameworks exist and are documented. Robert
Klemme's comment is important where he explains the simple test-method,
but even more when he mentions the unit testing framework: Even if it
hurts, you may be better off trying to *apply* the concepts of
unit-testing in the way they are meant to be used.

You will probably have to write new code from scratch and give up trying
to improve the procedural heritage which just costs you energy.

Cheerio.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.