From b7c686e836c31d0a54f2978642220959fed051f4 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 5 Jan 2020 22:49:27 -0700 Subject: [PATCH] Add `cover` matcher Works the same as `contain` but is for ranges. --- src/spectator/dsl/matchers.cr | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/spectator/dsl/matchers.cr b/src/spectator/dsl/matchers.cr index 784426a..2108a88 100644 --- a/src/spectator/dsl/matchers.cr +++ b/src/spectator/dsl/matchers.cr @@ -454,6 +454,27 @@ module Spectator ::Spectator::Matchers::ContainMatcher.new(%test_value) end + # Indicates that some range (or collection) should contain another value. + # This is typically used on a `Range` (although any `Enumerable` works). + # The `includes?` method is used. + # + # Examples: + # ``` + # expect(1..10).to contain(5) + # expect((1..)).to contain(100) + # expect(..100).to contain(50) + # ``` + # + # Additionally, multiple arguments can be specified. + # ``` + # expect(1..10).to contain(2, 3) + # expect(..100).to contain(0, 50) + # ``` + macro cover(*expected) + %test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}}) + ::Spectator::Matchers::ContainMatcher.new(%test_value) + end + # Indicates that some value or set should contain another value. # This is similar to `#contain`, but uses a different method for matching. # Typically a `String` or `Array` (any `Enumerable` works) is checked against.