From 1a011b51dedf5d5e84c0d8e8fe7c599190450fbd Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Mon, 11 Aug 2014 09:41:12 -0700 Subject: fix the timezone to UTC or Date specs will fail only works in -800 right now --- spec/ffi_yajl/encoder_spec.rb | 17 ++++++++++++++--- spec/ffi_yajl/json_gem_spec.rb | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'spec') 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 -- cgit v1.2.1