matchi 2.3.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module Matchi
6
- module Matcher
7
- # *Identity* matcher.
8
- class Equal < ::Matchi::Matcher::Base
9
- # Initialize the matcher with an object.
10
- #
11
- # @example The number 42 matcher.
12
- # Matchi::Matcher::Equal.new(42)
13
- #
14
- # @param expected [#equal?] An expected object.
15
- def initialize(expected)
16
- super()
17
- @expected = expected
18
- end
19
-
20
- # Boolean comparison between the actual value and the expected value.
21
- #
22
- # @example Is it equal to :foo?
23
- # equal = Matchi::Matcher::Equal.new(:foo)
24
- # equal.matches? { :foo } # => true
25
- #
26
- # @yieldreturn [#object_id] The actual value to compare to the expected
27
- # one.
28
- #
29
- # @return [Boolean] Comparison between actual and expected values.
30
- def matches?(*, **)
31
- expected.equal?(yield)
32
- end
33
- end
34
- end
35
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module Matchi
6
- module Matcher
7
- # *Regular expressions* matcher.
8
- class Match < ::Matchi::Matcher::Base
9
- # Initialize the matcher with an instance of Regexp.
10
- #
11
- # @example Username matcher.
12
- # Matchi::Matcher::Match.new(/^[a-z0-9_-]{3,16}$/)
13
- #
14
- # @param expected [#match] A regular expression.
15
- def initialize(expected)
16
- super()
17
- @expected = expected
18
- end
19
-
20
- # Boolean comparison between the actual value and the expected value.
21
- #
22
- # @example Is it matching /^foo$/ regex?
23
- # match = Matchi::Matcher::Match.new(/^foo$/)
24
- # match.matches? { "foo" } # => true
25
- #
26
- # @yieldreturn [#object_id] The actual value to compare to the expected
27
- # one.
28
- #
29
- # @return [Boolean] Comparison between actual and expected values.
30
- def matches?(*, **)
31
- expected.match?(yield)
32
- end
33
- end
34
- end
35
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module Matchi
6
- module Matcher
7
- # *Expecting errors* matcher.
8
- class RaiseException < ::Matchi::Matcher::Base
9
- # Initialize the matcher with a descendant of class Exception.
10
- #
11
- # @example Divided by 0 matcher.
12
- # Matchi::Matcher::RaiseException.new(ZeroDivisionError)
13
- #
14
- # @param expected [Exception] The class of the expected exception.
15
- def initialize(expected)
16
- super()
17
- @expected = expected
18
- end
19
-
20
- # Boolean comparison between the actual value and the expected value.
21
- #
22
- # @example Is it raising NameError?
23
- # matcher = Matchi::Matcher::RaiseException.new(NameError)
24
- # matcher.matches? { Boom } # => true
25
- #
26
- # @yieldreturn [#object_id] The actual value to compare to the expected
27
- # one.
28
- #
29
- # @return [Boolean] Comparison between actual and expected values.
30
- def matches?(*, **)
31
- yield
32
- rescue expected => _e
33
- true
34
- else
35
- false
36
- end
37
- end
38
- end
39
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module Matchi
6
- module Matcher
7
- # *Satisfy* matcher.
8
- class Satisfy < ::Matchi::Matcher::Base
9
- # Initialize the matcher with a block.
10
- #
11
- # @example The number 42 matcher.
12
- # Matchi::Matcher::Satisfy.new { |value| value == 42 }
13
- #
14
- # @param block [Proc] A block of code.
15
- def initialize(&block)
16
- super()
17
- @expected = block
18
- end
19
-
20
- # (see Base#inspect)
21
- def inspect
22
- "#{self.class}(&block)"
23
- end
24
-
25
- # Boolean comparison between the actual value and the expected value.
26
- #
27
- # @example Is it equal to 42
28
- # equal = Matchi::Matcher::Satisfy.new { |value| value == 42 }
29
- # equal.matches? { 42 } # => true
30
- #
31
- # @yieldreturn [#object_id] The actual value to compare to the expected
32
- # one.
33
- #
34
- # @return [Boolean] Comparison between actual and expected values.
35
- def matches?(*, **)
36
- expected.call(yield)
37
- end
38
-
39
- # (see Base#to_s)
40
- def to_s
41
- "#{self.class.to_sym} &block"
42
- end
43
- end
44
- end
45
- end