> > > 2009/4/28 Andrew Premdas <aprem...@gmail.com> > >> I guess I'll just have to use a global, perhaps trying to freeze them in >> production. Just thought there might be something that might be an >> alternative. Might have a look at using a stub if that doesn't work. Thanks >> for your input > > > You could pass the value as a constructor parameter into objects that use > it, defaulted to the constant: > > def initialize(threshold = THRESHOLD) > @threshold = threshold > # ... > end >
I agree. This probably also means dropping down a level - from Cucumber to RSpec. > > That way the default constructor would Do The Right Thing and you could > pass in values for testing. It is also more intention-revealing than > referencing global constants. (Where do you use the threshold? What for?) > > Cheers, > Dan > > > >> 2009/4/27 David Chelimsky <dchelim...@gmail.com> >> >> On Mon, Apr 27, 2009 at 7:00 AM, Andrew Premdas <aprem...@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@rubyforge.org >>> > http://rubyforge.org/mailman/listinfo/rspec-users >>> > >>> _______________________________________________ >>> 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 >> > > > _______________________________________________ > 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