wildcard_matchers 0.1.1 → 0.1.2
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.
- data/CHANGELOG.md +3 -0
- data/VERSION +1 -1
- data/lib/wildcard_matchers/helpers/for_all.rb +1 -5
- data/lib/wildcard_matchers/helpers/for_any.rb +1 -5
- data/lib/wildcard_matchers/helpers/nil_or.rb +1 -5
- data/lib/wildcard_matchers/helpers.rb +10 -1
- data/lib/wildcard_matchers/matchers/hash_includes.rb +2 -4
- data/lib/wildcard_matchers/matchers/is_uri.rb +4 -8
- data/lib/wildcard_matchers/matchers.rb +40 -13
- data/wildcard_matchers.gemspec +3 -1
- metadata +18 -2
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module WildcardMatchers
|
2
2
|
module Helpers
|
3
|
-
|
4
|
-
expectation = block_given? ? block : expectation
|
5
|
-
|
6
|
-
ForAll.new(expectation)
|
7
|
-
end
|
3
|
+
define_wildcard_helper(:for_all)
|
8
4
|
|
9
5
|
class ForAll < ::WildcardMatchers::WildcardMatcher
|
10
6
|
protected
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module WildcardMatchers
|
2
2
|
module Helpers
|
3
|
-
|
4
|
-
expectation = block_given? ? block : expectation
|
5
|
-
|
6
|
-
ForAny.new(expectation)
|
7
|
-
end
|
3
|
+
define_wildcard_helper(:for_any)
|
8
4
|
|
9
5
|
class ForAny < ::WildcardMatchers::WildcardMatcher
|
10
6
|
protected
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module WildcardMatchers
|
2
2
|
module Helpers
|
3
|
-
|
4
|
-
expectation = block_given? ? block : expectation
|
5
|
-
|
6
|
-
NilOr.new(expectation)
|
7
|
-
end
|
3
|
+
define_wildcard_helper(:nil_or)
|
8
4
|
|
9
5
|
class NilOr < ::WildcardMatchers::WildcardMatcher
|
10
6
|
protected
|
@@ -1,5 +1,14 @@
|
|
1
|
-
module
|
1
|
+
module WildcardMatchers
|
2
2
|
module Helpers
|
3
|
+
class << self
|
4
|
+
def define_wildcard_helper(name)
|
5
|
+
define_method(name) do |expectation = nil, &block|
|
6
|
+
expectation = block_given? ? block : expectation
|
7
|
+
|
8
|
+
::WildcardMatchers::Helpers.const_get(name.to_s.camelcase(:upper)).new(expectation)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
3
12
|
end
|
4
13
|
end
|
5
14
|
|
@@ -1,15 +1,13 @@
|
|
1
1
|
module WildcardMatchers
|
2
2
|
module Matchers
|
3
3
|
# RSpeck::Mocks has hash_including
|
4
|
-
|
5
|
-
HashIncludes.new(args)
|
6
|
-
end
|
4
|
+
define_wildcard_matcher(:hash_includes)
|
7
5
|
|
8
6
|
class HashIncludes < ::WildcardMatchers::WildcardMatcher
|
9
7
|
protected
|
10
8
|
def wildcard_match(actual)
|
11
9
|
unless actual.is_a?(Hash)
|
12
|
-
|
10
|
+
errors.push "#{position}: expect #{actual} to Hash"
|
13
11
|
end
|
14
12
|
|
15
13
|
hash_to_match = {}
|
@@ -12,16 +12,12 @@ module WildcardMatchers
|
|
12
12
|
require "addressable/uri"
|
13
13
|
uri = ::Addressable::URI.parse(actual) # if actual is ::URI re-parse
|
14
14
|
rescue LoadError
|
15
|
-
require "uri"
|
16
|
-
uri = actual.is_a?(URI) ? actual : ::URI.parse(actual)
|
15
|
+
require "uri".tapp
|
16
|
+
uri = actual.is_a?(::URI) ? actual : ::URI.parse(actual)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
|
-
|
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")
|
19
|
+
expectation.each do |key, value|
|
20
|
+
errors.push(*self.class.superclass.check_errors(uri.__send__(key), value, position + "[#{key.inspect}]"))
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
@@ -1,28 +1,55 @@
|
|
1
|
+
require "facets/string/camelcase"
|
2
|
+
|
1
3
|
module WildcardMatchers
|
2
4
|
module Matchers
|
3
|
-
|
5
|
+
class << self
|
6
|
+
def define_wildcard_matcher(name, &block)
|
7
|
+
if block_given?
|
8
|
+
define_method(name, &block)
|
9
|
+
else
|
10
|
+
define_method(name) do |*args|
|
11
|
+
::WildcardMatchers::Matchers.const_get(name.to_s.camelcase(:upper)).new(args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_wildcard_matcher_with_proc(name, &block)
|
17
|
+
raise "no block defined" unless block_given?
|
18
|
+
|
19
|
+
define_method(name) do
|
20
|
+
block
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# is_a(klass)
|
26
|
+
define_wildcard_matcher(:is_a) do |klass|
|
4
27
|
klass
|
5
28
|
end
|
6
29
|
|
30
|
+
# is_a_string
|
31
|
+
# is_a_integer
|
32
|
+
# is_a_float
|
33
|
+
# is_a_hash
|
34
|
+
# is_a_array
|
7
35
|
[ String, Integer, Float, Hash, Array ].each do |klass|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
}
|
36
|
+
define_wildcard_matcher("is_a_#{klass.to_s.downcase}") do
|
37
|
+
klass
|
38
|
+
end
|
13
39
|
end
|
14
40
|
|
15
|
-
|
16
|
-
|
41
|
+
# is_bool
|
42
|
+
define_wildcard_matcher_with_proc(:is_bool) do |bool|
|
43
|
+
TrueClass === bool or FalseClass === bool
|
17
44
|
end
|
18
45
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
46
|
+
# is_time
|
47
|
+
define_wildcard_matcher_with_proc(:is_time) do |time|
|
48
|
+
require "time"
|
49
|
+
time.is_a?(Time) or (Time.parse(time) rescue false)
|
24
50
|
end
|
25
51
|
|
52
|
+
# TODO: DSL
|
26
53
|
def is_a_member_of(*args)
|
27
54
|
lambda do |item|
|
28
55
|
args.flatten.any? {|expected| expected === item }
|
data/wildcard_matchers.gemspec
CHANGED
@@ -14,11 +14,13 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.version = File.read(File.join(File.dirname(__FILE__), "VERSION")).chomp
|
16
16
|
|
17
|
+
gem.add_dependency "facets"
|
18
|
+
|
17
19
|
gem.add_development_dependency "rake"
|
18
20
|
gem.add_development_dependency "rspec"
|
19
21
|
gem.add_development_dependency "autowatchr"
|
20
22
|
|
21
|
-
# your
|
23
|
+
# your choice
|
22
24
|
gem.add_development_dependency "addressable"
|
23
25
|
|
24
26
|
# for debug
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: facets
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: rake
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|