summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-08-11 09:41:12 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-08-23 11:16:14 -0700
commit1a011b51dedf5d5e84c0d8e8fe7c599190450fbd (patch)
treea05b153e25c669d92d79f3d5b43d63094262d872 /spec
parent5d35f31762750169569eb5ae9ce51b9af8a91793 (diff)
downloadffi-yajl-1a011b51dedf5d5e84c0d8e8fe7c599190450fbd.tar.gz
fix the timezone to UTC or Date specs will fail
only works in -800 right now
Diffstat (limited to 'spec')
-rw-r--r--spec/ffi_yajl/encoder_spec.rb17
-rw-r--r--spec/ffi_yajl/json_gem_spec.rb17
2 files changed, 28 insertions, 6 deletions
diff --git a/spec/ffi_yajl/encoder_spec.rb b/spec/ffi_yajl/encoder_spec.rb
index 969481a..b358f17 100644
--- a/spec/ffi_yajl/encoder_spec.rb
+++ b/spec/ffi_yajl/encoder_spec.rb
@@ -65,9 +65,20 @@ describe "FFI_Yajl::Encoder" do
expect(encoder.encode(ruby)).to eq( %q{"2001-02-03"} )
end
- it "can encode Time objects" do
- ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
- expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 13:05:06 -0800"} )
+ context "when encoding Time objects in UTC timezone" do
+ before do
+ @saved_tz = ENV['TZ']
+ ENV['TZ'] = 'UTC'
+ end
+
+ after do
+ ENV['TZ'] = @saved_tz
+ end
+
+ it "encodes them correctly" do
+ ruby = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
+ expect(encoder.encode(ruby)).to eq( %q{"2001-02-02 21:05:06 +0000"} )
+ end
end
it "can encode DateTime objects" do
diff --git a/spec/ffi_yajl/json_gem_spec.rb b/spec/ffi_yajl/json_gem_spec.rb
index bfb9e2b..1aa1edd 100644
--- a/spec/ffi_yajl/json_gem_spec.rb
+++ b/spec/ffi_yajl/json_gem_spec.rb
@@ -148,9 +148,20 @@ describe "JSON Gem Compat API" do
expect(d.to_json).to eq( %Q{"#{d.to_s}"} )
end
- it "encodes Time values correctly" do
- t = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
- expect(t.to_json).to eq( %Q{"2001-02-02 13:05:06 -0800"} )
+ context "when encoding Time objects in UTC timezone" do
+ before do
+ @saved_tz = ENV['TZ']
+ ENV['TZ'] = 'UTC'
+ end
+
+ after do
+ ENV['TZ'] = @saved_tz
+ end
+
+ it "encodes Time values correctly" do
+ t = DateTime.parse('2001-02-03T04:05:06.1+07:00').to_time
+ expect(t.to_json).to eq( %Q{"2001-02-02 21:05:06 +0000"} )
+ end
end
it "encodes Date values correctly" do