spec/rtime_spec.rb in rufus-scheduler-2.0.17 vs spec/rtime_spec.rb in rufus-scheduler-2.0.18

- old
+ new

@@ -22,10 +22,19 @@ Rufus.to_duration_hash(f, opts) end it 'parses duration strings' do + pts('-1.0d1.0w1.0d').should == -777600.0 + pts('-1d1w1d').should == -777600.0 + pts('-1w2d').should == -777600.0 + pts('-1h10s').should == -3610.0 + pts('-1h').should == -3600.0 + pts('-5.').should == -5.0 + pts('-2.5s').should == -2.5 + pts('-1s').should == -1.0 + pts('-500').should == -0.5 pts('').should == 0.0 pts('5.0').should == 5.0 pts('0.5').should == 0.5 pts('.5').should == 0.5 pts('5.').should == 5.0 @@ -37,9 +46,24 @@ pts('1h').should == 3600.0 pts('1h10s').should == 3610.0 pts('1w2d').should == 777600.0 pts('1d1w1d').should == 777600.0 pts('1.0d1.0w1.0d').should == 777600.0 + + pts('.5m').should == 30.0 + pts('5.m').should == 300.0 + pts('1m.5s').should == 60.5 + pts('-.5m').should == -30.0 + end + + it 'raises on wrong duration strings' do + + lambda { pts('-') }.should raise_error(ArgumentError) + lambda { pts('h') }.should raise_error(ArgumentError) + lambda { pts('whatever') }.should raise_error(ArgumentError) + lambda { pts('hms') }.should raise_error(ArgumentError) + + lambda { pts(' 1h ') }.should raise_error(ArgumentError) end it 'generates duration strings' do tts(0).should == '0s'