David Chelimsky
2009-Apr-27 13:34 UTC
[rspec-users] [cucumber] Setting a constant in step definition
On Mon, Apr 27, 2009 at 7:00 AM, Andrew Premdas <apremdas at gmail.com> wrote:> Currently I have a very simple constants implementation being loaded as a > Rails initialiser > > module MVOR > ? module Postage > ??? THRESHOLD = BigDecimal.new(''6.99'') > ??? RATE = BigDecimal.new(''30.00'') > ? end > end > > > My scenarios of my postage feature want to deal with two situations when the > THRESHOLD has been set to zero and to ''6.99''. The question is how can I set > the threshold in my step_definition. So I want to implement > > ? Given the postage threshold is 0.00 > ? Given the postage threshold is 6.99 > > > ?I''ve considered a number of ideas, but seem to keep on getting into complex > solutions for what I assume is something very simple.If THRESHOLD can change, then it is not, by definition, a constant. It''s just a global variable. I''d change it to a method and then stub that method for a given scenario (even though stubbing is a Cucumber no-no ;) ). WDYT? David> > TIA > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
Matt Wynne
2009-Apr-27 20:52 UTC
[rspec-users] [cucumber] Setting a constant in step definition
On 27 Apr 2009, at 19:08, Andrew Premdas wrote:> Thankyou Aslak much appreciatedBear in mind that this trick will change the value of the constant FOR ALL REMAINING SCENARIOS - not just the current one. If that bothers you, have a read of this thread: http://www.nabble.com/AfterCurrentScenario-block-td23100686.html> > > Andrew > > 2009/4/27 aslak hellesoy <aslak.hellesoy at gmail.com> > > Good question. One answer is that it can change, it just needs a > code change and application restart. > > Basic business case is that someone will set the postage threshold > before the application is deployed. However they could choose any > value. So I want to test what happens when the application is setup > with different values e.g. zero because all postage is free and ?30 > cos postage is free if you spend ?50 or more. > > Currently we do not want to do form based admin for this setting > (and similar ones) because such a change would be very infrequent, > so we are currently happy to redeploy to make the change. > > I would do something like this: http://gist.github.com/102586 > > > > 2009/4/27 aslak hellesoy <aslak.hellesoy at gmail.com> > > > > On Mon, Apr 27, 2009 at 2:00 PM, Andrew Premdas <apremdas at gmail.com> > wrote: > Currently I have a very simple constants implementation being loaded > as a Rails initialiser > > module MVOR > module Postage > THRESHOLD = BigDecimal.new(''6.99'') > RATE = BigDecimal.new(''30.00'') > end > end > > > My scenarios of my postage feature want to deal with two situations > when the THRESHOLD has been set to zero and to ''6.99''. The question > is how can I set the threshold in my step_definition. So I want to > implement > > Given the postage threshold is 0.00 > Given the postage threshold is 6.99 > > > Since it''s a constant - how can it possibly change? And therefore - > why are you testing it with different values? > > > I''ve considered a number of ideas, but seem to keep on getting into > complex solutions for what I assume is something very simple. > > TIA > > > _______________________________________________ > 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 > > > _______________________________________________ > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-usersMatt Wynne http://blog.mattwynne.net http://www.songkick.com
Matt Wynne
2009-Apr-28 00:17 UTC
[rspec-users] [cucumber] Setting a constant in step definition
On 27 Apr 2009, at 22:48, aslak hellesoy wrote:> > > On 27 Apr 2009, at 19:08, Andrew Premdas wrote: > > Thankyou Aslak much appreciated > > Bear in mind that this trick will change the value of the constant > FOR ALL REMAINING SCENARIOS - not just the current one. > > I think you missed the After block.I stand corrected :)> If that bothers you, have a read of this thread: > http://www.nabble.com/AfterCurrentScenario-block-td23100686.html > > > > > Andrew > > 2009/4/27 aslak hellesoy <aslak.hellesoy at gmail.com> > > Good question. One answer is that it can change, it just needs a > code change and application restart. > > Basic business case is that someone will set the postage threshold > before the application is deployed. However they could choose any > value. So I want to test what happens when the application is setup > with different values e.g. zero because all postage is free and ?30 > cos postage is free if you spend ?50 or more. > > Currently we do not want to do form based admin for this setting > (and similar ones) because such a change would be very infrequent, > so we are currently happy to redeploy to make the change. > > I would do something like this: http://gist.github.com/102586 > > > > 2009/4/27 aslak hellesoy <aslak.hellesoy at gmail.com> > > > > On Mon, Apr 27, 2009 at 2:00 PM, Andrew Premdas <apremdas at gmail.com> > wrote: > Currently I have a very simple constants implementation being loaded > as a Rails initialiser > > module MVOR > module Postage > THRESHOLD = BigDecimal.new(''6.99'') > RATE = BigDecimal.new(''30.00'') > end > end > > > My scenarios of my postage feature want to deal with two situations > when the THRESHOLD has been set to zero and to ''6.99''. The question > is how can I set the threshold in my step_definition. So I want to > implement > > Given the postage threshold is 0.00 > Given the postage threshold is 6.99 > > > Since it''s a constant - how can it possibly change? And therefore - > why are you testing it with different values? > > > I''ve considered a number of ideas, but seem to keep on getting into > complex solutions for what I assume is something very simple. > > TIA > > > _______________________________________________ > 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 > > > _______________________________________________ > 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 > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-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-usersMatt Wynne http://blog.mattwynne.net http://www.songkick.com