matchi 4.1.1 → 5.0.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,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Matchi
4
- class Change
5
- # *Change by at least* matcher.
6
- class ByAtLeast
7
- # Initialize the matcher with an object and a block.
8
- #
9
- # @example
10
- # require "matchi/change/by_at_least"
11
- #
12
- # object = []
13
- #
14
- # Matchi::Change::ByAtLeast.new(1) { object.length }
15
- #
16
- # @param expected [#object_id] An expected delta.
17
- # @param state [Proc] A block of code to execute to get the
18
- # state of the object.
19
- def initialize(expected, &state)
20
- raise ::ArgumentError, "expected must be a Numeric" unless expected.is_a?(::Numeric)
21
- raise ::ArgumentError, "a block must be provided" unless block_given?
22
- raise ::ArgumentError, "expected must be non-negative" if expected.negative?
23
-
24
- @expected = expected
25
- @state = state
26
- end
27
-
28
- # Boolean comparison on the expected change by comparing the value
29
- # before and after the code execution.
30
- #
31
- # @example
32
- # require "matchi/change/by_at_least"
33
- #
34
- # object = []
35
- #
36
- # matcher = Matchi::Change::ByAtLeast.new(1) { object.length }
37
- # matcher.match? { object << "foo" } # => true
38
- #
39
- # @yieldreturn [#object_id] The block of code to execute.
40
- #
41
- # @return [Boolean] Comparison between the value before and after the
42
- # code execution.
43
- def match?
44
- raise ::ArgumentError, "a block must be provided" unless block_given?
45
-
46
- value_before = @state.call
47
- yield
48
- value_after = @state.call
49
-
50
- @expected <= (value_after - value_before)
51
- end
52
-
53
- # Returns a string representing the matcher.
54
- #
55
- # @return [String] a human-readable description of the matcher
56
- def to_s
57
- "change by at least #{@expected.inspect}"
58
- end
59
- end
60
- end
61
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Matchi
4
- class Change
5
- # *Change by at most* matcher.
6
- class ByAtMost
7
- # Initialize the matcher with an object and a block.
8
- #
9
- # @example
10
- # require "matchi/change/by_at_most"
11
- #
12
- # object = []
13
- #
14
- # Matchi::Change::ByAtMost.new(1) { object.length }
15
- #
16
- # @param expected [#object_id] An expected delta.
17
- # @param state [Proc] A block of code to execute to get the
18
- # state of the object.
19
- def initialize(expected, &state)
20
- raise ::ArgumentError, "expected must be a Numeric" unless expected.is_a?(::Numeric)
21
- raise ::ArgumentError, "a block must be provided" unless block_given?
22
- raise ::ArgumentError, "expected must be non-negative" if expected.negative?
23
-
24
- @expected = expected
25
- @state = state
26
- end
27
-
28
- # Boolean comparison on the expected change by comparing the value
29
- # before and after the code execution.
30
- #
31
- # @example
32
- # require "matchi/change/by_at_most"
33
- #
34
- # object = []
35
- #
36
- # matcher = Matchi::Change::ByAtMost.new(1) { object.length }
37
- # matcher.match? { object << "foo" } # => true
38
- #
39
- # @yieldreturn [#object_id] The block of code to execute.
40
- #
41
- # @return [Boolean] Comparison between the value before and after the
42
- # code execution.
43
- def match?
44
- raise ::ArgumentError, "a block must be provided" unless block_given?
45
-
46
- value_before = @state.call
47
- yield
48
- value_after = @state.call
49
-
50
- @expected >= (value_after - value_before)
51
- end
52
-
53
- # Returns a string representing the matcher.
54
- #
55
- # @return [String] a human-readable description of the matcher
56
- def to_s
57
- "change by at most #{@expected.inspect}"
58
- end
59
- end
60
- end
61
- end
@@ -1,65 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Matchi
4
- class Change
5
- class From
6
- # *Change from to* matcher.
7
- class To
8
- # Initialize the matcher with two objects and a block.
9
- #
10
- # @example
11
- # require "matchi/change/from/to"
12
- #
13
- # object = "foo"
14
- #
15
- # Matchi::Change::From::To.new("foo", "FOO") { object.to_s }
16
- #
17
- # @param expected_init [#object_id] An expected initial value.
18
- # @param expected_new_value [#object_id] An expected new value.
19
- # @param state [Proc] A block of code to execute to
20
- # get the state of the object.
21
- def initialize(expected_init, expected_new_value, &state)
22
- raise ::ArgumentError, "a block must be provided" unless block_given?
23
-
24
- @expected_init = expected_init
25
- @expected = expected_new_value
26
- @state = state
27
- end
28
-
29
- # Boolean comparison on the expected change by comparing the value
30
- # before and after the code execution.
31
- #
32
- # @example
33
- # require "matchi/change/from/to"
34
- #
35
- # object = "foo"
36
- #
37
- # matcher = Matchi::Change::From::To.new("foo", "FOO") { object.to_s }
38
- # matcher.match? { object.upcase! } # => true
39
- #
40
- # @yieldreturn [#object_id] The block of code to execute.
41
- #
42
- # @return [Boolean] Comparison between the value before and after the
43
- # code execution.
44
- def match?
45
- raise ::ArgumentError, "a block must be provided" unless block_given?
46
-
47
- value_before = @state.call
48
- return false unless @expected_init == value_before
49
-
50
- yield
51
- value_after = @state.call
52
-
53
- @expected == value_after
54
- end
55
-
56
- # Returns a string representing the matcher.
57
- #
58
- # @return [String] a human-readable description of the matcher
59
- def to_s
60
- "change from #{@expected_init.inspect} to #{@expected.inspect}"
61
- end
62
- end
63
- end
64
- end
65
- end