matchi 4.1.1 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +148 -219
- data/lib/matchi/be.rb +58 -16
- data/lib/matchi/be_a_kind_of.rb +87 -34
- data/lib/matchi/be_an_instance_of.rb +74 -62
- data/lib/matchi/be_within.rb +125 -14
- data/lib/matchi/change/by.rb +99 -22
- data/lib/matchi/change/by_at_least.rb +118 -21
- data/lib/matchi/change/by_at_most.rb +132 -22
- data/lib/matchi/change/from/to.rb +92 -25
- data/lib/matchi/change/from.rb +31 -1
- data/lib/matchi/change/to.rb +72 -23
- data/lib/matchi/change.rb +119 -45
- data/lib/matchi/eq.rb +58 -16
- data/lib/matchi/match.rb +56 -16
- data/lib/matchi/predicate.rb +122 -33
- data/lib/matchi/raise_exception.rb +89 -22
- data/lib/matchi/satisfy.rb +87 -16
- data/lib/matchi.rb +51 -297
- metadata +12 -5
- data/lib/matchi/be_within/of.rb +0 -51
data/lib/matchi/be_within/of.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Matchi
|
4
|
-
class BeWithin
|
5
|
-
# *BeWithin of* matcher.
|
6
|
-
class Of
|
7
|
-
# Initialize the matcher with a delta and an expected value.
|
8
|
-
#
|
9
|
-
# @example
|
10
|
-
# require "matchi/be_within/of"
|
11
|
-
#
|
12
|
-
# Matchi::BeWithin::Of.new(1, 41)
|
13
|
-
#
|
14
|
-
# @param delta [Numeric] The accepted variation of the actual value.
|
15
|
-
# @param expected [Numeric] The expected value.
|
16
|
-
def initialize(delta, expected)
|
17
|
-
raise ::ArgumentError, "delta must be a Numeric" unless delta.is_a?(::Numeric)
|
18
|
-
raise ::ArgumentError, "expected must be a Numeric" unless expected.is_a?(::Numeric)
|
19
|
-
raise ::ArgumentError, "delta must be non-negative" if delta.negative?
|
20
|
-
|
21
|
-
@delta = delta
|
22
|
-
@expected = expected
|
23
|
-
end
|
24
|
-
|
25
|
-
# Boolean comparison on the expected be_within by comparing the actual
|
26
|
-
# value and the expected value.
|
27
|
-
#
|
28
|
-
# @example
|
29
|
-
# require "matchi/be_within/of"
|
30
|
-
#
|
31
|
-
# matcher = Matchi::BeWithin::Of.new(1, 41)
|
32
|
-
# matcher.match? { 42 } # => true
|
33
|
-
#
|
34
|
-
# @yieldreturn [Numeric] The block of code to execute.
|
35
|
-
#
|
36
|
-
# @return [Boolean] Comparison between the actual and the expected values.
|
37
|
-
def match?
|
38
|
-
raise ::ArgumentError, "a block must be provided" unless block_given?
|
39
|
-
|
40
|
-
(@expected - yield).abs <= @delta
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns a string representing the matcher.
|
44
|
-
#
|
45
|
-
# @return [String] a human-readable description of the matcher
|
46
|
-
def to_s
|
47
|
-
"be within #{@delta} of #{@expected}"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|