spec/timeliness/definitions_spec.rb in timeliness-0.3.6 vs spec/timeliness/definitions_spec.rb in timeliness-0.3.7
- old
+ new
@@ -17,22 +17,22 @@
definitions.add_formats(:time, "h o'clock")
should_parse("12 o'clock", :time)
end
it "should raise error if format exists" do
- expect { definitions.add_formats(:time, "hh:nn:ss") }.should raise_error
+ expect { definitions.add_formats(:time, "hh:nn:ss") }.to raise_error
end
context "with :before option" do
it "should add new format with higher precedence" do
definitions.add_formats(:time, "ss:hh:nn", :before => 'hh:nn:ss')
time_array = parser._parse('59:23:58', :time)
- time_array.should == [nil,nil,nil,23,58,59,nil,nil]
+ time_array.should eq [nil,nil,nil,23,58,59,nil,nil]
end
it "should raise error if :before format does not exist" do
- expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.should raise_error
+ expect { definitions.add_formats(:time, "ss:hh:nn", :before => 'nn:hh:ss') }.to raise_error
end
end
after do
definitions.time_formats = @default_formats
@@ -61,34 +61,46 @@
definitions.remove_formats(:time, 'h.nn_ampm')
should_not_parse('2.12am', :time)
end
it "should raise error if format does not exist" do
- expect { definitions.remove_formats(:time, "ss:hh:nn") }.should raise_error()
+ expect { definitions.remove_formats(:time, "ss:hh:nn") }.to raise_error()
end
after do
definitions.time_formats = @default_formats
definitions.compile_formats
end
end
context "use_euro_formats" do
it "should allow ambiguous date to be parsed as European format" do
- parser._parse('01/02/2000', :date).should == [2000,1,2,nil,nil,nil,nil,nil]
+ parser._parse('01/02/2000', :date).should eq [2000,1,2,nil,nil,nil,nil,nil]
definitions.use_euro_formats
- parser._parse('01/02/2000', :date).should == [2000,2,1,nil,nil,nil,nil,nil]
+ parser._parse('01/02/2000', :date).should eq [2000,2,1,nil,nil,nil,nil,nil]
end
+
+ it "should not parse formats on switch to euro after initial compile" do
+ definitions.compile_formats
+ Timeliness::FormatSet.should_not_receive(:compile)
+ definitions.use_euro_formats
+ end
end
- context "use_use_formats" do
+ context "use_us_formats" do
before do
definitions.use_euro_formats
end
it "should allow ambiguous date to be parsed as European format" do
- parser._parse('01/02/2000', :date).should == [2000,2,1,nil,nil,nil,nil,nil]
+ parser._parse('01/02/2000', :date).should eq [2000,2,1,nil,nil,nil,nil,nil]
definitions.use_us_formats
- parser._parse('01/02/2000', :date).should == [2000,1,2,nil,nil,nil,nil,nil]
+ parser._parse('01/02/2000', :date).should eq [2000,1,2,nil,nil,nil,nil,nil]
+ end
+
+ it "should not parse formats on switch to euro after initial compile" do
+ definitions.compile_formats
+ Timeliness::FormatSet.should_not_receive(:compile)
+ definitions.use_us_formats
end
end
end