Skip to content

Instantly share code, notes, and snippets.

@jfredett
Created June 15, 2012 17:36
Show Gist options
  • Save jfredett/2937762 to your computer and use it in GitHub Desktop.
Save jfredett/2937762 to your computer and use it in GitHub Desktop.
[PATCH] add specs for Time#round
From 91c5562dc68d2b9f067b4bce76c14eff9e216cfc Mon Sep 17 00:00:00 2001
From: Joe Fredette <jfredett@gmail.com>
Date: Fri, 15 Jun 2012 13:28:43 -0400
Subject: [PATCH] add specs for Time#round
---
spec/ruby/core/time/round_spec.rb | 54 ++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/spec/ruby/core/time/round_spec.rb b/spec/ruby/core/time/round_spec.rb
index 2a988c3..285feaf 100644
--- a/spec/ruby/core/time/round_spec.rb
+++ b/spec/ruby/core/time/round_spec.rb
@@ -1,7 +1,59 @@
require File.expand_path('../../../spec_helper', __FILE__)
ruby_version_is "1.9" do
+ require 'time'
describe "Time#round" do
- it "needs to be reviewed for spec completeness"
+
+ before do
+ @time = Time.utc(2010, 3, 30, 5, 43, "25.123456789".to_r)
+ end
+
+ it "defaults to rounding to 0 places" do
+ @time.round.iso8601(10).should == "2010-03-30T05:43:25.0000000000Z"
+ end
+
+ it "rounds to 0 decimal places with an explicit argument" do
+ @time.round(0).iso8601(10).should == "2010-03-30T05:43:25.0000000000Z"
+ end
+
+ it "rounds to 1 decimal places with an explicit argument" do
+ @time.round(1).iso8601(10).should == "2010-03-30T05:43:25.1000000000Z"
+ end
+
+ it "rounds to 2 decimal places with an explicit argument" do
+ @time.round(2).iso8601(10).should == "2010-03-30T05:43:25.1200000000Z"
+ end
+
+ it "rounds to 3 decimal places with an explicit argument" do
+ @time.round(3).iso8601(10).should == "2010-03-30T05:43:25.1230000000Z"
+ end
+
+ it "rounds to 4 decimal places with an explicit argument" do
+ @time.round(4).iso8601(10).should == "2010-03-30T05:43:25.1235000000Z"
+ end
+
+ it "rounds to 5 decimal places with an explicit argument" do
+ @time.round(5).iso8601(10).should == "2010-03-30T05:43:25.1234600000Z"
+ end
+
+ it "rounds to 6 decimal places with an explicit argument" do
+ @time.round(6).iso8601(10).should == "2010-03-30T05:43:25.1234570000Z"
+ end
+
+ it "rounds to 7 decimal places with an explicit argument" do
+ @time.round(7).iso8601(10).should == "2010-03-30T05:43:25.1234568000Z"
+ end
+
+ it "rounds to 8 decimal places with an explicit argument" do
+ @time.round(8).iso8601(10).should == "2010-03-30T05:43:25.1234567900Z"
+ end
+
+ it "rounds to 9 decimal places with an explicit argument" do
+ @time.round(9).iso8601(10).should == "2010-03-30T05:43:25.1234567890Z"
+ end
+
+ it "rounds to 10 decimal places with an explicit argument" do
+ @time.round(10).iso8601(10).should == "2010-03-30T05:43:25.1234567890Z"
+ end
end
end
--
1.7.10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment