matchi 2.4.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative File.join("..", "base")
4
-
5
- module Matchi
6
- module Matcher
7
- class Change
8
- # *Change to* matcher.
9
- class To < ::Matchi::Matcher::Base
10
- # Returns a symbol identifying the matcher.
11
- def self.to_sym
12
- :change
13
- end
14
-
15
- # Initialize the matcher with an object.
16
- #
17
- # @example The change to "FOO" matcher.
18
- # object = "foo"
19
- # Matchi::Matcher::Change::To.new("FOO") { object.to_s }
20
- #
21
- # @param expected [#object_id] An expected result value.
22
- # @param state [Proc] A block of code to execute to get the
23
- # state of the object.
24
- def initialize(expected, &state)
25
- super()
26
- @expected = expected
27
- @state = state
28
- end
29
-
30
- # Boolean comparison on the expected change by comparing the value
31
- # before and after the code execution.
32
- #
33
- # @example
34
- # object = "foo"
35
- # change = Matchi::Matcher::Change::To.new("FOO") { object.to_s }
36
- # change.matches? { object.upcase! } # => true
37
- #
38
- # @yieldreturn [#object_id] The block of code to execute.
39
- #
40
- # @return [Boolean] Comparison between the value before and after the
41
- # code execution.
42
- def matches?(*, **)
43
- yield
44
- value_after = @state.call
45
-
46
- expected == value_after
47
- end
48
-
49
- # (see Base#to_s)
50
- def to_s
51
- "change to #{expected.inspect}"
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
- module Matchi
6
- module Matcher
7
- # *Equivalence* matcher.
8
- class Eql < ::Matchi::Matcher::Base
9
- # Initialize the matcher with an object.
10
- #
11
- # @example The string "foo" matcher.
12
- # Matchi::Matcher::Eql.new("foo")
13
- #
14
- # @param expected [#eql?] An expected equivalent 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 equivalent to "foo"?
23
- # eql = Matchi::Matcher::Eql.new("foo")
24
- # eql.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.eql?(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
- # *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