wildcard_matchers 0.3.1 → 0.4.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: 9f0029733e952a19949334e821540bcd02666e63
4
- data.tar.gz: 8129970e9554d6d724891529d1dda6712fe2bfa1
3
+ metadata.gz: dd4ca93bea9915e3384d715ec82062abadd7fbef
4
+ data.tar.gz: f6b60be0f29d1c1780587510c826da705c03707c
5
5
  SHA512:
6
- metadata.gz: d35e104eef286b82162eb6363d38b3f91512ca504a44fecb712967a1b53d70d02d3333df3362e920f3f0841e85992610446d89c8e90dcc5548d36742a8f43766
7
- data.tar.gz: 0ed3f3e94e1ca35ba7087c3f06e8ecb56f29a19ccfb6c3de31b0b2b6e4d447f592fc43514d31a6dc0e62b697f5b526bc742216adc2fe959241f44bac6d1dd3c9
6
+ metadata.gz: 4630a91e0e0fc32b05436a5730e4153d25fff6b6059b7dc2b8cee24e41b9e873185f2db874c4faa3c0bb44c325aecd4fccb1080e8b3977dff8bdcc544dfc6022
7
+ data.tar.gz: b16a591a726765b83985d5cb86406b9e80b28e6d5fb8bc3a24f6b095ca08dda8bcfe69eba75962b58c70ad05246e2d6c61f592f086335a16a77a75d0da994572
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+ * ENHANCEMENT
3
+ * add any_of and all_of helper
4
+
1
5
  ## 0.3.1
2
6
 
3
7
  * IMPROVEMENT
data/README.md CHANGED
@@ -49,6 +49,12 @@ See specs, for more detail.
49
49
  * nil_or
50
50
  * nil_or(is_a_string) === nil #=> true
51
51
  * nil_or(is_a_string) === "a" #=> true
52
+ * any_of
53
+ * any_of(String, /b/) === "a" #=> true
54
+ * any_of(Integer, /b/) === "a" #=> false
55
+ * all_of
56
+ * all_of(String, /a/) === "a" #=> true
57
+ * all_of(String, /b/) === "a" #=> false
52
58
  * for_all
53
59
  * for_all(is_a_string) === %w[ a b c ] #=> true
54
60
  * for_any
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
@@ -0,0 +1,18 @@
1
+ module WildcardMatchers
2
+ module Helpers
3
+ define_wildcard_helper(:all_of)
4
+
5
+ class AllOf < ::WildcardMatchers::WildcardMatcher
6
+ protected
7
+ def wildcard_match(actual)
8
+ errors = expectation.map do |e|
9
+ self.class.superclass.check_errors(actual, e)
10
+ end.flatten
11
+
12
+ unless errors.empty?
13
+ @errors = errors
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module WildcardMatchers
2
+ module Helpers
3
+ define_wildcard_helper(:any_of)
4
+
5
+ class AnyOf < ::WildcardMatchers::WildcardMatcher
6
+ protected
7
+ def wildcard_match(actual)
8
+ errors = expectation.map do |e|
9
+ self.class.superclass.check_errors(actual, e)
10
+ end
11
+
12
+ unless errors.any? {|e| e == [] }
13
+ @errors = errors.flatten
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -12,6 +12,8 @@ module WildcardMatchers
12
12
  end
13
13
  end
14
14
 
15
+ require "wildcard_matchers/helpers/any_of"
16
+ require "wildcard_matchers/helpers/all_of"
15
17
  require "wildcard_matchers/helpers/for_any"
16
18
  require "wildcard_matchers/helpers/for_all"
17
19
  require "wildcard_matchers/helpers/nil_or"
