Sha256: eb564b6fc040ce09f9b2677ed76768d215fab10376a0acf7deda3f657850f32c

Contents?: true

Size: 949 Bytes

Versions: 6

Compression:

Stored size: 949 Bytes

Contents

require 'date'

describe "Date#step" do

  it "steps forward in time" do
    ds    = Date.civil(2008, 10, 11)
    de    = Date.civil(2008,  9, 29)
    count = 0
    de.step(ds) do |d|
      d.should <= ds
      d.should >= de
      count += 1
    end
    count.should == 13

    count = 0
    de.step(ds, 5) do |d|
      d.should <= ds
      d.should >= de
      count += 1
    end
    count.should == 3

    count = 0
    ds.step(de) do |d|; count += 1; end
    count.should == 0

  end

  it "steps backward in time" do
    ds    = Date.civil(2000, 4, 14)
    de    = Date.civil(2000, 3, 29)
    count = 0
    ds.step(de, -1) do |d|
      d.should <= ds
      d.should >= de
      count += 1
    end
    count.should == 17

    count = 0
    ds.step(de, -5) do |d|
      d.should <= ds
      d.should >= de
      count += 1
    end
    count.should == 4

    count = 0
    de.step(ds, -1) do |d|; count += 1; end
    count.should == 0

  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rubysl-date-2.0.9 spec/date/step_spec.rb
rubysl-date-2.0.8 spec/date/step_spec.rb
rubysl-date-2.0.6 spec/date/step_spec.rb
rubysl-date-2.0.5 spec/date/step_spec.rb
rubysl-date-2.0.3 spec/date/step_spec.rb
rubysl-date-1.0.1 spec/date/step_spec.rb