spec/timeliness/definitions_spec.rb in timeliness-0.4.2 vs spec/timeliness/definitions_spec.rb in timeliness-0.4.3

- old
+ new

@@ -1,7 +1,6 @@ describe Timeliness::Definitions do - context "add_formats" do before do @default_formats = definitions.time_formats.dup end @@ -100,27 +99,35 @@ expect(Timeliness::FormatSet).not_to receive(:compile) definitions.use_us_formats end end - context "thread safe date format switching" do + context "thread safe ambiguous date format switching" do let(:ambiguous_date) { "01/02/2000" } - it "should allow indepdent regional format control in current thread" do + around do |example| + Timeliness::Definitions.compile_formats + example.call + Timeliness::Definitions.compile_formats + end + + it "should allow independent control in current thread" do threads = { euro: Thread.new { Timeliness.use_euro_formats; sleep(0.005); Timeliness.parse(ambiguous_date) }, us: Thread.new { sleep(0.001); Timeliness.use_us_formats; Timeliness.parse(ambiguous_date) } } threads.values.each { |t| t.join } expect(threads[:euro].value).to eql(Time.new(2000,2,1)) expect(threads[:us].value).to eql(Time.new(2000,1,2)) end - it 'should use default regional format in new threads' do + it 'should use default format in new threads' do + Timeliness.configuration.ambiguous_date_format = :euro + thread = Thread.new { sleep(0.001); Timeliness.parse(ambiguous_date) } thread.join - expect(thread.value).to eql(Time.new(2000,1,2)) + expect(thread.value).to eql(Time.new(2000,2,1)) end end end