@@ -44,3 +44,24 @@ shared_examples_for "wildcard match with helper" do |actual, helper, matcher, *a
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ shared_examples_for "not wildcard match with helper" do |actual, helper, matcher, *args|
49
+ matcher_string =if matcher.is_a?(Symbol) and WildcardMatchers.respond_to?(matcher)
50
+ matcher.to_s
51
+ else
52
+ matcher.inspect
53
+ end
54
+
55
+ expected = helper.to_s + "(" + (args.size > 0 ?
56
+ "(#{matcher_string}(#{args.map(&:inspect).join(",")})" :
57
+ matcher_string) + ")"
58
+
59
+ it "#{actual.inspect} with #{expected}" do
60
+ if matcher.is_a?(Symbol) and WildcardMatchers.respond_to?(matcher)
61
+ # Note: some symbol comes here and may fail
62
+ expect(wildcard_match?(actual, send(helper, send(matcher, *args)), &debugger)).to be false
63
+ else
64
+ expect(wildcard_match?(actual, send(helper, matcher), &debugger)).to be false
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe WildcardMatchers::Helpers::AllOf do
4
+ [ [ "a", :all_of, [ String, /a/ ] ],
5
+ ].each do |actual, helper, matcher, *args|
6
+ it_behaves_like "wildcard match with helper", actual, helper, matcher, *args
7
+ end
8
+
9
+ [ [ "a", :all_of, [ Integer, /a/ ] ],
10
+ [ "a", :all_of, [ String, /b/ ] ],
11
+ [ "a", :all_of, [ Integer, /b/ ] ],
12
+ ].each do |actual, helper, matcher, *args|
13
+ it_behaves_like "not wildcard match with helper", actual, helper, matcher, *args
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe WildcardMatchers::Helpers::AnyOf do
4
+ [ [ "a", :any_of, [ String, /b/ ] ],
5
+ [ "a", :any_of, [ Integer, /a/ ] ],
6
+ [ "a", :any_of, [ String, /a/ ] ],
7
+ ].each do |actual, helper, matcher, *args|
8
+ it_behaves_like "wildcard match with helper", actual, helper, matcher, *args
9
+ end
10
+
11
+ [ [ "a", :any_of, [ Integer, /b/ ] ],
12
+ ].each do |actual, helper, matcher, *args|
13
+ it_behaves_like "not wildcard match with helper", actual, helper, matcher, *args
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wildcard_matchers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - okitan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-11 00:00:00.000000000 Z
11
+ date: 2016-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: facets
@@ -141,6 +141,8 @@ files:
141
141
  - VERSION
142
142
  - lib/wildcard_matchers.rb
143
143
  - lib/wildcard_matchers/helpers.rb
144
+ - lib/wildcard_matchers/helpers/all_of.rb
145
+ - lib/wildcard_matchers/helpers/any_of.rb
144
146
  - lib/wildcard_matchers/helpers/for_all.rb
145
147
  - lib/wildcard_matchers/helpers/for_any.rb
146
148
  - lib/wildcard_matchers/helpers/nil_or.rb
@@ -155,6 +157,8 @@ files:
155
157
  - spec/spec.watchr
156
158
  - spec/spec_helper.rb
157
159
  - spec/support/shared_examples.rb
160
+ - spec/wildcard_matchers/helpers/all_of_spec.rb
161
+ - spec/wildcard_matchers/helpers/any_of_spec.rb
158
162
  - spec/wildcard_matchers/helpers/for_all_spec.rb
159
163
  - spec/wildcard_matchers/helpers/for_any_spec.rb
160
164
  - spec/wildcard_matchers/helpers/nil_or_spec.rb
@@ -195,6 +199,8 @@ test_files:
195
199
  - spec/spec.watchr
196
200
  - spec/spec_helper.rb
197
201
  - spec/support/shared_examples.rb
202
+ - spec/wildcard_matchers/helpers/all_of_spec.rb
203
+ - spec/wildcard_matchers/helpers/any_of_spec.rb
198
204
  - spec/wildcard_matchers/helpers/for_all_spec.rb
199
205
  - spec/wildcard_matchers/helpers/for_any_spec.rb
200
206
  - spec/wildcard_matchers/helpers/nil_or_spec.rb