On Mon, Mar 17, 2008 at 7:05 AM, Ashley Moran <[EMAIL PROTECTED]> wrote: > On 13/03/2008, Bart Zonneveld <[EMAIL PROTECTED]> wrote: > > > Hey list, > > > > I'm refactoring some much-used functionality into a common_steps step > > group. Methods like this are in there: > > > Hi Bart / list > > This is not quite what you are thinking but I've noticed something strange > about steps_for. Basically when the steps are define the Given, When, Then > methods run in the context of a StepGroup, but when they run they have a > different context. > > So to call a method in a step group you have to do something like this: > > steps_for :login do > def sign_in(page, username, password) > # ... > end > > Given "a signed-in support user" do > # ... > @page = browser.open_page("/signin") > steps_for(:login).sign_in(@page, "[EMAIL PROTECTED]", > "support-password") > end > > # ... > end > > (If you wonder about the code, I'm using Selenium not Rails Stories) > > Two consequences of this scoping : > * you have to use steps_for(:login) as the explicit receiver of the sign_in > method > * you have to pass in the instance variable because when the code runs, > sign_in puts the instance variables in the StepGroup, not in whatever object > the runner uses (didn't bother to figure that out)
I have mixed feelings about this. If you do build up a library of step groups, having explicit scoping like this can be a great benefit. Agreed it makes things less convenient otherwise. I can see copying the helper methods to the scope in which the steps are executed. WDYT? David > > Really strange behaviour - I wonder if there's a better way to do this. Am > I going about it the wrong way by using methods in steps_for? Comments > welcome > > Ashley > > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users