I’m pretty new Ruby, and I’m slightly confused about when to use ‘self’.
I’m in a process of writing a common automation framework to test our
(java-based) web products using Cucumber. I’m using the ‘Page Object’
design pattern, which basically means that each page should be
represented by a class.
Some pages, share behavior. For example - many pages utilize JavaScript
popup. I have a couple of methods that handle popups (accept them,
dismiss them etc). My instincts tell me that since popup handling is
basically a collection of methods, and those are state-less, I should be
using a module. Hopefully I’m right to this point.
Now, I’m not sure if I should include the module into my Page Objects,
or “self” the whole module, and just call those methods from the page
object when I need them.
As test frameworks being very ‘procedural’ oriented, I find much of my
code being stateless. Using too many modules and 'self’ing those worry
me (as my C# background should me that I should be extra careful when
I’m using static methods). Some guidelines on when I should be using
self so I won’t over-do it will be useful for me.