debian-mirror-gitlab/tooling/rspec_flaky/flaky_examples_collection.rb

39 lines
958 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-10-15 14:42:47 +05:30
require 'active_support/hash_with_indifferent_access'
2021-01-29 00:20:46 +05:30
require 'delegate'
2018-10-15 14:42:47 +05:30
require_relative 'flaky_example'
2018-03-17 18:26:18 +05:30
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,
2022-01-26 12:08:38 +05:30
RspecFlaky::FlakyExample.new(example.to_h.symbolize_keys)
2018-03-17 18:26:18 +05:30
]
end
super(Hash[collection_of_flaky_examples])
end
2018-10-15 14:42:47 +05:30
def to_h
2020-07-28 23:09:34 +05:30
transform_values { |example| example.to_h }.deep_symbolize_keys
2018-03-17 18:26:18 +05:30
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