I test web applications for living. I use Ruby and Watir for automating functional tests. My scripts have grown, so I made a little framework to make them simpler (all code in this post is simplified and not tested).
Class Page makes checking page URL and text(s) easier.
View item page at application under test has text (breadcrumb) {item_type} > View (example: File > View).
After item is added/edited, at that page there is also text {item_type} {action} (example: File added.).
Class File tests files, of course.
And it works just nice. All I have to write is this.
There are three objects. One for each (@page_view...) variable. id in Page:{id} is different for each variable.
But, duplication bugs me.
I would like that File#initialize looks like this.
But (surprise!), it does not work. Well, I am pretty new in object oriented world, so this was not really a surprise for me.
This way only one Page object is created, and all three variables point to it. No matter which variable I change, it changes the object it points to. Result is that all three variables are the same. Not what I wanted to do.
I have tried a few alternatives, but none worked. I will live with duplication for now, but I would like to remove it from my scripts.