argspec 0.3.1 → 0.3.3
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/lib/argspec/argument.rb +10 -6
- data/lib/argspec/constants.rb +1 -1
- data/lib/argspec/dsl/matchers.rb +2 -1
- data/lib/argspec/matchers/all.rb +1 -0
- data/lib/argspec/matchers/base_matcher.rb +14 -1
- data/lib/argspec/matchers/satisfy.rb +6 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7530a54443a31a3935f593dffe2e9db9c060e755
|
4
|
+
data.tar.gz: 0a6107f1acdea055a2e7d9c6607182b813a157ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e57e5047bbd137788c73f328b3ecb0500665f170437d098964f167267f49b1643f5661be9d890f092b2630a0866ba4eab46916ed6048f6897881aa9f466a6ae8
|
7
|
+
data.tar.gz: 4096f8daefcee69e639386786583bebe921c8d67ff68eca21f6a068cfd109ce918c519ebf029eaad591b9aa35c634ae8c18c6d2a89b2d46c07ec8b826e379eab
|
data/lib/argspec/argument.rb
CHANGED
@@ -27,6 +27,7 @@ module ArgumentSpecification
|
|
27
27
|
#
|
28
28
|
# Arguments:
|
29
29
|
# matcher: (Matchers::BaseMatcher)
|
30
|
+
# block: (Block)
|
30
31
|
#
|
31
32
|
# Example:
|
32
33
|
# >> should be_a(Symbol)
|
@@ -35,10 +36,11 @@ module ArgumentSpecification
|
|
35
36
|
# Raises:
|
36
37
|
# ArgumentError: When the argument does not match
|
37
38
|
#
|
38
|
-
def should(matcher)
|
39
|
+
def should(matcher, &block)
|
39
40
|
return self unless matcher.is_a?(Matchers::BaseMatcher)
|
40
41
|
|
41
42
|
matcher.send(:actual=, @actual)
|
43
|
+
matcher.send(:block=, block) if block_given?
|
42
44
|
|
43
45
|
return self if matcher.matches?
|
44
46
|
|
@@ -49,6 +51,7 @@ module ArgumentSpecification
|
|
49
51
|
#
|
50
52
|
# Arguments:
|
51
53
|
# matcher: (Matchers::BaseMatcher)
|
54
|
+
# block: (Block)
|
52
55
|
#
|
53
56
|
# Example:
|
54
57
|
# >> should_not be_a(Symbol)
|
@@ -57,10 +60,11 @@ module ArgumentSpecification
|
|
57
60
|
# Raises:
|
58
61
|
# ArgumentError: When the argument matches
|
59
62
|
#
|
60
|
-
def should_not(matcher)
|
63
|
+
def should_not(matcher, &block)
|
61
64
|
return self unless matcher.is_a?(Matchers::BaseMatcher)
|
62
65
|
|
63
66
|
matcher.send(:actual=, @actual)
|
67
|
+
matcher.send(:block=, block) if block_given?
|
64
68
|
|
65
69
|
return self unless matcher.matches?
|
66
70
|
|
@@ -73,8 +77,8 @@ module ArgumentSpecification
|
|
73
77
|
# >> and be_a(Symbol)
|
74
78
|
# => #<Argument:0x00000000000000 @actual=:test>
|
75
79
|
#
|
76
|
-
def and(*args)
|
77
|
-
should(*args)
|
80
|
+
def and(*args, &block)
|
81
|
+
should(*args, &block)
|
78
82
|
end
|
79
83
|
|
80
84
|
# Alias for should_not
|
@@ -83,8 +87,8 @@ module ArgumentSpecification
|
|
83
87
|
# >> and_not be_a(Symbol)
|
84
88
|
# => #<Argument:0x00000000000000 @actual=:test>
|
85
89
|
#
|
86
|
-
def and_not(*args)
|
87
|
-
should_not(*args)
|
90
|
+
def and_not(*args, &block)
|
91
|
+
should_not(*args, &block)
|
88
92
|
end
|
89
93
|
end
|
90
94
|
end
|
data/lib/argspec/constants.rb
CHANGED
data/lib/argspec/dsl/matchers.rb
CHANGED
@@ -18,8 +18,9 @@ module ArgumentSpecification
|
|
18
18
|
|
19
19
|
module_eval <<-EOS
|
20
20
|
def #{name}(*args, &block)
|
21
|
-
instance = #{klass}.new(*args
|
21
|
+
instance = #{klass}.new(*args)
|
22
22
|
instance.send(:setup, '#{name}'.to_sym, args)
|
23
|
+
instance.send(:block=, block) if block_given?
|
23
24
|
instance
|
24
25
|
end
|
25
26
|
EOS
|
data/lib/argspec/matchers/all.rb
CHANGED
@@ -22,7 +22,7 @@ module ArgumentSpecification
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
attr_reader :actual, :metadata
|
25
|
+
attr_reader :actual, :block, :metadata
|
26
26
|
|
27
27
|
# The failure message when using 'should'
|
28
28
|
#
|
@@ -102,6 +102,19 @@ module ArgumentSpecification
|
|
102
102
|
@actual = actual
|
103
103
|
end
|
104
104
|
|
105
|
+
# Set the block
|
106
|
+
#
|
107
|
+
# Arguments:
|
108
|
+
# block: (Proc)
|
109
|
+
#
|
110
|
+
# Example:
|
111
|
+
# >> matcher.block = Proc.new {}
|
112
|
+
# => #<Proc:0x00000000000000>
|
113
|
+
#
|
114
|
+
def block=(block)
|
115
|
+
@block = block
|
116
|
+
end
|
117
|
+
|
105
118
|
# Prettify a matcher
|
106
119
|
#
|
107
120
|
# Arguments:
|
@@ -3,21 +3,19 @@ module ArgumentSpecification
|
|
3
3
|
class Satisfy < BaseMatcher
|
4
4
|
matcher_name :satisfy
|
5
5
|
|
6
|
-
attr_reader :description
|
6
|
+
attr_reader :description
|
7
7
|
|
8
8
|
# Create a new matcher instance
|
9
9
|
#
|
10
10
|
# Arguments:
|
11
11
|
# description: (String)
|
12
|
-
# block: (Block)
|
13
12
|
#
|
14
13
|
# Example:
|
15
|
-
# >> ArgumentSpecification::Matchers::Satisfy.new('always pass')
|
14
|
+
# >> ArgumentSpecification::Matchers::Satisfy.new('always pass')
|
16
15
|
# => #<ArgumentSpecification::Matchers::Satisfy:0x00000000000000 @block=#<Proc:0x00000000000000>>
|
17
16
|
#
|
18
|
-
def initialize(description
|
17
|
+
def initialize(description)
|
19
18
|
@description = description
|
20
|
-
@block = block
|
21
19
|
end
|
22
20
|
|
23
21
|
# The failure message when using 'should'
|
@@ -59,7 +57,9 @@ module ArgumentSpecification
|
|
59
57
|
# => true
|
60
58
|
#
|
61
59
|
def matches?
|
62
|
-
@block.call(@actual)
|
60
|
+
return @block.call(@actual) if @block
|
61
|
+
|
62
|
+
false
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nialto Services
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|