mirror of
https://github.com/jimeh/time_ext.git
synced 2026-02-19 05:16:40 +00:00
Interation methods #each, #map_each and more are
implemented and working. Also restructured files again.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe "TimeExt" do
|
||||
describe "Time Calculations" do
|
||||
|
||||
before(:each) do
|
||||
@time = Time.local(2010, 8, 28, 15, 57, 17, 78430)
|
||||
63
spec/time_iterations_spec.rb
Normal file
63
spec/time_iterations_spec.rb
Normal file
@@ -0,0 +1,63 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
||||
|
||||
describe "Time Iterations" do
|
||||
|
||||
before(:each) do
|
||||
@now = Time.now
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #each" do
|
||||
times = []
|
||||
result = @now.each(:hour) { |time| times << time }
|
||||
times.should have(24).items
|
||||
times.should == (1..24).map { |i| @now + i.hours }
|
||||
result.should == @now
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #beginning_of_each" do
|
||||
times = []
|
||||
result = @now.beginning_of_each_hour { |time| times << time }
|
||||
times.should have(24).items
|
||||
times.should == (1..24).map { |i| @now.beginning_of_hour + i.hours }
|
||||
result.should == @now
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #map_each" do
|
||||
result = @now.map_each_hour { |time| time }
|
||||
result.should have(24).items
|
||||
result.should == (1..24).map { |i| @now + i.hours }
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #map_beginning_of_each" do
|
||||
result = @now.map_beginning_of_each(:hour) { |time| time }
|
||||
result.should have(24).items
|
||||
result.should == (1..24).map { |i| @now.beginning_of_hour + i.hours }
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #each and #until via method chaining" do
|
||||
match = (1..6).map { |i| @now + i.hours }
|
||||
|
||||
times = []
|
||||
result = @now.each(:hour).until(@now + 6.hours) { |time| times << time }
|
||||
times.should == match
|
||||
result.should == @now
|
||||
|
||||
times = []
|
||||
result = @now.until(@now + 6.hours).each_hour { |time| times << time }
|
||||
times.should == match
|
||||
result.should == @now
|
||||
end
|
||||
|
||||
it "should iterate over time objects with #map_each and #until via method chaining" do
|
||||
match = (1..6).map { |i| @now + i.hours }
|
||||
@now.map_each_hour.until(@now + 6.hours) { |time| time }.should == match
|
||||
@now.until(@now + 6.hours).map_each(:hour) { |time| time }.should == match
|
||||
end
|
||||
|
||||
it "should iterate over time objects backwards with #until set in the past" do
|
||||
match = (1..6).map { |i| @now - i.hours }
|
||||
@now.map_each_hour.until(@now - 6.hours) { |time| time }.should == match
|
||||
@now.until(@now - 6.hours).map_each(:hour) { |time| time }.should == match
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user