summaryrefslogtreecommitdiff
path: root/spec/ruby/core/time/minus_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/time/minus_spec.rb')
-rw-r--r--spec/ruby/core/time/minus_spec.rb40
1 files changed, 29 insertions, 11 deletions
diff --git a/spec/ruby/core/time/minus_spec.rb b/spec/ruby/core/time/minus_spec.rb
index 4e2bb60333..ee3d8acda8 100644
--- a/spec/ruby/core/time/minus_spec.rb
+++ b/spec/ruby/core/time/minus_spec.rb
@@ -1,4 +1,5 @@
-require File.expand_path('../../../spec_helper', __FILE__)
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
describe "Time#-" do
it "decrements the time by the specified amount" do
@@ -19,18 +20,18 @@ describe "Time#-" do
end
it "raises a TypeError if given argument is a coercible String" do
- lambda { Time.now - "1" }.should raise_error(TypeError)
- lambda { Time.now - "0.1" }.should raise_error(TypeError)
- lambda { Time.now - "1/3" }.should raise_error(TypeError)
+ -> { Time.now - "1" }.should.raise(TypeError)
+ -> { Time.now - "0.1" }.should.raise(TypeError)
+ -> { Time.now - "1/3" }.should.raise(TypeError)
end
it "raises TypeError on argument that can't be coerced" do
- lambda { Time.now - Object.new }.should raise_error(TypeError)
- lambda { Time.now - "stuff" }.should raise_error(TypeError)
+ -> { Time.now - Object.new }.should.raise(TypeError)
+ -> { Time.now - "stuff" }.should.raise(TypeError)
end
it "raises TypeError on nil argument" do
- lambda { Time.now - nil }.should raise_error(TypeError)
+ -> { Time.now - nil }.should.raise(TypeError)
end
it "tracks microseconds" do
@@ -78,21 +79,38 @@ describe "Time#-" do
end
it "returns a UTC time if self is UTC" do
- (Time.utc(2012) - 10).utc?.should == true
+ (Time.utc(2012) - 10).should.utc?
end
it "returns a non-UTC time if self is non-UTC" do
- (Time.local(2012) - 10).utc?.should == false
+ (Time.local(2012) - 10).should_not.utc?
end
it "returns a time with the same fixed offset as self" do
(Time.new(2012, 1, 1, 0, 0, 0, 3600) - 10).utc_offset.should == 3600
end
+ it "preserves time zone" do
+ time_with_zone = Time.now.utc
+ time_with_zone.zone.should == (time_with_zone - 1).zone
+
+ time_with_zone = Time.now
+ time_with_zone.zone.should == (time_with_zone - 1).zone
+ end
+
+ context "zone is a timezone object" do
+ it "preserves time zone" do
+ zone = TimeSpecs::Timezone.new(offset: (5*3600+30*60))
+ time = Time.new(2012, 1, 1, 12, 0, 0, zone) - 1
+
+ time.zone.should == zone
+ end
+ end
+
it "does not return a subclass instance" do
c = Class.new(Time)
- x = c.now + 1
- x.should be_an_instance_of(Time)
+ x = c.now - 1
+ x.should.instance_of?(Time)
end
it "returns a time with nanoseconds precision between two time objects" do