spec/lib/timeparser_spec.rb in timeparser-0.0.1 vs spec/lib/timeparser_spec.rb in timeparser-0.0.2

- old
+ new

@@ -3,23 +3,62 @@ describe Timeparser do it "creates instance" do Timeparser::Parser.new.should_not be_nil end - let(:parser){ Timeparser::Parser.new } + context "instance methods" do + let(:parser){ Timeparser::Parser.new } - it "parses hours" do - parser.parse('1h').should eql 60 - end + it "ignores whitespaces" do + parser.parse(" 1h ").to_i.should eql 60 + end - it "parses minutes" do - parser.parse('1m').should eql 1 - end + it "handles whitespaces in between" do + parser.parse('1h 20m').to_i.should eql 80 + end - it "parses hours and minutes" do - parser.parse('1h20m').should eql 80 + it "parses hours" do + parser.parse('1h').to_i.should eql 60 + parser.parse('2hrs').to_i.should eql 120 + parser.parse('2hours').to_i.should eql 120 + end + + it "parses minutes" do + parser.parse('1m').to_i.should eql 1 + parser.parse('20min').to_i.should eql 20 + parser.parse('120minutes').to_i.should eql 120 + end + + it "parses hours and minutes" do + parser.parse('1h20m').to_i.should eql 80 + end + + it "parses colon notation" do + parser.parse('1:20').to_i.should eql 80 + end + + it "parses enhanced colon notation" do + parser.parse('1h:20m').to_i.should eql 80 + end + + it "parses empty string" do + parser.parse('').to_i.should eql 0 + end + + it "parses times within a text" do + parser.parse(%Q{The movie was 1h long but the truck was 20m long.}).to_i.should eql 0 + end end - it "parses dot notation" do - parser.parse('1:20').should eql 80 + + context "module methods" do + it "has instance of parser" do + Timeparser.parser.should be_instance_of(Timeparser::Parser) + end + + it "should delegate to parser instance" do + Timeparser.parser.should_receive(:parse).with('1:20') + Timeparser.parse('1:20') + end end + end \ No newline at end of file