wildcard_matchers 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +4 -0
- data/VERSION +1 -1
- data/lib/wildcard_matchers/helpers/for_all.rb +1 -1
- data/lib/wildcard_matchers/helpers/for_any.rb +18 -0
- data/lib/wildcard_matchers/helpers/nil_or.rb +1 -1
- data/lib/wildcard_matchers/helpers.rb +1 -0
- data/lib/wildcard_matchers/matchers/is_uri.rb +29 -0
- data/lib/wildcard_matchers/matchers.rb +2 -1
- data/spec/wildcard_matchers/helpers/for_any_spec.rb +13 -0
- data/spec/wildcard_matchers/matchers/is_uri_spec.rb +28 -0
- data/wildcard_matchers.gemspec +3 -0
- metadata +25 -2
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,8 @@ See specs, for more detail.
|
|
28
28
|
* is_bool === object #=> false
|
29
29
|
* is_time
|
30
30
|
* is_time === "2012-05-13" #=> true
|
31
|
+
* is_url
|
32
|
+
* is_url(:host => "example.com") === "http://example.com" #=> true
|
31
33
|
* hash_includes
|
32
34
|
* hash_includes(:a) === { :a => 1 } #=> true
|
33
35
|
* hash_includes(:b) === { :a => 1 } #=> false
|
@@ -42,6 +44,8 @@ See specs, for more detail.
|
|
42
44
|
* nil_or(is_a_string) === "a" #=> true
|
43
45
|
* for_all
|
44
46
|
* for_all(is_a_string) === %w[ a b c ] #=> true
|
47
|
+
* for_any
|
48
|
+
* for_any(is_a_string) === [ 1, "1" ] #=> true
|
45
49
|
|
46
50
|
## How it works
|
47
51
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module WildcardMatchers
|
2
|
+
module Helpers
|
3
|
+
def for_any(expectation = nil, &block)
|
4
|
+
expectation = block_given? ? block : expectation
|
5
|
+
|
6
|
+
ForAny.new(expectation)
|
7
|
+
end
|
8
|
+
|
9
|
+
class ForAny < ::WildcardMatchers::WildcardMatcher
|
10
|
+
protected
|
11
|
+
def wildcard_match(actual)
|
12
|
+
unless actual.any? {|e| self.class.superclass.check_errors(e, expectation) == [] }
|
13
|
+
errors.push("expect #{actual} has #{expectation}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module WildcardMatchers
|
2
|
+
module Matchers
|
3
|
+
def is_uri(hash = {})
|
4
|
+
IsUri.new(hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
class IsUri < ::WildcardMatchers::WildcardMatcher
|
8
|
+
protected
|
9
|
+
def wildcard_match(actual)
|
10
|
+
uri = nil
|
11
|
+
begin
|
12
|
+
require "addressable/uri"
|
13
|
+
uri = ::Addressable::URI.parse(actual) # if actual is ::URI re-parse
|
14
|
+
rescue LoadError
|
15
|
+
require "uri"
|
16
|
+
uri = actual.is_a?(URI) ? actual : ::URI.parse(actual)
|
17
|
+
end
|
18
|
+
|
19
|
+
begin
|
20
|
+
expectation.each do |key, value|
|
21
|
+
errors.push(*self.class.superclass.check_errors(uri.__send__(key), value, position + "[#key.inspect}]"))
|
22
|
+
end
|
23
|
+
rescue ::URI::Error
|
24
|
+
errors.push("#{position}: expect #{actual} to be parsed as uri")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe WildcardMatchers::Helpers::ForAny do
|
4
|
+
[ [ %w[ a b c ], :for_any, String ],
|
5
|
+
[ [ 1, "1" ], :for_any, String ],
|
6
|
+
].each do |actual, helper, matcher, *args|
|
7
|
+
it_behaves_like "wildcard match with helper", actual, helper, matcher, *args
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should match using lambda with helper" do
|
11
|
+
[ 1, 2, 3 ].should wildcard_match(for_any ->(item) { item % 2 == 0 })
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe WildcardMatchers::Matchers::IsUri do
|
4
|
+
[ [ "http://example.com", :is_uri ],
|
5
|
+
[ "http://example.com", :is_uri, :scheme => "http", :host => "example.com" ],
|
6
|
+
[ "http://example.com", :is_uri, :host => /example/ ],
|
7
|
+
].each do |actual, matcher, *args|
|
8
|
+
it_behaves_like "wildcard match", actual, matcher, *args
|
9
|
+
end
|
10
|
+
|
11
|
+
[ [ "http://example.com", :is_uri, :host => "google.com" ],
|
12
|
+
[ "http://example.com", :is_uri, :host => /google/ ],
|
13
|
+
].each do |actual, matcher, *args|
|
14
|
+
it_behaves_like "not wildcard match", actual, matcher, *args
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when you use addressable, :query_values also available" do
|
18
|
+
[ [ "http://example.com/?hoge=fuga", :is_uri, :query_values => { "hoge" => /fu/ } ],
|
19
|
+
].each do |actual, matcher, *args|
|
20
|
+
it_behaves_like "wildcard match", actual, matcher, *args
|
21
|
+
end
|
22
|
+
|
23
|
+
[ [ "http://example.com/?hoge=fuga", :is_uri, :query_values => { "hoge" => /ho/ } ],
|
24
|
+
].each do |actual, matcher, *args|
|
25
|
+
it_behaves_like "not wildcard match", actual, matcher, *args
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/wildcard_matchers.gemspec
CHANGED
@@ -18,6 +18,9 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency "rspec"
|
19
19
|
gem.add_development_dependency "autowatchr"
|
20
20
|
|
21
|
+
# your choic
|
22
|
+
gem.add_development_dependency "addressable"
|
23
|
+
|
21
24
|
# for debug
|
22
25
|
gem.add_development_dependency "pry"
|
23
26
|
gem.add_development_dependency "tapp"
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: addressable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: pry
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -111,17 +127,21 @@ files:
|
|
111
127
|
- lib/wildcard_matchers.rb
|
112
128
|
- lib/wildcard_matchers/helpers.rb
|
113
129
|
- lib/wildcard_matchers/helpers/for_all.rb
|
130
|
+
- lib/wildcard_matchers/helpers/for_any.rb
|
114
131
|
- lib/wildcard_matchers/helpers/nil_or.rb
|
115
132
|
- lib/wildcard_matchers/matchers.rb
|
116
133
|
- lib/wildcard_matchers/matchers/hash_includes.rb
|
134
|
+
- lib/wildcard_matchers/matchers/is_uri.rb
|
117
135
|
- lib/wildcard_matchers/rspec.rb
|
118
136
|
- lib/wildcard_matchers/wildcard_matcher.rb
|
119
137
|
- spec/spec.watchr
|
120
138
|
- spec/spec_helper.rb
|
121
139
|
- spec/support/shared_examples.rb
|
122
140
|
- spec/wildcard_matchers/helpers/for_all_spec.rb
|
141
|
+
- spec/wildcard_matchers/helpers/for_any_spec.rb
|
123
142
|
- spec/wildcard_matchers/helpers/nil_or_spec.rb
|
124
143
|
- spec/wildcard_matchers/matchers/hash_includes_spec.rb
|
144
|
+
- spec/wildcard_matchers/matchers/is_uri_spec.rb
|
125
145
|
- spec/wildcard_matchers/matchers_spec.rb
|
126
146
|
- spec/wildcard_matchers/rspec_spec.rb
|
127
147
|
- spec/wildcard_matchers_spec.rb
|
@@ -155,8 +175,11 @@ test_files:
|
|
155
175
|
- spec/spec_helper.rb
|
156
176
|
- spec/support/shared_examples.rb
|
157
177
|
- spec/wildcard_matchers/helpers/for_all_spec.rb
|
178
|
+
- spec/wildcard_matchers/helpers/for_any_spec.rb
|
158
179
|
- spec/wildcard_matchers/helpers/nil_or_spec.rb
|
159
180
|
- spec/wildcard_matchers/matchers/hash_includes_spec.rb
|
181
|
+
- spec/wildcard_matchers/matchers/is_uri_spec.rb
|
160
182
|
- spec/wildcard_matchers/matchers_spec.rb
|
161
183
|
- spec/wildcard_matchers/rspec_spec.rb
|
162
184
|
- spec/wildcard_matchers_spec.rb
|
185
|
+
has_rdoc:
|