2018-10-08 10:50:39 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-04-10 07:22:19 -04:00
|
|
|
require 'active_support/hash_with_indifferent_access'
|
2020-10-26 05:08:48 -04:00
|
|
|
require 'delegate'
|
2017-10-05 09:59:58 -04:00
|
|
|
|
2018-04-06 12:30:59 -04:00
|
|
|
require_relative 'flaky_example'
|
|
|
|
|
2017-10-05 09:59:58 -04:00
|
|
|
module RspecFlaky
|
|
|
|
class FlakyExamplesCollection < SimpleDelegator
|
|
|
|
def initialize(collection = {})
|
|
|
|
unless collection.is_a?(Hash)
|
|
|
|
raise ArgumentError, "`collection` must be a Hash, #{collection.class} given!"
|
|
|
|
end
|
|
|
|
|
|
|
|
collection_of_flaky_examples =
|
|
|
|
collection.map do |uid, example|
|
|
|
|
[
|
|
|
|
uid,
|
2021-12-13 16:14:32 -05:00
|
|
|
RspecFlaky::FlakyExample.new(example.to_h.symbolize_keys)
|
2017-10-05 09:59:58 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
super(Hash[collection_of_flaky_examples])
|
|
|
|
end
|
|
|
|
|
2018-04-10 07:22:19 -04:00
|
|
|
def to_h
|
2020-06-21 20:08:57 -04:00
|
|
|
transform_values { |example| example.to_h }.deep_symbolize_keys
|
2017-10-05 09:59:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def -(other)
|
|
|
|
unless other.respond_to?(:key)
|
|
|
|
raise ArgumentError, "`other` must respond to `#key?`, #{other.class} does not!"
|
|
|
|
end
|
|
|
|
|
|
|
|
self.class.new(reject { |uid, _| other.key?(uid) })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|