diff --git a/lib/fbe/iterate.rb b/lib/fbe/iterate.rb index 969d5d3..f72b239 100644 --- a/lib/fbe/iterate.rb +++ b/lib/fbe/iterate.rb @@ -97,6 +97,7 @@ def initialize(fb:, loog:, options:, global:, epoch:, kickoff:) @kickoff = kickoff @label = nil @since = 0 + @custom = false @query = nil @sorting = nil @repeats = 1 @@ -161,9 +162,11 @@ def repeats(repeats) # @example Start iteration from issue number 100 # iterator.since(100) def since(value) + raise(Fbe::Error, 'Since is already set') if @custom raise(Fbe::Error, 'Cannot set "since" to nil') if value.nil? raise(Fbe::Error, 'The "since" must be an Integer') unless value.is_a?(Integer) @since = value + @custom = true end # Sets the query to execute for each iteration. diff --git a/test/fbe/test_iterate.rb b/test/fbe/test_iterate.rb index dc9cfd0..0d4b244 100644 --- a/test/fbe/test_iterate.rb +++ b/test/fbe/test_iterate.rb @@ -191,6 +191,54 @@ def test_raises_when_repeats_is_not_positive end end + def test_configures_since_start + opts = Judges::Options.new(['repositories=foo/bar', 'testing=true']) + fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL) + seen = [] + Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do + as('custom_since_test') + since(7) + by('(plus $before 1)') + repeats(1) + over do |_, nxt| + seen << nxt + nxt + end + end + assert_equal([8], seen) + end + + def test_raises_when_since_is_nil + opts = Judges::Options.new(['repositories=foo/bar', 'testing=true']) + fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL) + assert_raises(Fbe::Error) do + Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do + since(nil) + end + end + end + + def test_raises_when_since_is_not_integer + opts = Judges::Options.new(['repositories=foo/bar', 'testing=true']) + fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL) + assert_raises(Fbe::Error) do + Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do + since('7') + end + end + end + + def test_raises_when_since_set_twice + opts = Judges::Options.new(['repositories=foo/bar', 'testing=true']) + fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL) + assert_raises(Fbe::Error) do + Fbe.iterate(fb:, loog: Loog::NULL, global: {}, options: opts, epoch: Time.now, kickoff: Time.now) do + since(1) + since(2) + end + end + end + def test_raises_when_label_is_nil opts = Judges::Options.new(['repositories=foo/bar', 'testing=true']) fb = Fbe.fb(fb: Factbase.new, global: {}, options: opts, loog: Loog::NULL)