matchi 2.2.1 → 3.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.
- checksums.yaml +4 -4
- data/README.md +69 -74
- data/lib/matchi.rb +4 -2
- data/lib/matchi/be.rb +44 -0
- data/lib/matchi/be_an_instance_of.rb +44 -0
- data/lib/matchi/change.rb +109 -0
- data/lib/matchi/change/by.rb +58 -0
- data/lib/matchi/change/by_at_least.rb +58 -0
- data/lib/matchi/change/by_at_most.rb +58 -0
- data/lib/matchi/change/from.rb +44 -0
- data/lib/matchi/change/from/to.rb +64 -0
- data/lib/matchi/change/to.rb +57 -0
- data/lib/matchi/eq.rb +44 -0
- data/lib/matchi/match.rb +44 -0
- data/lib/matchi/raise_exception.rb +48 -0
- data/lib/matchi/satisfy.rb +44 -0
- metadata +17 -15
- data/lib/matchi/helper.rb +0 -40
- data/lib/matchi/matcher.rb +0 -11
- data/lib/matchi/matcher/base.rb +0 -63
- data/lib/matchi/matcher/be_an_instance_of.rb +0 -51
- data/lib/matchi/matcher/be_false.rb +0 -24
- data/lib/matchi/matcher/be_nil.rb +0 -24
- data/lib/matchi/matcher/be_true.rb +0 -24
- data/lib/matchi/matcher/eql.rb +0 -35
- data/lib/matchi/matcher/equal.rb +0 -35
- data/lib/matchi/matcher/match.rb +0 -35
- data/lib/matchi/matcher/raise_exception.rb +0 -39
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Matchi
|
|
4
|
+
# *Satisfy* matcher.
|
|
5
|
+
class Satisfy
|
|
6
|
+
# Initialize the matcher with a block.
|
|
7
|
+
#
|
|
8
|
+
# @example
|
|
9
|
+
# require "matchi/satisfy"
|
|
10
|
+
#
|
|
11
|
+
# Matchi::Satisfy.new { |value| value == 42 }
|
|
12
|
+
#
|
|
13
|
+
# @param block [Proc] A block of code.
|
|
14
|
+
def initialize(&block)
|
|
15
|
+
@expected = block
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Boolean comparison between the actual value and the expected value.
|
|
19
|
+
#
|
|
20
|
+
# @example
|
|
21
|
+
# require "matchi/satisfy"
|
|
22
|
+
#
|
|
23
|
+
# matcher = Matchi::Satisfy.new { |value| value == 42 }
|
|
24
|
+
# matcher.matches? { 42 } # => 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.call(yield)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# A string containing a human-readable representation of the matcher.
|
|
35
|
+
def inspect
|
|
36
|
+
"#{self.class}(&block)"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Returns a string representing the matcher.
|
|
40
|
+
def to_s
|
|
41
|
+
"satisfy &block"
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matchi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Cyril Kato
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-07-
|
|
11
|
+
date: 2021-07-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -122,7 +122,7 @@ dependencies:
|
|
|
122
122
|
- - ">="
|
|
123
123
|
- !ruby/object:Gem::Version
|
|
124
124
|
version: '0'
|
|
125
|
-
description: "Collection of expectation matchers for
|
|
125
|
+
description: "Collection of expectation matchers for Rubyists \U0001F939"
|
|
126
126
|
email: contact@cyril.email
|
|
127
127
|
executables: []
|
|
128
128
|
extensions: []
|
|
@@ -131,17 +131,19 @@ files:
|
|
|
131
131
|
- LICENSE.md
|
|
132
132
|
- README.md
|
|
133
133
|
- lib/matchi.rb
|
|
134
|
-
- lib/matchi/
|
|
135
|
-
- lib/matchi/
|
|
136
|
-
- lib/matchi/
|
|
137
|
-
- lib/matchi/
|
|
138
|
-
- lib/matchi/
|
|
139
|
-
- lib/matchi/
|
|
140
|
-
- lib/matchi/
|
|
141
|
-
- lib/matchi/
|
|
142
|
-
- lib/matchi/
|
|
143
|
-
- lib/matchi/
|
|
144
|
-
- lib/matchi/
|
|
134
|
+
- lib/matchi/be.rb
|
|
135
|
+
- lib/matchi/be_an_instance_of.rb
|
|
136
|
+
- lib/matchi/change.rb
|
|
137
|
+
- lib/matchi/change/by.rb
|
|
138
|
+
- lib/matchi/change/by_at_least.rb
|
|
139
|
+
- lib/matchi/change/by_at_most.rb
|
|
140
|
+
- lib/matchi/change/from.rb
|
|
141
|
+
- lib/matchi/change/from/to.rb
|
|
142
|
+
- lib/matchi/change/to.rb
|
|
143
|
+
- lib/matchi/eq.rb
|
|
144
|
+
- lib/matchi/match.rb
|
|
145
|
+
- lib/matchi/raise_exception.rb
|
|
146
|
+
- lib/matchi/satisfy.rb
|
|
145
147
|
homepage: https://github.com/fixrb/matchi
|
|
146
148
|
licenses:
|
|
147
149
|
- MIT
|
|
@@ -164,5 +166,5 @@ requirements: []
|
|
|
164
166
|
rubygems_version: 3.1.6
|
|
165
167
|
signing_key:
|
|
166
168
|
specification_version: 4
|
|
167
|
-
summary: "Collection of expectation matchers for
|
|
169
|
+
summary: "Collection of expectation matchers for Rubyists \U0001F939"
|
|
168
170
|
test_files: []
|
data/lib/matchi/helper.rb
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "matcher"
|
|
4
|
-
|
|
5
|
-
module Matchi
|
|
6
|
-
# When included, this module defines a helper instance method per matcher.
|
|
7
|
-
#
|
|
8
|
-
# @example Define and use the dynamic helper instance method of a custom matcher
|
|
9
|
-
# require "matchi/matcher/base"
|
|
10
|
-
#
|
|
11
|
-
# module Matchi
|
|
12
|
-
# module Matcher
|
|
13
|
-
# class BeTheAnswer < ::Matchi::Matcher::Base
|
|
14
|
-
# def matches?
|
|
15
|
-
# 42.equal?(yield)
|
|
16
|
-
# end
|
|
17
|
-
# end
|
|
18
|
-
# end
|
|
19
|
-
# end
|
|
20
|
-
#
|
|
21
|
-
# require "matchi/helper"
|
|
22
|
-
#
|
|
23
|
-
# class MatcherBase
|
|
24
|
-
# include ::Matchi::Helper
|
|
25
|
-
# end
|
|
26
|
-
#
|
|
27
|
-
# matcher_base = MatcherBase.new
|
|
28
|
-
# matcher_base.be_the_answer.matches? { 42 } # => true
|
|
29
|
-
module Helper
|
|
30
|
-
::Matchi::Matcher.constants.each do |matcher_const|
|
|
31
|
-
next if matcher_const.equal?(:Base)
|
|
32
|
-
|
|
33
|
-
matcher_klass = ::Matchi::Matcher.const_get(matcher_const)
|
|
34
|
-
|
|
35
|
-
define_method(matcher_klass.to_sym) do |*args|
|
|
36
|
-
matcher_klass.new(*args)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
data/lib/matchi/matcher.rb
DELETED
data/lib/matchi/matcher/base.rb
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Matchi
|
|
4
|
-
module Matcher
|
|
5
|
-
# Abstract matcher class.
|
|
6
|
-
class Base
|
|
7
|
-
# Returns a symbol identifying the matcher.
|
|
8
|
-
#
|
|
9
|
-
# @example The readable definition of a FooBar matcher class.
|
|
10
|
-
# matcher_class = Matchi::Matcher::FooBar
|
|
11
|
-
# matcher_class.to_sym # => "foo_bar"
|
|
12
|
-
#
|
|
13
|
-
# @return [Symbol] A symbol identifying the matcher.
|
|
14
|
-
def self.to_sym
|
|
15
|
-
name.split("::")
|
|
16
|
-
.fetch(-1)
|
|
17
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
18
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
19
|
-
.downcase
|
|
20
|
-
.to_sym
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# @return [#object_id] Any value to give to the matcher.
|
|
24
|
-
attr_reader :expected
|
|
25
|
-
|
|
26
|
-
# A string containing a human-readable representation of the matcher.
|
|
27
|
-
#
|
|
28
|
-
# @example The human-readable representation of a FooBar matcher instance.
|
|
29
|
-
# matcher = Matchi::Matcher::FooBar.new(42)
|
|
30
|
-
# matcher.inspect # => "Matchi::Matcher::FooBar(42)"
|
|
31
|
-
#
|
|
32
|
-
# @return [String] The human-readable representation of the matcher.
|
|
33
|
-
def inspect
|
|
34
|
-
"#{self.class}(#{expected&.inspect})"
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# Abstract matcher class.
|
|
38
|
-
#
|
|
39
|
-
# @example Test the equivalence between two "foo" strings.
|
|
40
|
-
# eql = Matchi::Matcher::Eql.new("foo")
|
|
41
|
-
# eql.matches? { "foo" } # => true
|
|
42
|
-
#
|
|
43
|
-
# @yieldreturn [#object_id] The actual value to compare to the expected
|
|
44
|
-
# one.
|
|
45
|
-
#
|
|
46
|
-
# @raise [NotImplementedError] Override this method inside a matcher.
|
|
47
|
-
def matches?
|
|
48
|
-
raise ::NotImplementedError, "matcher MUST respond to this method."
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Returns a string representing the matcher instance.
|
|
52
|
-
#
|
|
53
|
-
# @example The readable definition of a FooBar matcher instance.
|
|
54
|
-
# matcher = Matchi::Matcher::FooBar.new(42)
|
|
55
|
-
# matcher.to_s # => "foo_bar 42"
|
|
56
|
-
#
|
|
57
|
-
# @return [String] A string representing the matcher instance.
|
|
58
|
-
def to_s
|
|
59
|
-
[self.class.to_sym, expected&.inspect].compact.join(" ")
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
|
|
5
|
-
module Matchi
|
|
6
|
-
module Matcher
|
|
7
|
-
# *Type/class* matcher.
|
|
8
|
-
class BeAnInstanceOf < ::Matchi::Matcher::Base
|
|
9
|
-
# Initialize the matcher with an object.
|
|
10
|
-
#
|
|
11
|
-
# @example A duck matcher
|
|
12
|
-
# Matchi::Matcher::BeAnInstanceOf.new(:Duck)
|
|
13
|
-
#
|
|
14
|
-
# @param expected [#to_s] The name of a module.
|
|
15
|
-
def initialize(expected)
|
|
16
|
-
super()
|
|
17
|
-
@expected = String(expected).to_sym
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# (see Base#inspect)
|
|
21
|
-
def inspect
|
|
22
|
-
"#{self.class}(#{expected})"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Boolean comparison between the class of the actual value and the
|
|
26
|
-
# expected class.
|
|
27
|
-
#
|
|
28
|
-
# @example Is it an instance of string?
|
|
29
|
-
# be_an_instance_of = Matchi::Matcher::BeInstanceOf.new(String)
|
|
30
|
-
# be_an_instance_of.matches? { "foo" } # => true
|
|
31
|
-
#
|
|
32
|
-
# be_an_instance_of = Matchi::Matcher::BeInstanceOf.new(:String)
|
|
33
|
-
# be_an_instance_of.matches? { "foo" } # => true
|
|
34
|
-
#
|
|
35
|
-
# be_an_instance_of = Matchi::Matcher::BeInstanceOf.new("String")
|
|
36
|
-
# be_an_instance_of.matches? { "foo" } # => true
|
|
37
|
-
#
|
|
38
|
-
# @yieldreturn [#class] the actual value to compare to the expected one.
|
|
39
|
-
#
|
|
40
|
-
# @return [Boolean] Comparison between actual and expected values.
|
|
41
|
-
def matches?(*, **)
|
|
42
|
-
self.class.const_get(expected).equal?(yield.class)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# (see Base#to_s)
|
|
46
|
-
def to_s
|
|
47
|
-
"#{self.class.to_sym} #{expected}"
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
|
|
5
|
-
module Matchi
|
|
6
|
-
module Matcher
|
|
7
|
-
# *Untruth* matcher.
|
|
8
|
-
class BeFalse < ::Matchi::Matcher::Base
|
|
9
|
-
# Boolean comparison between the actual value and the expected value.
|
|
10
|
-
#
|
|
11
|
-
# @example Is it false?
|
|
12
|
-
# be_false = Matchi::Matcher::BeFalse.new
|
|
13
|
-
# be_false.matches? { false } # => true
|
|
14
|
-
#
|
|
15
|
-
# @yieldreturn [#object_id] The actual value to compare to the expected
|
|
16
|
-
# one.
|
|
17
|
-
#
|
|
18
|
-
# @return [Boolean] Comparison between actual and expected values.
|
|
19
|
-
def matches?(*, **)
|
|
20
|
-
false.equal?(yield)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
|
|
5
|
-
module Matchi
|
|
6
|
-
module Matcher
|
|
7
|
-
# *Nil* matcher.
|
|
8
|
-
class BeNil < ::Matchi::Matcher::Base
|
|
9
|
-
# Boolean comparison between the actual value and the expected value.
|
|
10
|
-
#
|
|
11
|
-
# @example Is it nil?
|
|
12
|
-
# be_nil = Matchi::Matcher::BeNil.new
|
|
13
|
-
# be_nil.matches? { nil } # => true
|
|
14
|
-
#
|
|
15
|
-
# @yieldreturn [#object_id] The actual value to compare to the expected
|
|
16
|
-
# one.
|
|
17
|
-
#
|
|
18
|
-
# @return [Boolean] Comparison between actual and expected values.
|
|
19
|
-
def matches?(*, **)
|
|
20
|
-
nil.equal?(yield)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "base"
|
|
4
|
-
|
|
5
|
-
module Matchi
|
|
6
|
-
module Matcher
|
|
7
|
-
# *Truth* matcher.
|
|
8
|
-
class BeTrue < ::Matchi::Matcher::Base
|
|
9
|
-
# Boolean comparison between the actual value and the expected value.
|
|
10
|
-
#
|
|
11
|
-
# @example Is it true?
|
|
12
|
-
# be_true = Matchi::Matcher::BeTrue.new
|
|
13
|
-
# be_true.matches? { true } # => true
|
|
14
|
-
#
|
|
15
|
-
# @yieldreturn [#object_id] The actual value to compare to the expected
|
|
16
|
-
# one.
|
|
17
|
-
#
|
|
18
|
-
# @return [Boolean] Comparison between actual and expected values.
|
|
19
|
-
def matches?(*, **)
|
|
20
|
-
true.equal?(yield)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
data/lib/matchi/matcher/eql.rb
DELETED
|
@@ -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
|
data/lib/matchi/matcher/equal.rb
DELETED
|
@@ -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
|
data/lib/matchi/matcher/match.rb
DELETED
|
@@ -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
|