The floating-point expectations allow for an error tolerance. Is there any similar facility for dates? For example, say I have a custom class that handles date/time spans and I want to spec it: context "A DateRange span" do specify "should know when a week ago is :)" do d = DateRange.new d.last_week.should_be_close_to(1.week.ago, 24*60*60) end end The idea of should_be_close_to is to provide a tolerance. My class only is required to be accurate to the same day, and I want to express that in terms of "close_to" uncertainty. Is there a great baked-in way I''m missing? I have code to do this in Test::Unit that I could port over if need be but I''d rather not if something better already exists. Thanks, Steve
On 1/9/07, s.ross <cwdinfo at gmail.com> wrote:> The floating-point expectations allow for an error tolerance. Is > there any similar facility for dates? For example, say I have a > custom class that handles date/time spans and I want to spec it: > > context "A DateRange span" do > specify "should know when a week ago is :)" do > d = DateRange.new > d.last_week.should_be_close_to(1.week.ago, 24*60*60) > end > end > > The idea of should_be_close_to is to provide a tolerance. My class > only is required to be accurate to the same day, and I want to > express that in terms of "close_to" uncertainty. Is there a great > baked-in way I''m missing? > > I have code to do this in Test::Unit that I could port over if need > be but I''d rather not if something better already exists.Doesn''t exist yet. Feel free to add a feature request: http://rubyforge.org/tracker/?group_id=797> Thanks, > > Steve > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 1/9/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 1/9/07, s.ross <cwdinfo at gmail.com> wrote: > > The floating-point expectations allow for an error tolerance. Is > > there any similar facility for dates? For example, say I have a > > custom class that handles date/time spans and I want to spec it: > > > > context "A DateRange span" do > > specify "should know when a week ago is :)" do > > d = DateRange.new > > d.last_week.should_be_close_to(1.week.ago, 24*60*60) > > end > > end > > > > The idea of should_be_close_to is to provide a tolerance. My class > > only is required to be accurate to the same day, and I want to > > express that in terms of "close_to" uncertainty. Is there a great > > baked-in way I''m missing? > > > > I have code to do this in Test::Unit that I could port over if need > > be but I''d rather not if something better already exists. > > Doesn''t exist yet. Feel free to add a feature request: > > http://rubyforge.org/tracker/?group_id=797Hey Steve - I just committed a small enhancement to rspec core that is intended to pave the way for custom expectations. Are you working w/ 0.7.5 or the trunk? If you''re working w/ trunk, grab the latest trunk and do this: module DateExpectations class BeCloseTo def initialize(target_date, tolerance) @target_date = target_date @tolerance = tolerance end def met_by?(target) #return true if target is a date #that meets the expectation end def failure_message #return an appropriate failure message end end def should_be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "My package" do include DateExpectations specify "should be delivered no later than 2 days after my order" do delivery_date.should be_close_to("1/9/2007", :days => 2) end end This is only experimental today, but will very likely become the entry way for custom expectations. Let me know how it works out for you. Cheers, David> > > Thanks, > > > > Steve > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >
I''m running 0.7.5. I guess I should learn how to install rspec from svn, huh? Basically, each time I change my version of rspec, I have to dive into 5 or 6 projects to update their Rails plugins and so on... Any shortcuts you use when doing this? Thanks for doing this so quickly! Steve On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote:> On 1/9/07, David Chelimsky <dchelimsky at gmail.com> wrote: >> On 1/9/07, s.ross <cwdinfo at gmail.com> wrote: >>> The floating-point expectations allow for an error tolerance. Is >>> there any similar facility for dates? For example, say I have a >>> custom class that handles date/time spans and I want to spec it: >>> >>> context "A DateRange span" do >>> specify "should know when a week ago is :)" do >>> d = DateRange.new >>> d.last_week.should_be_close_to(1.week.ago, 24*60*60) >>> end >>> end >>> >>> The idea of should_be_close_to is to provide a tolerance. My class >>> only is required to be accurate to the same day, and I want to >>> express that in terms of "close_to" uncertainty. Is there a great >>> baked-in way I''m missing? >>> >>> I have code to do this in Test::Unit that I could port over if need >>> be but I''d rather not if something better already exists. >> >> Doesn''t exist yet. Feel free to add a feature request: >> >> http://rubyforge.org/tracker/?group_id=797 > > Hey Steve - I just committed a small enhancement to rspec core that is > intended to pave the way for custom expectations. Are you working w/ > 0.7.5 or the trunk? If you''re working w/ trunk, grab the latest trunk > and do this: > > module DateExpectations > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = target_date > @tolerance = tolerance > end > > def met_by?(target) > #return true if target is a date > #that meets the expectation > end > > def failure_message > #return an appropriate failure message > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > delivery_date.should be_close_to("1/9/2007", :days => 2) > end > end > > This is only experimental today, but will very likely become the entry > way for custom expectations. Let me know how it works out for you. > > Cheers, > David > >> >>> Thanks, >>> >>> Steve >>> _______________________________________________ >>> 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
I upgraded to trunk and changed the code as follows: module DateExpectations HOUR_TOLERANCE = 60 * 60 DAY_TOLERANCE = HOUR_TOLERANCE * 24 WEEK_TOLERANCE = DAY_TOLERANCE * 7 class BeCloseTo def initialize(target_date, tolerance) @target_date = Time.parse(target_date) @tolerance = tolerance end def met_by?(target) compare_date = target - @target_date adjustment = @tolerance.inject do |item| case item when :days adjustment += DAY_TOLERANCE when :weeks adjustment += WEEK_TOLERANCE end end return true if compare_date.abs < adjustment end def failure_message return "#{@target_date} does not fall within tolerance." # s/ b better end end def should_be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "My package" do include DateExpectations specify "should be delivered no later than 2 days after my order" do 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 end end The result is: 1) NoMethodError in ''My package should be delivered no later than 2 days after my order'' undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time ./spec/helpers/date_range_spec.rb:40: Any thoughts as to why? (Note: You had written the expectation in your sample as: "should<space>be_close_to" -- was that intentional?). Steve On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote:> module DateExpectations > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = target_date > @tolerance = tolerance > end > > def met_by?(target) > #return true if target is a date > #that meets the expectation > end > > def failure_message > #return an appropriate failure message > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > delivery_date.should be_close_to("1/9/2007", :days => 2) > end > end
On 1/10/07, s.ross <cwdinfo at gmail.com> wrote:> I upgraded to trunk and changed the code as follows: > > module DateExpectations > HOUR_TOLERANCE = 60 * 60 > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = Time.parse(target_date) > @tolerance = tolerance > end > > def met_by?(target) > compare_date = target - @target_date > adjustment = @tolerance.inject do |item| > case item > when :days > adjustment += DAY_TOLERANCE > when :weeks > adjustment += WEEK_TOLERANCE > end > end > return true if compare_date.abs < adjustment > end > > def failure_message > return "#{@target_date} does not fall within tolerance." # s/ > b better > end > end > > def should_be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "My package" do > include DateExpectations > specify "should be delivered no later than 2 days after my order" do > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > end > end > > The result is: > > 1) > NoMethodError in ''My package should be delivered no later than 2 days > after my order'' > undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time > ./spec/helpers/date_range_spec.rb:40: > > > Any thoughts as to why? (Note: You had written the expectation in > your sample as: > "should<space>be_close_to" -- was that intentional?).Yes!!!! That''s the whole point. ;) should be_close_to and your method should be named be_close_to Let me know how it works out. Thanks for giving this a shot - you''re the guinea pig! David> > Steve > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > module DateExpectations > > class BeCloseTo > > def initialize(target_date, tolerance) > > @target_date = target_date > > @tolerance = tolerance > > end > > > > def met_by?(target) > > #return true if target is a date > > #that meets the expectation > > end > > > > def failure_message > > #return an appropriate failure message > > end > > end > > > > def should_be_close_to(target_date, tolerance) > > return BeCloseTo.new(target_date, tolerance) > > end > > end > > > > context "My package" do > > include DateExpectations > > specify "should be delivered no later than 2 days after my order" do > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > end > > end > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > > I upgraded to trunk and changed the code as follows: > > > > module DateExpectations > > HOUR_TOLERANCE = 60 * 60 > > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > > > class BeCloseTo > > def initialize(target_date, tolerance) > > @target_date = Time.parse(target_date) > > @tolerance = tolerance > > end > > > > def met_by?(target) > > compare_date = target - @target_date > > adjustment = @tolerance.inject do |item| > > case item > > when :days > > adjustment += DAY_TOLERANCE > > when :weeks > > adjustment += WEEK_TOLERANCE > > end > > end > > return true if compare_date.abs < adjustment > > end > > > > def failure_message > > return "#{@target_date} does not fall within tolerance." # s/ > > b better > > end > > end > > > > def should_be_close_to(target_date, tolerance) > > return BeCloseTo.new(target_date, tolerance) > > end > > end > > > > context "My package" do > > include DateExpectations > > specify "should be delivered no later than 2 days after my order" do > > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > > end > > end > > > > The result is: > > > > 1) > > NoMethodError in ''My package should be delivered no later than 2 days > > after my order'' > > undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time > > ./spec/helpers/date_range_spec.rb:40: > > > > > > Any thoughts as to why? (Note: You had written the expectation in > > your sample as: > > "should<space>be_close_to" -- was that intentional?). > > Yes!!!! That''s the whole point. ;)I should clarify that a bit. The idea is to decouple expectations from Object so that we can more easily write, maintain and extend them while simultaneously minimizing the risk of other frameworks (like rails) screwing w/ our use of method missing. If you look at the initialize method in should.rb, it now takes an optional expectation argument. If it gets one, it processes it. What you are writing is an expectation that gets passed to should, which then passes the target to the expectation for verification. Make sense? David> > should be_close_to > > and your method should be named be_close_to > > Let me know how it works out. > > Thanks for giving this a shot - you''re the guinea pig! > > David > > > > > Steve > > > > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > > > module DateExpectations > > > class BeCloseTo > > > def initialize(target_date, tolerance) > > > @target_date = target_date > > > @tolerance = tolerance > > > end > > > > > > def met_by?(target) > > > #return true if target is a date > > > #that meets the expectation > > > end > > > > > > def failure_message > > > #return an appropriate failure message > > > end > > > end > > > > > > def should_be_close_to(target_date, tolerance) > > > return BeCloseTo.new(target_date, tolerance) > > > end > > > end > > > > > > context "My package" do > > > include DateExpectations > > > specify "should be delivered no later than 2 days after my order" do > > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > > end > > > end > > > > _______________________________________________ > > rspec-users mailing list > > rspec-users at rubyforge.org > > http://rubyforge.org/mailman/listinfo/rspec-users > > >
On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote:> On 1/10/07, David Chelimsky <dchelimsky at gmail.com> wrote: > > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > > > I upgraded to trunk and changed the code as follows: > > > > > > module DateExpectations > > > HOUR_TOLERANCE = 60 * 60 > > > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > > > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > > > > > class BeCloseTo > > > def initialize(target_date, tolerance) > > > @target_date = Time.parse(target_date) > > > @tolerance = tolerance > > > end > > > > > > def met_by?(target) > > > compare_date = target - @target_date > > > adjustment = @tolerance.inject do |item| > > > case item > > > when :days > > > adjustment += DAY_TOLERANCE > > > when :weeks > > > adjustment += WEEK_TOLERANCE > > > end > > > end > > > return true if compare_date.abs < adjustment > > > end > > > > > > def failure_message > > > return "#{@target_date} does not fall within tolerance." # s/ > > > b better > > > end > > > end > > > > > > def should_be_close_to(target_date, tolerance) > > > return BeCloseTo.new(target_date, tolerance) > > > end > > > end > > > > > > context "My package" do > > > include DateExpectations > > > specify "should be delivered no later than 2 days after my order" do > > > 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- line 40 > > > end > > > end > > > > > > The result is: > > > > > > 1) > > > NoMethodError in ''My package should be delivered no later than 2 days > > > after my order'' > > > undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time > > > ./spec/helpers/date_range_spec.rb:40: > > > > > > > > > Any thoughts as to why? (Note: You had written the expectation in > > > your sample as: > > > "should<space>be_close_to" -- was that intentional?). > > > > Yes!!!! That''s the whole point. ;) > > I should clarify that a bit. The idea is to decouple expectations from > Object so that we can more easily write, maintain and extend them > while simultaneously minimizing the risk of other frameworks (like > rails) screwing w/ our use of method missing. > > If you look at the initialize method in should.rb, it now takes an > optional expectation argument. If it gets one, it processes it. What > you are writing is an expectation that gets passed to should, which > then passes the target to the expectation for verification. > > Make sense?I blogged about this here: http://blog.davidchelimsky.net/articles/2007/01/10/rspec-should-use_a_little_less_magic Comments welcome and appreciated. Thanks, David> > David > > > > > should be_close_to > > > > and your method should be named be_close_to > > > > Let me know how it works out. > > > > Thanks for giving this a shot - you''re the guinea pig! > > > > David > > > > > > > > Steve > > > > > > > > > On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > > > > > > > module DateExpectations > > > > class BeCloseTo > > > > def initialize(target_date, tolerance) > > > > @target_date = target_date > > > > @tolerance = tolerance > > > > end > > > > > > > > def met_by?(target) > > > > #return true if target is a date > > > > #that meets the expectation > > > > end > > > > > > > > def failure_message > > > > #return an appropriate failure message > > > > end > > > > end > > > > > > > > def should_be_close_to(target_date, tolerance) > > > > return BeCloseTo.new(target_date, tolerance) > > > > end > > > > end > > > > > > > > context "My package" do > > > > include DateExpectations > > > > specify "should be delivered no later than 2 days after my order" do > > > > delivery_date.should be_close_to("1/9/2007", :days => 2) > > > > end > > > > end > > > > > > _______________________________________________ > > > rspec-users mailing list > > > rspec-users at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/rspec-users > > > > > >
My net connection''s gone spotty over the last couple of days, but I wanted to follow up and tell you that your new code works great. Here''s just a proof of concept implementation (complete with hard coding!): module DateExpectations HOUR_TOLERANCE = 60 * 60 DAY_TOLERANCE = HOUR_TOLERANCE * 24 WEEK_TOLERANCE = DAY_TOLERANCE * 7 class BeCloseTo def initialize(target_date, tolerance) @target_date = Time.parse(target_date) @tolerance = tolerance end def met_by?(target) @compare_date = target compare_span = target - @target_date adjustment = 0 @tolerance.each do |key, amount| case key when :hours adjustment += HOUR_TOLERANCE * amount when :days adjustment += DAY_TOLERANCE * amount when :weeks adjustment += WEEK_TOLERANCE * amount end end return true if compare_span.abs < adjustment end def failure_message return "#{@target_date} does not fall within tolerance (# {@tolerance.collect{|k,v| "#{k.to_s} => #{v}"}.join(", ")}) from # {@compare_date}." end end def be_close_to(target_date, tolerance) return BeCloseTo.new(target_date, tolerance) end end context "The DateRange helper" do include DateExpectations specify "should be able to approximate within two days" do 1.day.ago.should be_close_to("1/9/2007", :days => 2) end end On Jan 10, 2007, at 11:22 AM, David Chelimsky wrote:> On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: >> I upgraded to trunk and changed the code as follows: >> >> module DateExpectations >> HOUR_TOLERANCE = 60 * 60 >> DAY_TOLERANCE = HOUR_TOLERANCE * 24 >> WEEK_TOLERANCE = DAY_TOLERANCE * 7 >> >> class BeCloseTo >> def initialize(target_date, tolerance) >> @target_date = Time.parse(target_date) >> @tolerance = tolerance >> end >> >> def met_by?(target) >> compare_date = target - @target_date >> adjustment = @tolerance.inject do |item| >> case item >> when :days >> adjustment += DAY_TOLERANCE >> when :weeks >> adjustment += WEEK_TOLERANCE >> end >> end >> return true if compare_date.abs < adjustment >> end >> >> def failure_message >> return "#{@target_date} does not fall within tolerance." # s/ >> b better >> end >> end >> >> def should_be_close_to(target_date, tolerance) >> return BeCloseTo.new(target_date, tolerance) >> end >> end >> >> context "My package" do >> include DateExpectations >> specify "should be delivered no later than 2 days after my >> order" do >> 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- >> line 40 >> end >> end >> >> The result is: >> >> 1) >> NoMethodError in ''My package should be delivered no later than 2 days >> after my order'' >> undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time >> ./spec/helpers/date_range_spec.rb:40: >> >> >> Any thoughts as to why? (Note: You had written the expectation in >> your sample as: >> "should<space>be_close_to" -- was that intentional?). > > Yes!!!! That''s the whole point. ;) > > should be_close_to > > and your method should be named be_close_to > > Let me know how it works out. > > Thanks for giving this a shot - you''re the guinea pig! > > David > >> >> Steve >> >> >> On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: >> >>> module DateExpectations >>> class BeCloseTo >>> def initialize(target_date, tolerance) >>> @target_date = target_date >>> @tolerance = tolerance >>> end >>> >>> def met_by?(target) >>> #return true if target is a date >>> #that meets the expectation >>> end >>> >>> def failure_message >>> #return an appropriate failure message >>> end >>> end >>> >>> def should_be_close_to(target_date, tolerance) >>> return BeCloseTo.new(target_date, tolerance) >>> end >>> end >>> >>> context "My package" do >>> include DateExpectations >>> specify "should be delivered no later than 2 days after my >>> order" do >>> delivery_date.should be_close_to("1/9/2007", :days => 2) >>> end >>> end >> >> _______________________________________________ >> 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
On 1/11/07, s.ross <cwdinfo at gmail.com> wrote:> My net connection''s gone spotty over the last couple of days, but I > wanted to follow up and tell you that your new code works great. > Here''s just a proof of concept implementation (complete with hard > coding!): > > module DateExpectations > HOUR_TOLERANCE = 60 * 60 > DAY_TOLERANCE = HOUR_TOLERANCE * 24 > WEEK_TOLERANCE = DAY_TOLERANCE * 7 > > class BeCloseTo > def initialize(target_date, tolerance) > @target_date = Time.parse(target_date) > @tolerance = tolerance > end > > def met_by?(target) > @compare_date = target > compare_span = target - @target_date > adjustment = 0 > @tolerance.each do |key, amount| > case key > when :hours > adjustment += HOUR_TOLERANCE * amount > when :days > adjustment += DAY_TOLERANCE * amount > when :weeks > adjustment += WEEK_TOLERANCE * amount > end > end > return true if compare_span.abs < adjustment > end > > def failure_message > return "#{@target_date} does not fall within tolerance (# > {@tolerance.collect{|k,v| "#{k.to_s} => #{v}"}.join(", ")}) from # > {@compare_date}." > end > end > > def be_close_to(target_date, tolerance) > return BeCloseTo.new(target_date, tolerance) > end > end > > context "The DateRange helper" do > include DateExpectations > specify "should be able to approximate within two days" do > 1.day.ago.should be_close_to("1/9/2007", :days => 2) > end > endGreat to hear it''s working for you. I just committed support for negative expectations as well. You just need to supply a negative_failure_message in addition to failure_message. Then you can say (given your extension): 3.days.ago.should_not be_close_to("1/10/2007", :days => 2) I am totally psyched about this. In addition to opening the door to custom expectations it seems to be leading towards a leaner implementation in rspec. Cheers, David> > > On Jan 10, 2007, at 11:22 AM, David Chelimsky wrote: > > > On 1/10/07, s.ross <cwdinfo at gmail.com> wrote: > >> I upgraded to trunk and changed the code as follows: > >> > >> module DateExpectations > >> HOUR_TOLERANCE = 60 * 60 > >> DAY_TOLERANCE = HOUR_TOLERANCE * 24 > >> WEEK_TOLERANCE = DAY_TOLERANCE * 7 > >> > >> class BeCloseTo > >> def initialize(target_date, tolerance) > >> @target_date = Time.parse(target_date) > >> @tolerance = tolerance > >> end > >> > >> def met_by?(target) > >> compare_date = target - @target_date > >> adjustment = @tolerance.inject do |item| > >> case item > >> when :days > >> adjustment += DAY_TOLERANCE > >> when :weeks > >> adjustment += WEEK_TOLERANCE > >> end > >> end > >> return true if compare_date.abs < adjustment > >> end > >> > >> def failure_message > >> return "#{@target_date} does not fall within tolerance." # s/ > >> b better > >> end > >> end > >> > >> def should_be_close_to(target_date, tolerance) > >> return BeCloseTo.new(target_date, tolerance) > >> end > >> end > >> > >> context "My package" do > >> include DateExpectations > >> specify "should be delivered no later than 2 days after my > >> order" do > >> 1.day.ago.should_be_close_to("1/9/2007", :days => 2) # <- > >> line 40 > >> end > >> end > >> > >> The result is: > >> > >> 1) > >> NoMethodError in ''My package should be delivered no later than 2 days > >> after my order'' > >> undefined method `close_to?'' for Tue Jan 09 10:59:31 -0800 2007:Time > >> ./spec/helpers/date_range_spec.rb:40: > >> > >> > >> Any thoughts as to why? (Note: You had written the expectation in > >> your sample as: > >> "should<space>be_close_to" -- was that intentional?). > > > > Yes!!!! That''s the whole point. ;) > > > > should be_close_to > > > > and your method should be named be_close_to > > > > Let me know how it works out. > > > > Thanks for giving this a shot - you''re the guinea pig! > > > > David > > > >> > >> Steve > >> > >> > >> On Jan 9, 2007, at 8:26 PM, David Chelimsky wrote: > >> > >>> module DateExpectations > >>> class BeCloseTo > >>> def initialize(target_date, tolerance) > >>> @target_date = target_date > >>> @tolerance = tolerance > >>> end > >>> > >>> def met_by?(target) > >>> #return true if target is a date > >>> #that meets the expectation > >>> end > >>> > >>> def failure_message > >>> #return an appropriate failure message > >>> end > >>> end > >>> > >>> def should_be_close_to(target_date, tolerance) > >>> return BeCloseTo.new(target_date, tolerance) > >>> end > >>> end > >>> > >>> context "My package" do > >>> include DateExpectations > >>> specify "should be delivered no later than 2 days after my > >>> order" do > >>> delivery_date.should be_close_to("1/9/2007", :days => 2) > >>> end > >>> end > >> > >> _______________________________________________ > >> 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 >