spec/timeliness/format_set_spec.rb in timeliness-0.3.7 vs spec/timeliness/format_set_spec.rb in timeliness-0.3.8

- old
+ new

@@ -1,14 +1,12 @@ -require 'spec_helper' - describe Timeliness::FormatSet do context "#compile!" do let(:set) { Timeliness::FormatSet.new(['yyyy-mm-dd', 'dd/mm/yyyy']) } it 'should set the regexp for the set' do set.compile! - set.regexp.should_not be_nil + expect(set.regexp).not_to be_nil end end context "compiled regexp" do context "for time formats" do @@ -26,12 +24,12 @@ 'h_ampm' => {:pass => ['2am', '2 am', '12 pm'], :fail => ['1.am', '12 pm', '2:12am']}, } format_tests.each do |format, values| it "should correctly match times in format '#{format}'" do regexp = compile_regexp(format) - values[:pass].each {|value| value.should match(regexp)} - values[:fail].each {|value| value.should_not match(regexp)} + values[:pass].each {|value| expect(value).to match(regexp)} + values[:fail].each {|value| expect(value).not_to match(regexp)} end end end context "for date formats" do @@ -49,12 +47,12 @@ :fail => ['1 Fe 00', 'Feb 1 2000', '1 Feb 0']} } format_tests.each do |format, values| it "should correctly match dates in format '#{format}'" do regexp = compile_regexp(format) - values[:pass].each {|value| value.should match(regexp)} - values[:fail].each {|value| value.should_not match(regexp)} + values[:pass].each {|value| expect(value).to match(regexp)} + values[:fail].each {|value| expect(value).not_to match(regexp)} end end end context "for datetime formats" do @@ -63,36 +61,36 @@ 'yyyy-mm-ddThh:nn:ss(?:Z|zo)' => {:pass => ['2008-07-19T12:00:00+10:00', '2008-07-19T12:00:00Z'], :fail => ['2008-07-19T12:00:00Z+10:00']}, } format_tests.each do |format, values| it "should correctly match datetimes in format '#{format}'" do regexp = compile_regexp(format) - values[:pass].each {|value| value.should match(regexp)} - values[:fail].each {|value| value.should_not match(regexp)} + values[:pass].each {|value| expect(value).to match(regexp)} + values[:fail].each {|value| expect(value).not_to match(regexp)} end end end end context "#match" do let(:set) { Timeliness::FormatSet.compile(['yyyy-mm-dd', 'dd/mm/yyyy']) } it 'should return array if string matches a format in set' do - set.match('2000-01-02').should be_kind_of(Array) + expect(set.match('2000-01-02')).to be_kind_of(Array) end it 'should return nil if string does not matches a format in set' do - set.match('2nd Feb 2000').should be_nil + expect(set.match('2nd Feb 2000')).to be_nil end it 'should only use specific format string for match if provided' do - set.match('2000-01-02', 'yyyy-mm-dd').should be_kind_of(Array) - set.match('2000-01-02', 'dd/mm/yyyy').should be_nil + expect(set.match('2000-01-02', 'yyyy-mm-dd')).to be_kind_of(Array) + expect(set.match('2000-01-02', 'dd/mm/yyyy')).to be_nil end it 'should compile unknown format for one off match' do - set.match('20001011').should be_nil - set.match('20001011', 'yyyymmdd').should be_kind_of(Array) + expect(set.match('20001011')).to be_nil + expect(set.match('20001011', 'yyyymmdd')).to be_kind_of(Array) end end def compile_regexp(format) Timeliness::FormatSet.compile([format]).regexp