mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle splat in macro for matcher DSL
Should fix https://github.com/icy-arctic-fox/spectator/issues/8
This commit is contained in:
parent
9c14c69bba
commit
8f0718db86
1 changed files with 35 additions and 10 deletions
|
@ -450,8 +450,13 @@ module Spectator
|
||||||
# expect(%i[a b c]).to contain(:a, :b)
|
# expect(%i[a b c]).to contain(:a, :b)
|
||||||
# ```
|
# ```
|
||||||
macro contain(*expected)
|
macro contain(*expected)
|
||||||
|
{% if expected.id.starts_with?("{*") %}
|
||||||
|
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
|
||||||
|
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
||||||
|
{% else %}
|
||||||
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
||||||
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates that some range (or collection) should contain another value.
|
# Indicates that some range (or collection) should contain another value.
|
||||||
|
@ -471,8 +476,13 @@ module Spectator
|
||||||
# expect(..100).to contain(0, 50)
|
# expect(..100).to contain(0, 50)
|
||||||
# ```
|
# ```
|
||||||
macro cover(*expected)
|
macro cover(*expected)
|
||||||
|
{% if expected.id.starts_with?("{*") %}
|
||||||
|
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
|
||||||
|
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
||||||
|
{% else %}
|
||||||
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
||||||
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
::Spectator::Matchers::ContainMatcher.new(%test_value)
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates that some value or set should contain another value.
|
# Indicates that some value or set should contain another value.
|
||||||
|
@ -501,8 +511,13 @@ module Spectator
|
||||||
# expect(%w[FOO BAR BAZ]).to have(/foo/i, String)
|
# expect(%w[FOO BAR BAZ]).to have(/foo/i, String)
|
||||||
# ```
|
# ```
|
||||||
macro have(*expected)
|
macro have(*expected)
|
||||||
|
{% if expected.id.starts_with?("{*") %}
|
||||||
|
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
|
||||||
|
::Spectator::Matchers::HaveMatcher.new(%test_value)
|
||||||
|
{% else %}
|
||||||
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
|
||||||
::Spectator::Matchers::HaveMatcher.new(%test_value)
|
::Spectator::Matchers::HaveMatcher.new(%test_value)
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates that some set, such as a `Hash`, has a given key.
|
# Indicates that some set, such as a `Hash`, has a given key.
|
||||||
|
@ -548,8 +563,13 @@ module Spectator
|
||||||
# expect([1, 2, 3]).to contain_exactly(3, 2, 1)
|
# expect([1, 2, 3]).to contain_exactly(3, 2, 1)
|
||||||
# ```
|
# ```
|
||||||
macro contain_exactly(*expected)
|
macro contain_exactly(*expected)
|
||||||
|
{% if expected.id.starts_with?("{*") %}
|
||||||
|
%test_value = ::Spectator::TestValue.new(({{expected.id[2...-1]}}).to_a, {{expected.stringify}})
|
||||||
|
::Spectator::Matchers::ArrayMatcher.new(%test_value)
|
||||||
|
{% else %}
|
||||||
%test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}})
|
%test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}})
|
||||||
::Spectator::Matchers::ArrayMatcher.new(%test_value)
|
::Spectator::Matchers::ArrayMatcher.new(%test_value)
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Indicates that some set should contain the same values in any order as another set.
|
# Indicates that some set should contain the same values in any order as another set.
|
||||||
|
@ -597,8 +617,13 @@ module Spectator
|
||||||
# expect(%i[a b c]).to have_attributes(size: 1..5, first: Symbol)
|
# expect(%i[a b c]).to have_attributes(size: 1..5, first: Symbol)
|
||||||
# ```
|
# ```
|
||||||
macro have_attributes(**expected)
|
macro have_attributes(**expected)
|
||||||
|
{% if expected.id.starts_with?("{**") %}
|
||||||
|
%test_value = ::Spectator::TestValue.new({{expected.id[3...-1]}}, {{expected.double_splat.stringify}})
|
||||||
|
::Spectator::Matchers::AttributesMatcher.new(%test_value)
|
||||||
|
{% else %}
|
||||||
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.double_splat.stringify}})
|
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.double_splat.stringify}})
|
||||||
::Spectator::Matchers::AttributesMatcher.new(%test_value)
|
::Spectator::Matchers::AttributesMatcher.new(%test_value)
|
||||||
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Verifies that all elements of a collection satisfy some matcher.
|
# Verifies that all elements of a collection satisfy some matcher.
|
||||||
|
|
Loading…
Reference in a new issue