summaryrefslogtreecommitdiff
path: root/lib/rspec_flaky/examples_pruner.rb
blob: de6cf30d8eea428b7e3aada8d82ef2a950406c19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require 'json'

module RspecFlaky
  class ExamplesPruner
    # - flaky_examples: contains flaky examples
    attr_reader :flaky_examples

    def initialize(collection)
      unless collection.is_a?(RspecFlaky::FlakyExamplesCollection)
        raise ArgumentError, "`collection` must be a RspecFlaky::FlakyExamplesCollection, #{collection.class} given!"
      end

      @flaky_examples = collection
    end

    def prune_examples_older_than(date)
      updated_hash = flaky_examples.dup
        .delete_if do |uid, hash|
          hash[:last_flaky_at] && Time.parse(hash[:last_flaky_at]).to_i < date.to_i
        end

      RspecFlaky::FlakyExamplesCollection.new(updated_hash)
    end
  end
end