Is there currently a way to register a block to run after the current scenario completes? If not, we''ve implemented one. Would anyone be interested in us submitting it as a patch to Cucumber? Something like Given "something that will not be rolled back after the scenario is finished" do original = SomeClass.a_value SomeClass.a_value = 7 AfterCurrentScenario do # undo stuff SomeClass.a_value = original end end If you''re interested, our use case is for pagination, where we explicitly set the length of a page to something much shorter than the default in a step, so that we only have to create a small number of objects to spill over onto another page. The page length value is set on a class variable, and would pollute other tests, so we want to reset it when the scenario is finished. e.g. Given the maximum number of Users to display is 2 And there are 3 Users When I view the Users page Then I should see the text "see all 3 users" Matt Wynne http://blog.mattwynne.net http://www.songkick.com
Den 17. april. 2009 kl. 18.06 skrev Matt Wynne <matt at mattwynne.net>:> Is there currently a way to register a block to run after the > current scenario completes? >After.> If not, we''ve implemented one. Would anyone be interested in us > submitting it as a patch to Cucumber? >How is this different from After? Aslak> Something like > > Given "something that will not be rolled back after the scenario is > finished" do > original = SomeClass.a_value > SomeClass.a_value = 7 > > AfterCurrentScenario do > # undo stuff > SomeClass.a_value = original > end > end > > If you''re interested, our use case is for pagination, where we > explicitly set the length of a page to something much shorter than > the default in a step, so that we only have to create a small number > of objects to spill over onto another page. The page length value is > set on a class variable, and would pollute other tests, so we want > to reset it when the scenario is finished. > > e.g. Given the maximum number of Users to display is 2 > And there are 3 Users > When I view the Users page > Then I should see the text "see all 3 users" > > Matt Wynne > http://blog.mattwynne.net > http://www.songkick.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Matt Wynne wrote:> Is there currently a way to register a block to run after the current > scenario completes? >You could achieve the same thing with After and tags: http://wiki.github.com/aslakhellesoy/cucumber/hooks @please-clean-me Scenario: dirty ... After "@please-clean-me" do #clean end -- Joseph Wilk http://blog.josephwilk.net> If not, we''ve implemented one. Would anyone be interested in us > submitting it as a patch to Cucumber? > > Something like > > Given "something that will not be rolled back after the scenario is > finished" do > original = SomeClass.a_value > SomeClass.a_value = 7 > > AfterCurrentScenario do > # undo stuff > SomeClass.a_value = original > end > end > > If you''re interested, our use case is for pagination, where we > explicitly set the length of a page to something much shorter than the > default in a step, so that we only have to create a small number of > objects to spill over onto another page. The page length value is set > on a class variable, and would pollute other tests, so we want to > reset it when the scenario is finished. > > e.g. Given the maximum number of Users to display is 2 > And there are 3 Users > When I view the Users page > Then I should see the text "see all 3 users" > > Matt Wynne > http://blog.mattwynne.net > http://www.songkick.com > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On Fri, Apr 17, 2009 at 9:06 AM, Matt Wynne <matt at mattwynne.net> wrote:> > If you''re interested, our use case is for pagination, where we explicitly > set the length of a page to something much shorter than the default in a > step, so that we only have to create a small number of objects to spill over > onto another page.Is this necessary? I mean, is the page length so long that creating that many objects takes appreciably longer than otherwise? I like to leave such values as page length alone in a scenario, because that''s part of the user requirement (if not a vitally important one). ///ark
On Fri, Apr 17, 2009 at 12:31 PM, Aslak Helles?y <aslak.hellesoy at gmail.com> wrote:> > > Den 17. april. 2009 kl. 18.06 skrev Matt Wynne <matt at mattwynne.net>: > >> Is there currently a way to register a block to run after the current >> scenario completes? >> > After.After is used after *any* scenario completes thought, right? If you add an After block inside of a step definition, it''s going to be executed from that point on, rather than clear out at the end of the scenario that ran it, correct?>> If not, we''ve implemented one. Would anyone be interested in us submitting >> it as a patch to Cucumber? >> > How is this different from After?* It clears out after the current scenario. * It doesn''t require to be run for scenarios that don''t need it. * It allows you to cleanly place the handler next to the code that it is so closely related * It doesn''t require you know the name of the scenario(s) that would need it (it''s simply determined by if a step definition is run)> > Aslak >> >> Something like >> >> Given "something that will not be rolled back after the scenario is >> finished" do >> ?original = SomeClass.a_value >> ?SomeClass.a_value = 7 >> >> ?AfterCurrentScenario do >> ? # undo stuff >> ? SomeClass.a_value = original >> ?end >> end >> >> If you''re interested, our use case is for pagination, where we explicitly >> set the length of a page to something much shorter than the default in a >> step, so that we only have to create a small number of objects to spill over >> onto another page. The page length value is set on a class variable, and >> would pollute other tests, so we want to reset it when the scenario is >> finished. >> >> ?e.g. ?Given the maximum number of Users to display is 2 >> ? And there are 3 Users >> ? When I view the Users page >> ? Then I should see the text "see all 3 users" >> >> Matt Wynne >> http://blog.mattwynne.net >> http://www.songkick.com >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-- Zach Dennis http://www.continuousthinking.com http://www.mutuallyhuman.com
Den 17. april. 2009 kl. 18.58 skrev Zach Dennis <zach.dennis at gmail.com>:> On Fri, Apr 17, 2009 at 12:31 PM, Aslak Helles?y > <aslak.hellesoy at gmail.com> wrote: >> >> >> Den 17. april. 2009 kl. 18.06 skrev Matt Wynne <matt at mattwynne.net>: >> >>> Is there currently a way to register a block to run after the >>> current >>> scenario completes? >>> >> After. > > After is used after *any* scenario completes thought, right? If you > add an After block inside of a step definition, it''s going to beAha now I understand. Matt, would Joseph''s suggestion work for you? Aslak> > executed from that point on, rather than clear out at the end of the > scenario that ran it, correct? > >>> If not, we''ve implemented one. Would anyone be interested in us >>> submitting >>> it as a patch to Cucumber? >>> >> How is this different from After? > > * It clears out after the current scenario. > * It doesn''t require to be run for scenarios that don''t need it. > * It allows you to cleanly place the handler next to the code that it > is so closely related > * It doesn''t require you know the name of the scenario(s) that would > need it (it''s simply determined by if a step definition is run) > >> >> Aslak >>> >>> Something like >>> >>> Given "something that will not be rolled back after the scenario is >>> finished" do >>> original = SomeClass.a_value >>> SomeClass.a_value = 7 >>> >>> AfterCurrentScenario do >>> # undo stuff >>> SomeClass.a_value = original >>> end >>> end >>> >>> If you''re interested, our use case is for pagination, where we >>> explicitly >>> set the length of a page to something much shorter than the >>> default in a >>> step, so that we only have to create a small number of objects to >>> spill over >>> onto another page. The page length value is set on a class >>> variable, and >>> would pollute other tests, so we want to reset it when the >>> scenario is >>> finished. >>> >>> e.g. Given the maximum number of Users to display is 2 >>> And there are 3 Users >>> When I view the Users page >>> Then I should see the text "see all 3 users" >>> >>> Matt Wynne >>> http://blog.mattwynne.net >>> http://www.songkick.com >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >> > > > > -- > Zach Dennis > http://www.continuousthinking.com > http://www.mutuallyhuman.com > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
On 17 Apr 2009, at 18:20, Aslak Helles?y wrote:> Den 17. april. 2009 kl. 18.58 skrev Zach Dennis > <zach.dennis at gmail.com>: > >> On Fri, Apr 17, 2009 at 12:31 PM, Aslak Helles?y >> <aslak.hellesoy at gmail.com> wrote: >>> >>> >>> Den 17. april. 2009 kl. 18.06 skrev Matt Wynne <matt at mattwynne.net>: >>> >>>> Is there currently a way to register a block to run after the >>>> current >>>> scenario completes? >>>> >>> After. >> >> After is used after *any* scenario completes thought, right? If you >> add an After block inside of a step definition, it''s going to be > > Aha now I understand. Matt, would Joseph''s suggestion work for you? > > AslakIt would work, yes, but I have to say I like ours a bit better - you can put the undo code right next to the code it''s undoing, as Zach pointed out. With the tags thing I''d have to put a tag in the feature file which is introducing a tiny bit more coupling and noise which I''d rather avoid. I had pondered on the idea of changing the After method to use a syntax a bit like RSpec''s #before(:each) where we could say: After(:each) do # general post-scenario clean-up After(:current) do # one-time clean-up Anyway, just a thought. Matt Wynne http://blog.mattwynne.net http://www.songkick.com