From 767ef550281bcdc8782233840f98cf8487340476 Mon Sep 17 00:00:00 2001 From: John Mettraux Date: Thu, 15 Aug 2024 20:47:17 +0900 Subject: [PATCH] Add spec for Fugit.parse() and .do_parse, gh-104 --- spec/parse_spec.rb | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/spec/parse_spec.rb b/spec/parse_spec.rb index 2f40cdc..f1590f5 100644 --- a/spec/parse_spec.rb +++ b/spec/parse_spec.rb @@ -114,9 +114,11 @@ it "returns nil quickly if the input is useless and long, gh-104" do - o = Fugit.parse('0 0' + ' 0' * 10_000 + ' 1 jan * UTC') -p o -# TODO + o, d = do_time { + Fugit.parse('0 0' + ' 0' * 10_000 + ' 1 jan * UTC') } + + expect(o).to be(nil) + expect(d).to be < 0.042 end end @@ -142,6 +144,23 @@ expect { Fugit.do_parse(k) }.to raise_error(ArgumentError) end end + + it "fails quickly if the input is useless and long, gh-104" do + + r, d = do_time { + begin + Fugit.do_parse('0 0' + ' 0' * 10_000 + ' 1 jan * UTC') + rescue => err + err + end } + + expect(r.class).to be( + ArgumentError) + expect(r.message).to eq( + 'invalid cron string "0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... len 20015"') + + expect(d).to be < 0.042 + end end CRONISHES = {