rspec-sleeping_king_studios 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +13 -7
- data/lib/rspec/sleeping_king_studios/matchers/built_in/respond_to.rb +15 -1
- data/lib/rspec/sleeping_king_studios/matchers/core/construct.rb +8 -3
- data/lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb +23 -6
- data/lib/rspec/sleeping_king_studios/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2914760ac00f260530d026c9aa1fb0215f1942cb
|
4
|
+
data.tar.gz: 185f9dc20a98f638ce428af5f53c353408734913
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 331f73ab249d34ecb3a46f327136774a8755c74de5cd543fc8a0b709ccfd354f1d1e5f73b6286ebf28f758d604574f952ed13432591a9817877225a904f9b5ca
|
7
|
+
data.tar.gz: 7550a28dd849c96e717df1d1e38a4eba927116aaa0caeccefdf8a97bd2ba6d8f32f8387c841ef2f6c39464e32dfc674747a7c77e9e6852a66399e7dab68b63f7
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 1.0.1
|
4
|
+
|
5
|
+
### New Features
|
6
|
+
|
7
|
+
* The #construct and #respond_to matchers now support 2.1.0 required keyword
|
8
|
+
arguments, of the form def foo(bar:, baz:). If the class constructor or
|
9
|
+
method requires one or more keyword arguments, and one or more of those
|
10
|
+
keywords are not provided when checking arguments using the #with
|
11
|
+
method, the matcher will fail with the message "missing keywords" and a list of the keywords that were not provided as arguments to #with.
|
12
|
+
|
13
|
+
## 1.0.0
|
14
|
+
|
15
|
+
* Official release.
|
data/README.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
A collection of matchers and extensions to ease TDD/BDD using RSpec.
|
4
4
|
|
5
|
+
## Supported Ruby Versions
|
6
|
+
|
7
|
+
Currently, the following versions of Ruby are officially supported:
|
8
|
+
|
9
|
+
* 1.9.3
|
10
|
+
* 2.0.0
|
11
|
+
* 2.1.0
|
12
|
+
|
5
13
|
## The Extensions
|
6
14
|
|
7
15
|
To enable an extension, simply require the associated file.
|
@@ -126,7 +134,9 @@ Has additional functionality to support Ruby 2.0 keyword arguments.
|
|
126
134
|
|
127
135
|
* **with:** Expects at most one Integer or Range argument, and zero or more
|
128
136
|
Symbol arguments corresponding to optional keywords. Verifies that the method
|
129
|
-
accepts that keyword, or has a variadic keyword of the form \*\*params.
|
137
|
+
accepts that keyword, or has a variadic keyword of the form \*\*params. As
|
138
|
+
of 2.1.0 and required keywords, verifies that all required keywords are
|
139
|
+
provided.
|
130
140
|
|
131
141
|
### Core
|
132
142
|
|
@@ -179,12 +189,8 @@ Has additional functionality to support Ruby 2.0 keyword arguments.
|
|
179
189
|
* **with:** Expects one Integer, Range, or nil argument, and zero or more
|
180
190
|
Symbol arguments corresponding to optional keywords. Verifies that the
|
181
191
|
class's constructor accepts that keyword, or has a variadic keyword of the
|
182
|
-
form \*\*params.
|
183
|
-
|
184
|
-
_Important note:_ If you do not wish to validate the number of arguments,
|
185
|
-
make sure to use nil as the first argument to #with; otherwise, the matcher
|
186
|
-
will interpret your first keyword as the number of arguments to expect. And
|
187
|
-
then explode.
|
192
|
+
form \*\*params. As of 2.1.0 and required keywords, verifies that all
|
193
|
+
required keywords are provided.
|
188
194
|
|
189
195
|
#### have\_property Matcher
|
190
196
|
|
@@ -126,7 +126,8 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
126
126
|
end # method matches_arity?
|
127
127
|
|
128
128
|
def matches_keywords? actual, name
|
129
|
-
return true unless @expected_keywords
|
129
|
+
return true unless @expected_keywords ||
|
130
|
+
(@expected_arity && RUBY_VERSION >= "2.1.0")
|
130
131
|
|
131
132
|
if result = check_method_keywords(actual.method(name), @expected_keywords)
|
132
133
|
(@failing_method_reasons[name] ||= {}).update result
|
@@ -134,6 +135,15 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
134
135
|
end # if
|
135
136
|
|
136
137
|
true
|
138
|
+
rescue NameError => error
|
139
|
+
if error.name == name
|
140
|
+
# Actual responds to name, but doesn't actually have a method defined
|
141
|
+
# there. Possibly using #method_missing or a test double. We obviously
|
142
|
+
# can't test that, so bail.
|
143
|
+
true
|
144
|
+
else
|
145
|
+
raise error
|
146
|
+
end # if-else
|
137
147
|
end # method matches_keywords?
|
138
148
|
|
139
149
|
def matches_block? actual, name
|
@@ -181,6 +191,10 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
181
191
|
messages << " expected at most #{hsh[:count]} arguments, but received #{hsh[:arity]}"
|
182
192
|
end # if-elsif
|
183
193
|
|
194
|
+
if ary = reasons.fetch(:missing_keywords, false)
|
195
|
+
messages << " missing keywords #{ary.map(&:inspect).join(", ")}"
|
196
|
+
end # if
|
197
|
+
|
184
198
|
if ary = reasons.fetch(:unexpected_keywords, false)
|
185
199
|
messages << " unexpected keywords #{ary.map(&:inspect).join(", ")}"
|
186
200
|
end # if
|
@@ -38,8 +38,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
38
38
|
# accepted by the method
|
39
39
|
#
|
40
40
|
# @return [ConstructMatcher] self
|
41
|
-
def with
|
42
|
-
@expected_arity =
|
41
|
+
def with *keywords
|
42
|
+
@expected_arity = keywords.shift if Integer === keywords.first || Range === keywords.first
|
43
43
|
@expected_keywords = keywords
|
44
44
|
self
|
45
45
|
end # method with
|
@@ -81,7 +81,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
81
81
|
end # method matches_arity?
|
82
82
|
|
83
83
|
def matches_keywords? actual
|
84
|
-
return true unless @expected_keywords
|
84
|
+
return true unless @expected_keywords ||
|
85
|
+
(@expected_arity && RUBY_VERSION >= "2.1.0")
|
85
86
|
|
86
87
|
if result = check_method_keywords(actual.allocate.method(:initialize), @expected_keywords)
|
87
88
|
@failing_method_reasons.update result
|
@@ -121,6 +122,10 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
121
122
|
messages << " expected at most #{hsh[:count]} arguments, but received #{hsh[:arity]}"
|
122
123
|
end # if-elsif
|
123
124
|
|
125
|
+
if ary = reasons.fetch(:missing_keywords, false)
|
126
|
+
messages << " missing keywords #{ary.map(&:inspect).join(", ")}"
|
127
|
+
end # if
|
128
|
+
|
124
129
|
if ary = reasons.fetch(:unexpected_keywords, false)
|
125
130
|
messages << " unexpected keywords #{ary.map(&:inspect).join(", ")}"
|
126
131
|
end # if
|
@@ -43,15 +43,32 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
43
43
|
def check_method_keywords method, keywords
|
44
44
|
return nil unless RUBY_VERSION >= "2.0.0"
|
45
45
|
|
46
|
+
keywords ||= []
|
46
47
|
parameters = method.parameters
|
47
|
-
|
48
|
+
reasons = {}
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
# Check for missing required keywords.
|
51
|
+
if RUBY_VERSION >= "2.1.0"
|
52
|
+
missing = []
|
53
|
+
parameters.select { |type, _| :keyreq == type }.each do |_, keyword|
|
54
|
+
missing << keyword unless keywords.include?(keyword)
|
55
|
+
end # each
|
56
|
+
|
57
|
+
reasons[:missing_keywords] = missing unless missing.empty?
|
58
|
+
end # if
|
59
|
+
|
60
|
+
unless 0 < parameters.count { |type, _| :keyrest == type }
|
61
|
+
mismatch = []
|
62
|
+
keywords.each do |keyword|
|
63
|
+
mismatch << keyword unless
|
64
|
+
parameters.include?([:key, keyword]) ||
|
65
|
+
parameters.include?([:keyreq, keyword])
|
66
|
+
end # each
|
67
|
+
|
68
|
+
reasons[:unexpected_keywords] = mismatch unless mismatch.empty?
|
69
|
+
end # unless
|
53
70
|
|
54
|
-
|
71
|
+
reasons.empty? ? nil : reasons
|
55
72
|
end # method check_method_keywords
|
56
73
|
|
57
74
|
# Checks whether the method expects a block.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-sleeping_king_studios
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rob "Merlin" Smith
|
@@ -56,30 +56,30 @@ dependencies:
|
|
56
56
|
name: fuubar
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.1.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.1.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 0.9.12
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 0.9.12
|
83
83
|
description: |2
|
84
84
|
A collection of RSpec patches and custom matchers. The features can be
|
85
85
|
included individually or by category. For more information, check out the
|
@@ -90,6 +90,7 @@ executables: []
|
|
90
90
|
extensions: []
|
91
91
|
extra_rdoc_files: []
|
92
92
|
files:
|
93
|
+
- CHANGELOG.md
|
93
94
|
- LICENSE
|
94
95
|
- README.md
|
95
96
|
- lib/rspec/sleeping_king_studios.rb
|