wildcard_matchers 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd4ca93bea9915e3384d715ec82062abadd7fbef
4
- data.tar.gz: f6b60be0f29d1c1780587510c826da705c03707c
3
+ metadata.gz: 505f14ca6ec4c6425c12be433c23de1833b7bb25
4
+ data.tar.gz: 85a7da4a4bb5703dd721ffeff73c977bc9f7cc3f
5
5
  SHA512:
6
- metadata.gz: 4630a91e0e0fc32b05436a5730e4153d25fff6b6059b7dc2b8cee24e41b9e873185f2db874c4faa3c0bb44c325aecd4fccb1080e8b3977dff8bdcc544dfc6022
7
- data.tar.gz: b16a591a726765b83985d5cb86406b9e80b28e6d5fb8bc3a24f6b095ca08dda8bcfe69eba75962b58c70ad05246e2d6c61f592f086335a16a77a75d0da994572
6
+ metadata.gz: cf5f6f22000d88c77f55591d5dd76e6bed1258c29695180cb78e5c94150ad354908d9a1085534348749f2515c0f6c508fcdea62c0d84f06d7e0fd6e367ba81af
7
+ data.tar.gz: 9444ae631b08f452de853539e0a16ed0a795d4132dfdcac713ce798bc29b5a606c5cd45d5e979a8eaed6b1e38440e7c2dc17ea71b0fdb4cc77d9c4397eecf930
@@ -1,3 +1,7 @@
1
+ ## 0.9.0
2
+ * ENHANCEMEN
3
+ * support & and | to composite matcher
4
+
1
5
  ## 0.4.0
2
6
  * ENHANCEMENT
3
7
  * add any_of and all_of helper
data/README.md CHANGED
@@ -62,6 +62,13 @@ See specs, for more detail.
62
62
  * responding
63
63
  * responding(next: 2) === 1 #=> true (because 1.next #=> 2)
64
64
 
65
+ ### composite matchers
66
+
67
+ * using &
68
+ * for_all(is_a_string) & for_any(/hoge/) # every element is String and one matched /hoge/
69
+ * using |
70
+ * for_all(is_a_string) | for_all(is_a_integer) # every element is String or Integer
71
+
65
72
  ## How it works
66
73
 
67
74
  It is very simple. Recursive match using ===, and Class, Range, and Proc act as wildcard matchers.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.9.0
@@ -3,6 +3,11 @@ module WildcardMatchers
3
3
  define_wildcard_helper(:all_of)
4
4
 
5
5
  class AllOf < ::WildcardMatchers::WildcardMatcher
6
+ def &(matcher)
7
+ expectation.push(matcher)
8
+ self
9
+ end
10
+
6
11
  protected
7
12
  def wildcard_match(actual)
8
13
  errors = expectation.map do |e|
@@ -3,6 +3,11 @@ module WildcardMatchers
3
3
  define_wildcard_helper(:any_of)
4
4
 
5
5
  class AnyOf < ::WildcardMatchers::WildcardMatcher
6
+ def |(matcher)
7
+ expectation.push(matcher)
8
+ self
9
+ end
10
+
6
11
  protected
7
12
  def wildcard_match(actual)
8
13
  errors = expectation.map do |e|
@@ -8,6 +8,14 @@ module WildcardMatchers
8
8
  @position = position
9
9
  end
10
10
 
11
+ def &(matcher)
12
+ WildcardMatchers::Helpers::AllOf.new([self, matcher])
13
+ end
14
+
15
+ def |(matcher)
16
+ WildcardMatchers::Helpers::AnyOf.new([self, matcher])
17
+ end
18
+
11
19
  def ===(actual)
12
20
  @errors = []
13
21
  wildcard_match_with_catch_exception(actual)
@@ -46,4 +46,54 @@ describe WildcardMatchers::Matchers do
46
46
  ].each do |actual, matcher, *args|
47
47
  it_behaves_like "not wildcard match", actual, matcher, *args
48
48
  end
49
+
50
+ context "composing matchers" do
51
+ context "with &" do
52
+ include WildcardMatchers
53
+
54
+ it "works" do
55
+ matcher = responding(size: 2) & /a/ & /b/
56
+ expect(wildcard_match?("ab", matcher, &debugger)).to be true
57
+ end
58
+
59
+ it "shows every erro4" do
60
+ matcher = responding(size: 2) & /a/ & /b/
61
+ expect(wildcard_match?("c", matcher, &debugger)).to be false
62
+ end
63
+
64
+ it "returns error just one mismatch" do
65
+ matcher = responding(size: 1) & /a/ & /b/
66
+ expect(wildcard_match?("a", matcher, &debugger)).to be false
67
+ end
68
+
69
+ it "is also available for all_of" do
70
+ matcher = all_of([String, /a/]) & /b/
71
+ expect(wildcard_match?("a", matcher, &debugger)).to be false
72
+ end
73
+ end
74
+
75
+ context "with |" do
76
+ include WildcardMatchers
77
+
78
+ it "works" do
79
+ matcher = responding(size: 2) | /a/ | /b/
80
+ expect(wildcard_match?("a", matcher, &debugger)).to be true
81
+ end
82
+
83
+ it "shows every error" do
84
+ matcher = responding(size: 2) | /a/ | /b/
85
+ expect(wildcard_match?("c", matcher, &debugger)).to be false
86
+ end
87
+
88
+ it "is also available for any_of" do
89
+ matcher = any_of([Integer, /a/]) | /b/
90
+ expect(wildcard_match?("b", matcher, &debugger)).to be true
91
+ end
92
+
93
+ it "is also available for any_of" do
94
+ matcher = any_of([Integer, /b/]) | /a/
95
+ expect(wildcard_match?("b", matcher, &debugger)).to be true
96
+ end
97
+ end
98
+ end
49
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wildcard_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan