diff options
author | Toon Claes <toon@gitlab.com> | 2018-03-06 20:42:14 +0100 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-03-06 20:42:14 +0100 |
commit | b0e5906d190ce1de499a553132f25de9135a1449 (patch) | |
tree | a8fd5b45c29db44dc32988a2d98678b6cadf6599 /spec/support/matchers | |
parent | 35f6efaee05835b75e605e1f269e57a8d6daf3fa (diff) | |
download | gitlab-ce-b0e5906d190ce1de499a553132f25de9135a1449.tar.gz |
Add matcher to match elements by idstc-geo-local-only-counts-matcher
Initially added in gitlab-org/gitlab-ee!4864 and
gitlab-org/gitlab-ee!4689.
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/match_ids.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/support/matchers/match_ids.rb b/spec/support/matchers/match_ids.rb new file mode 100644 index 00000000000..d8424405b96 --- /dev/null +++ b/spec/support/matchers/match_ids.rb @@ -0,0 +1,24 @@ +RSpec::Matchers.define :match_ids do |*expected| + match do |actual| + actual_ids = map_ids(actual) + expected_ids = map_ids(expected) + + expect(actual_ids).to match_array(expected_ids) + end + + description do + 'matches elements by ids' + end + + def map_ids(elements) + elements = elements.flatten if elements.respond_to?(:flatten) + + if elements.respond_to?(:map) + elements.map(&:id) + elsif elements.respond_to?(:id) + [elements.id] + else + raise ArgumentError, "could not map elements to ids: #{elements}" + end + end +end |