Skip to content

Commit

Permalink
Add strip spec for Fugit.parse itself, gh-74
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Aug 24, 2022
1 parent 6eaf79d commit 0a26f39
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions spec/parse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

describe '.parse' do

{
CASES = {
'2017-01-03 11:21:17' => [ EtOrbi::EoTime, '2017-01-03 11:21:17 Z' ],
'00 00 L 5 *' => [ Fugit::Cron, '0 0 -1 5 *' ],
'1Y3M2d' => [ Fugit::Duration, '1Y3M2D' ],
Expand All @@ -34,25 +34,52 @@
[ 'every day at noon', { nat: false } ] => nil,
[ '* * * * 1', { cron: false } ] => nil,


true => nil,
'I have a pen, I have an apple, pen apple' => nil,

}.each do |k, (c, s)|
'every day at noon' => [ Fugit::Cron, '0 12 * * *' ],
'0 0 1 jan *' => [ Fugit::Cron, '0 0 1 1 *' ],
'at 12 PM' => [ Fugit::Cron, '0 12 * * *' ],
'at noon' => [ Fugit::Cron, '0 12 * * *' ],
}

CASES.each do |k, (c, s)|

k, opts = k
t = k.inspect + (opts ? ' ' + opts.inspect : '')
opts ||= {}

it "parses #{t} into #{c} / #{s.inspect}" do

c =
c || NilClass
c = c || NilClass
x = in_zone('UTC') { Fugit.parse(k, opts) }

expect(x.class).to eq(c)

x =
in_zone('UTC') do
Fugit.parse(k, opts)
expect(
case x
when EtOrbi::EoTime then Fugit.time_to_plain_s(x)
when Fugit::Duration then x.to_plain_s
when Fugit::Cron then x.to_cron_s
else nil
end
).to eq(s)
end
end

CASES.each do |k, (c, s)|

k, opts = k

t = k.inspect + (opts ? ' ' + opts.inspect : '')
t = " \n #{t} \n "

opts ||= {}

it "parses #{t} into #{c} / #{s.inspect}" do

c = c || NilClass
x = in_zone('UTC') { Fugit.parse(k, opts) }

expect(x.class).to eq(c)

Expand Down

0 comments on commit 0a26f39

Please sign in to comment.