rspec-sleeping_king_studios 2.8.4 → 2.8.5
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/CHANGELOG.md +4 -0
- data/lib/rspec/sleeping_king_studios/matchers/active_model/have_errors_matcher.rb +38 -38
- data/lib/rspec/sleeping_king_studios/matchers/built_in/be_kind_of_matcher.rb +12 -12
- data/lib/rspec/sleeping_king_studios/matchers/core/have_constant_matcher.rb +29 -29
- data/lib/rspec/sleeping_king_studios/matchers/description.rb +16 -11
- data/lib/rspec/sleeping_king_studios/matchers/shared/match_parameters.rb +28 -33
- data/lib/rspec/sleeping_king_studios/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '002180c2b61102ae17dfa6814f04d8bbc8ffbaabcdf9eb2ee3659663881da1c1'
|
|
4
|
+
data.tar.gz: '0481509d19957f9be6ed46f70ef42c6c905bac506bcbf9af7e6f0e6573913e47'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa434f2ae76a8c062d601af815cd000e00880c74d87710be827b9e62983e82d72b57db2ffac52f9c20993e64efbd30c406bbffa9645eb1ec2e1585cdedae630f
|
|
7
|
+
data.tar.gz: 58ad6ba8b887d4032394884e0974d1ebad253463af1c4dc40aede8b504f2b24ae2b2149c264ed2dff96581c19bf46a66e7808ceda4ab3a5dffa9f4f86bcab4b7
|
data/CHANGELOG.md
CHANGED
|
@@ -19,7 +19,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
19
19
|
# The error and message expectations are set up through #on and
|
|
20
20
|
# #with_message.
|
|
21
21
|
@error_expectations = []
|
|
22
|
-
end
|
|
22
|
+
end
|
|
23
23
|
|
|
24
24
|
# (see BaseMatcher#description)
|
|
25
25
|
def description
|
|
@@ -30,22 +30,22 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
30
30
|
|
|
31
31
|
error_messages = expectation.messages.select(&:expected).map do |message_expectation|
|
|
32
32
|
%{"#{message_expectation.message}"}
|
|
33
|
-
end
|
|
33
|
+
end
|
|
34
34
|
|
|
35
35
|
unless error_messages.empty?
|
|
36
|
-
tools =
|
|
36
|
+
tools = SleepingKingStudios::Tools::Toolbelt.instance
|
|
37
37
|
|
|
38
38
|
attribute_message <<
|
|
39
39
|
" with message#{error_messages.count == 1 ? '' : 's'} "\
|
|
40
|
-
"#{tools.humanize_list error_messages}"
|
|
41
|
-
end
|
|
40
|
+
"#{tools.array_tools.humanize_list error_messages}"
|
|
41
|
+
end
|
|
42
42
|
|
|
43
43
|
attribute_message
|
|
44
|
-
end
|
|
44
|
+
end
|
|
45
45
|
message << " on #{attribute_messages.join(", and on ")}" unless attribute_messages.empty?
|
|
46
46
|
|
|
47
47
|
message
|
|
48
|
-
end
|
|
48
|
+
end
|
|
49
49
|
|
|
50
50
|
# Checks if the object can be validated, whether the object is valid, and
|
|
51
51
|
# checks the errors on the object against the expected errors and messages
|
|
@@ -66,7 +66,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
66
66
|
return false unless @validates = actual.respond_to?(:valid?)
|
|
67
67
|
|
|
68
68
|
!matches?(actual)
|
|
69
|
-
end
|
|
69
|
+
end
|
|
70
70
|
|
|
71
71
|
# Checks if the object can be validated, whether the object is valid, and
|
|
72
72
|
# checks the errors on the object against the expected errors and messages
|
|
@@ -85,7 +85,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
85
85
|
return false unless @validates = actual.respond_to?(:valid?)
|
|
86
86
|
|
|
87
87
|
!@actual.valid? && attributes_have_errors?
|
|
88
|
-
end
|
|
88
|
+
end
|
|
89
89
|
|
|
90
90
|
# Adds an error expectation. If the actual object does not have an error on
|
|
91
91
|
# the specified attribute, #matches? will return false.
|
|
@@ -100,7 +100,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
100
100
|
@error_expectations << ErrorExpectation.new(attribute)
|
|
101
101
|
|
|
102
102
|
self
|
|
103
|
-
end
|
|
103
|
+
end
|
|
104
104
|
|
|
105
105
|
# Adds a message expectation for the most recently added error attribute.
|
|
106
106
|
# If the actual object does not have an error on the that attribute with
|
|
@@ -125,7 +125,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
125
125
|
@error_expectations.last.messages << MessageExpectation.new(message)
|
|
126
126
|
|
|
127
127
|
self
|
|
128
|
-
end
|
|
128
|
+
end
|
|
129
129
|
|
|
130
130
|
# Adds a set of message expectations for the most recently added error
|
|
131
131
|
# attribute.
|
|
@@ -137,7 +137,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
137
137
|
messages.each do |message| self.with_message(message); end
|
|
138
138
|
|
|
139
139
|
self
|
|
140
|
-
end
|
|
140
|
+
end
|
|
141
141
|
alias_method :with, :with_messages
|
|
142
142
|
|
|
143
143
|
# (see BaseMatcher#failure_message)
|
|
@@ -154,8 +154,8 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
154
154
|
"expected #{@actual.inspect} to have errors"
|
|
155
155
|
else
|
|
156
156
|
"expected #{@actual.inspect} to have errors#{expected_errors_message}#{received_errors_message}"
|
|
157
|
-
end
|
|
158
|
-
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
159
|
|
|
160
160
|
# (see BaseMatcher#failure_message_when_negated)
|
|
161
161
|
def failure_message_when_negated
|
|
@@ -174,8 +174,8 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
174
174
|
return "expected #{@actual.inspect} not to have errors#{received_errors_message}"
|
|
175
175
|
else
|
|
176
176
|
return "expected #{@actual.inspect} not to have errors#{expected_errors_message}#{received_errors_message}"
|
|
177
|
-
end
|
|
178
|
-
end
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
179
|
|
|
180
180
|
private
|
|
181
181
|
|
|
@@ -186,7 +186,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
186
186
|
# Find the matching error expectation, if any.
|
|
187
187
|
error_expectation = @error_expectations.detect do |error_expectation|
|
|
188
188
|
error_expectation.attribute == attribute
|
|
189
|
-
end
|
|
189
|
+
end
|
|
190
190
|
|
|
191
191
|
if error_expectation
|
|
192
192
|
error_expectation.received = true
|
|
@@ -201,52 +201,52 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
201
201
|
message =~ message_expectation.message
|
|
202
202
|
else
|
|
203
203
|
message == message_expectation.message
|
|
204
|
-
end
|
|
205
|
-
end
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
206
|
|
|
207
207
|
if message_expectation
|
|
208
208
|
message_expectation.received = true
|
|
209
209
|
else
|
|
210
210
|
error_expectation.messages << MessageExpectation.new(message, false, true)
|
|
211
|
-
end
|
|
212
|
-
end
|
|
213
|
-
end
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
214
|
else
|
|
215
215
|
error_expectation = ErrorExpectation.new attribute, false, true
|
|
216
216
|
messages.each do |message|
|
|
217
217
|
error_expectation.messages << MessageExpectation.new(message, false, true)
|
|
218
|
-
end
|
|
218
|
+
end
|
|
219
219
|
|
|
220
220
|
@error_expectations << error_expectation
|
|
221
|
-
end
|
|
222
|
-
end
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
223
|
|
|
224
224
|
missing_errors.empty? && missing_messages.empty?
|
|
225
|
-
end
|
|
225
|
+
end
|
|
226
226
|
|
|
227
227
|
def expected_errors
|
|
228
228
|
@error_expectations.select do |error_expectation|
|
|
229
229
|
error_expectation.expected
|
|
230
|
-
end
|
|
231
|
-
end
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
232
|
|
|
233
233
|
def missing_errors
|
|
234
234
|
@error_expectations.select do |error_expectation|
|
|
235
235
|
error_expectation.expected && !error_expectation.received
|
|
236
|
-
end
|
|
237
|
-
end
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
238
|
|
|
239
239
|
def missing_messages
|
|
240
240
|
@error_expectations.select do |error_expectation|
|
|
241
241
|
!error_expectation.messages.missing.empty?
|
|
242
|
-
end
|
|
243
|
-
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
244
|
|
|
245
245
|
def unexpected_errors
|
|
246
246
|
@error_expectations.select do |error_expectation|
|
|
247
247
|
!error_expectation.expected && error_expectation.received
|
|
248
|
-
end
|
|
249
|
-
end
|
|
248
|
+
end
|
|
249
|
+
end
|
|
250
250
|
|
|
251
251
|
def expected_errors_message
|
|
252
252
|
"\n expected errors:" + expected_errors.map do |error_expectation|
|
|
@@ -254,7 +254,7 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
254
254
|
"(#{@negative_expectation ? 'none' : 'any'})" :
|
|
255
255
|
error_expectation.messages.expected.map(&:message).map(&:inspect).join(", "))
|
|
256
256
|
end.join # map
|
|
257
|
-
end
|
|
257
|
+
end
|
|
258
258
|
|
|
259
259
|
def received_errors_message
|
|
260
260
|
return "" unless @validates
|
|
@@ -264,6 +264,6 @@ module RSpec::SleepingKingStudios::Matchers::ActiveModel
|
|
|
264
264
|
"\n received errors:" + @actual.errors.messages.map do |attr, ary|
|
|
265
265
|
"\n #{attr}: " + ary.map(&:inspect).join(", ")
|
|
266
266
|
end.join # map
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
end
|
|
@@ -9,7 +9,7 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
|
9
9
|
# (see BaseMatcher#description)
|
|
10
10
|
def description
|
|
11
11
|
message = "be #{type_string}"
|
|
12
|
-
end
|
|
12
|
+
end
|
|
13
13
|
|
|
14
14
|
# Checks if the object matches one of the specified types. Allows an
|
|
15
15
|
# expected value of nil as a shortcut for expecting an instance of
|
|
@@ -23,17 +23,17 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
|
23
23
|
# otherwise false.
|
|
24
24
|
def match expected, actual
|
|
25
25
|
match_type? expected
|
|
26
|
-
end
|
|
26
|
+
end
|
|
27
27
|
|
|
28
28
|
# (see BaseMatcher#failure_message)
|
|
29
29
|
def failure_message
|
|
30
30
|
"expected #{@actual.inspect} to be #{type_string}"
|
|
31
|
-
end
|
|
31
|
+
end
|
|
32
32
|
|
|
33
33
|
# (see BaseMatcher#failure_message_when_negated)
|
|
34
34
|
def failure_message_when_negated
|
|
35
35
|
"expected #{@actual.inspect} not to be #{type_string}"
|
|
36
|
-
end
|
|
36
|
+
end
|
|
37
37
|
|
|
38
38
|
private
|
|
39
39
|
|
|
@@ -45,21 +45,21 @@ module RSpec::SleepingKingStudios::Matchers::BuiltIn
|
|
|
45
45
|
expected.reduce(false) { |memo, obj| memo || match_type?(obj) }
|
|
46
46
|
else
|
|
47
47
|
@actual.kind_of? expected
|
|
48
|
-
end
|
|
49
|
-
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
50
|
|
|
51
51
|
def type_string
|
|
52
52
|
case
|
|
53
53
|
when @expected.nil?
|
|
54
54
|
@expected.inspect
|
|
55
55
|
when @expected.is_a?(Enumerable) && 1 < @expected.count
|
|
56
|
-
tools =
|
|
56
|
+
tools = SleepingKingStudios::Tools::Toolbelt.instance
|
|
57
57
|
items = @expected.map { |value| value.nil? ? 'nil' : value }
|
|
58
58
|
|
|
59
|
-
"a #{tools.humanize_list items, :last_separator => ' or '}"
|
|
59
|
+
"a #{tools.array_tools.humanize_list items, :last_separator => ' or '}"
|
|
60
60
|
else
|
|
61
61
|
"a #{expected}"
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -17,7 +17,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
17
17
|
# the actual object.
|
|
18
18
|
def initialize expected
|
|
19
19
|
@expected = expected.intern
|
|
20
|
-
end
|
|
20
|
+
end
|
|
21
21
|
|
|
22
22
|
# (see BaseMatcher#description)
|
|
23
23
|
def description
|
|
@@ -27,7 +27,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
27
27
|
message << ' with value ' << value_to_string if @value_set
|
|
28
28
|
|
|
29
29
|
message
|
|
30
|
-
end
|
|
30
|
+
end
|
|
31
31
|
|
|
32
32
|
# (see BaseMatcher#does_not_match?)
|
|
33
33
|
def does_not_match? actual
|
|
@@ -36,7 +36,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
36
36
|
@errors = {}
|
|
37
37
|
|
|
38
38
|
!has_constant?
|
|
39
|
-
end
|
|
39
|
+
end
|
|
40
40
|
|
|
41
41
|
# (see BaseMatcher#failure_message)
|
|
42
42
|
def failure_message
|
|
@@ -49,33 +49,33 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
49
49
|
", but #{@actual.inspect} does not respond to ::const_defined?"
|
|
50
50
|
|
|
51
51
|
return message
|
|
52
|
-
end
|
|
52
|
+
end
|
|
53
53
|
|
|
54
54
|
if @errors[:constant_is_not_defined]
|
|
55
55
|
message <<
|
|
56
56
|
", but #{@actual.inspect} does not define constant #{@expected.inspect}"
|
|
57
57
|
|
|
58
58
|
return message
|
|
59
|
-
end
|
|
59
|
+
end
|
|
60
60
|
|
|
61
61
|
if hsh = @errors[:value_does_not_match]
|
|
62
62
|
messages <<
|
|
63
63
|
"constant #{@expected.inspect} has value #{hsh[:received].inspect}"
|
|
64
|
-
end
|
|
64
|
+
end
|
|
65
65
|
|
|
66
66
|
if hsh = @errors[:value_is_mutable]
|
|
67
67
|
messages <<
|
|
68
68
|
"the value of #{@expected.inspect} was mutable"
|
|
69
|
-
end
|
|
69
|
+
end
|
|
70
70
|
|
|
71
71
|
unless messages.empty?
|
|
72
|
-
tools =
|
|
72
|
+
tools = SleepingKingStudios::Tools::Toolbelt.instance
|
|
73
73
|
|
|
74
|
-
message << ', but ' << tools.humanize_list(messages)
|
|
75
|
-
end
|
|
74
|
+
message << ', but ' << tools.array_tools.humanize_list(messages)
|
|
75
|
+
end
|
|
76
76
|
|
|
77
77
|
message
|
|
78
|
-
end
|
|
78
|
+
end
|
|
79
79
|
|
|
80
80
|
# (see BaseMatcher#failure_message_when_negated)
|
|
81
81
|
def failure_message_when_negated
|
|
@@ -86,7 +86,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
86
86
|
"value #{actual.const_get(@expected).inspect}"
|
|
87
87
|
|
|
88
88
|
message
|
|
89
|
-
end
|
|
89
|
+
end
|
|
90
90
|
|
|
91
91
|
# Sets a mutability expectation. The matcher will determine whether the
|
|
92
92
|
# value of the constant is mutable. Values of `nil`, `false`, `true` are
|
|
@@ -99,14 +99,14 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
99
99
|
@immutable = true
|
|
100
100
|
|
|
101
101
|
self
|
|
102
|
-
end
|
|
102
|
+
end
|
|
103
103
|
alias_method :frozen, :immutable
|
|
104
104
|
|
|
105
105
|
# @return [Boolean] True if a mutability expectation is set, otherwise
|
|
106
106
|
# false.
|
|
107
107
|
def immutable?
|
|
108
108
|
!!@immutable
|
|
109
|
-
end
|
|
109
|
+
end
|
|
110
110
|
alias_method :frozen?, :immutable?
|
|
111
111
|
|
|
112
112
|
# Checks if the object has a constant :expected. Additionally, if a
|
|
@@ -125,7 +125,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
125
125
|
return false unless has_constant?
|
|
126
126
|
|
|
127
127
|
matches_constant? :all?
|
|
128
|
-
end
|
|
128
|
+
end
|
|
129
129
|
|
|
130
130
|
# Sets a value expectation. The matcher will compare the value of the
|
|
131
131
|
# constant with the specified value.
|
|
@@ -137,7 +137,7 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
137
137
|
@value = value
|
|
138
138
|
@value_set = true
|
|
139
139
|
self
|
|
140
|
-
end
|
|
140
|
+
end
|
|
141
141
|
alias_method :with_value, :with
|
|
142
142
|
|
|
143
143
|
private
|
|
@@ -147,16 +147,16 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
147
147
|
@errors[:does_not_define_constants] = true
|
|
148
148
|
|
|
149
149
|
return false
|
|
150
|
-
end
|
|
150
|
+
end
|
|
151
151
|
|
|
152
152
|
unless actual.const_defined?(@expected)
|
|
153
153
|
@errors[:constant_is_not_defined] = true
|
|
154
154
|
|
|
155
155
|
return false
|
|
156
|
-
end
|
|
156
|
+
end
|
|
157
157
|
|
|
158
158
|
true
|
|
159
|
-
end
|
|
159
|
+
end
|
|
160
160
|
|
|
161
161
|
def immutable_value?
|
|
162
162
|
return true unless @immutable
|
|
@@ -167,16 +167,16 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
167
167
|
@errors[:value_is_mutable] = true
|
|
168
168
|
|
|
169
169
|
return false
|
|
170
|
-
end
|
|
170
|
+
end
|
|
171
171
|
|
|
172
172
|
true
|
|
173
|
-
end
|
|
173
|
+
end
|
|
174
174
|
|
|
175
175
|
def matches_constant? filter
|
|
176
176
|
[ matches_constant_value?,
|
|
177
177
|
immutable_value?
|
|
178
178
|
].send(filter) { |bool| bool }
|
|
179
|
-
end
|
|
179
|
+
end
|
|
180
180
|
|
|
181
181
|
def matches_constant_value?
|
|
182
182
|
return true unless @value_set
|
|
@@ -193,10 +193,10 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
193
193
|
} # end hash
|
|
194
194
|
|
|
195
195
|
return false
|
|
196
|
-
end
|
|
196
|
+
end
|
|
197
197
|
|
|
198
198
|
true
|
|
199
|
-
end
|
|
199
|
+
end
|
|
200
200
|
|
|
201
201
|
def mutable? value
|
|
202
202
|
case value
|
|
@@ -212,8 +212,8 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
212
212
|
(value.keys + value.values).reduce(false) { |memo, item| memo || mutable?(item) }
|
|
213
213
|
else
|
|
214
214
|
!value.frozen?
|
|
215
|
-
end
|
|
216
|
-
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
217
|
|
|
218
218
|
# Formats the expected value as a human-readable string. If the value looks
|
|
219
219
|
# like an RSpec matcher (it responds to :matches? and :description), calls
|
|
@@ -224,6 +224,6 @@ module RSpec::SleepingKingStudios::Matchers::Core
|
|
|
224
224
|
return @value.description if @value.respond_to?(:matches?) && @value.respond_to?(:description)
|
|
225
225
|
|
|
226
226
|
@value.inspect
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
end
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
end
|
|
@@ -23,13 +23,13 @@ module RSpec::SleepingKingStudios::Matchers
|
|
|
23
23
|
desc << format_expected_items
|
|
24
24
|
|
|
25
25
|
desc
|
|
26
|
-
end
|
|
26
|
+
end
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
30
|
def expected_items_for_description
|
|
31
31
|
defined?(@expected) ? @expected : DEFAULT_EXPECTED_ITEMS
|
|
32
|
-
end
|
|
32
|
+
end
|
|
33
33
|
|
|
34
34
|
def format_expected_items
|
|
35
35
|
expected_items = expected_items_for_description
|
|
@@ -43,20 +43,25 @@ module RSpec::SleepingKingStudios::Matchers
|
|
|
43
43
|
# RSpec 3.0-3.3
|
|
44
44
|
to_sentence(expected_items)
|
|
45
45
|
else
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
processed =
|
|
47
|
+
tools
|
|
48
|
+
.array_tools
|
|
49
|
+
.humanize_list([expected_items].flatten.map(&:inspect))
|
|
48
50
|
|
|
49
51
|
' ' << array_tools.humanize_list(processed)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
52
54
|
|
|
53
55
|
def matcher_name
|
|
54
56
|
return @matcher_name if @matcher_name
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
name = string_tools.underscore(self.class.name.split('::').last)
|
|
58
|
+
name = tools.string_tools.underscore(self.class.name.split('::').last)
|
|
58
59
|
|
|
59
60
|
@matcher_name = name.tr('_', ' ').sub(/ matcher\z/, '')
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def tools
|
|
64
|
+
SleepingKingStudios::Tools::Toolbelt.instance
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'rspec/sleeping_king_studios/matchers'
|
|
4
4
|
require 'sleeping_king_studios/tools/array_tools'
|
|
5
5
|
require 'rspec/sleeping_king_studios/support/method_signature_expectation'
|
|
6
6
|
|
|
7
7
|
module RSpec::SleepingKingStudios::Matchers::Shared
|
|
8
|
-
# Helper methods for checking the
|
|
9
|
-
# a method.
|
|
8
|
+
# Helper methods for checking the arguments and keywords of a method.
|
|
10
9
|
module MatchParameters
|
|
11
10
|
# Convenience method for more fluent specs. Does nothing and returns self.
|
|
12
11
|
#
|
|
13
12
|
# @return self
|
|
14
13
|
def argument
|
|
15
14
|
self
|
|
16
|
-
end
|
|
15
|
+
end
|
|
17
16
|
alias_method :arguments, :argument
|
|
18
17
|
|
|
19
18
|
# Adds a parameter count expectation and/or one or more keyword
|
|
@@ -55,12 +54,12 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
55
54
|
|
|
56
55
|
method_signature_expectation.min_arguments = arity
|
|
57
56
|
method_signature_expectation.max_arguments = arity
|
|
58
|
-
end
|
|
57
|
+
end
|
|
59
58
|
|
|
60
59
|
method_signature_expectation.keywords = keywords
|
|
61
60
|
|
|
62
61
|
self
|
|
63
|
-
end
|
|
62
|
+
end
|
|
64
63
|
|
|
65
64
|
# Adds a block expectation. The actual object will only match a block
|
|
66
65
|
# expectation if it expects a parameter of the form &block.
|
|
@@ -70,7 +69,7 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
70
69
|
method_signature_expectation.block_argument = true
|
|
71
70
|
|
|
72
71
|
self
|
|
73
|
-
end
|
|
72
|
+
end
|
|
74
73
|
alias_method :and_a_block, :with_a_block
|
|
75
74
|
|
|
76
75
|
# Adds an arbitrary keyword expectation, e.g. that the method supports
|
|
@@ -79,7 +78,7 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
79
78
|
method_signature_expectation.any_keywords = true
|
|
80
79
|
|
|
81
80
|
self
|
|
82
|
-
end
|
|
81
|
+
end
|
|
83
82
|
alias_method :and_arbitrary_keywords, :with_arbitrary_keywords
|
|
84
83
|
alias_method :with_any_keywords, :with_arbitrary_keywords
|
|
85
84
|
alias_method :and_any_keywords, :with_any_keywords
|
|
@@ -94,7 +93,7 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
94
93
|
method_signature_expectation.keywords = keywords
|
|
95
94
|
|
|
96
95
|
self
|
|
97
|
-
end
|
|
96
|
+
end
|
|
98
97
|
alias_method :and_keywords, :with_keywords
|
|
99
98
|
|
|
100
99
|
# Adds an unlimited parameter count expectation, e.g. that the method
|
|
@@ -105,17 +104,15 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
105
104
|
method_signature_expectation.unlimited_arguments = true
|
|
106
105
|
|
|
107
106
|
self
|
|
108
|
-
end
|
|
107
|
+
end
|
|
109
108
|
alias_method :and_unlimited_arguments, :with_unlimited_arguments
|
|
110
109
|
|
|
111
110
|
private
|
|
112
111
|
|
|
113
|
-
# @api private
|
|
114
112
|
def check_method_signature method
|
|
115
113
|
method_signature_expectation.matches?(method)
|
|
116
|
-
end
|
|
114
|
+
end
|
|
117
115
|
|
|
118
|
-
# @api private
|
|
119
116
|
def format_errors errors
|
|
120
117
|
messages = []
|
|
121
118
|
|
|
@@ -127,17 +124,17 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
127
124
|
# - at least :min (for methods with variadic params)
|
|
128
125
|
if hsh = errors.fetch(:not_enough_args, false)
|
|
129
126
|
messages << " expected at least #{hsh[:expected]} arguments, but received #{hsh[:received]}"
|
|
130
|
-
end
|
|
127
|
+
end
|
|
131
128
|
|
|
132
129
|
if hsh = errors.fetch(:too_many_args, false)
|
|
133
130
|
messages << " expected at most #{hsh[:expected]} arguments, but received #{hsh[:received]}"
|
|
134
|
-
end
|
|
131
|
+
end
|
|
135
132
|
|
|
136
133
|
# TODO: Replace this with " expected method to receive unlimited "\
|
|
137
134
|
# "arguments, but method can receive at most :max arguments"
|
|
138
135
|
if hsh = errors.fetch(:no_variadic_args, false)
|
|
139
136
|
messages << " expected at most #{hsh[:expected]} arguments, but received unlimited arguments"
|
|
140
|
-
end
|
|
137
|
+
end
|
|
141
138
|
|
|
142
139
|
# TODO: Replace this with " expected method to receive arbitrary "\
|
|
143
140
|
# "keywords, but the method can receive :keyword_list", with
|
|
@@ -146,46 +143,44 @@ module RSpec::SleepingKingStudios::Matchers::Shared
|
|
|
146
143
|
# " receive keywords"
|
|
147
144
|
if errors.fetch(:no_variadic_keywords, false)
|
|
148
145
|
messages << " expected arbitrary keywords"
|
|
149
|
-
end
|
|
146
|
+
end
|
|
150
147
|
|
|
151
148
|
# TODO: Replace this with " expected method to receive keywords "\
|
|
152
149
|
# ":received_list, but the method requires keywords :required_list"
|
|
153
150
|
if ary = errors.fetch(:missing_keywords, false)
|
|
154
|
-
tools = ::SleepingKingStudios::Tools::ArrayTools
|
|
155
|
-
|
|
156
151
|
messages <<
|
|
157
152
|
" missing keyword#{ary.count == 1 ? '' : 's'} "\
|
|
158
|
-
"#{tools.humanize_list ary.map(&:inspect)}"
|
|
159
|
-
end
|
|
153
|
+
"#{tools.array_tools.humanize_list ary.map(&:inspect)}"
|
|
154
|
+
end
|
|
160
155
|
|
|
161
156
|
# TODO: Replace this with " expected method to receive keywords "\
|
|
162
157
|
# ":received_list, but the method can receive :keyword_list"
|
|
163
158
|
if ary = errors.fetch(:unexpected_keywords, false)
|
|
164
|
-
tools = ::SleepingKingStudios::Tools::ArrayTools
|
|
165
|
-
|
|
166
159
|
messages <<
|
|
167
160
|
" unexpected keyword#{ary.count == 1 ? '' : 's'} "\
|
|
168
|
-
"#{tools.humanize_list ary.map(&:inspect)}"
|
|
169
|
-
end
|
|
161
|
+
"#{tools.array_tools.humanize_list ary.map(&:inspect)}"
|
|
162
|
+
end
|
|
170
163
|
|
|
171
164
|
# TODO: Replace this with " expected method to receive a block "\
|
|
172
165
|
# "argument, but the method signature does not specify a block argument"
|
|
173
166
|
if errors.fetch(:no_block_argument, false)
|
|
174
167
|
messages << " unexpected block"
|
|
175
|
-
end
|
|
168
|
+
end
|
|
176
169
|
|
|
177
170
|
messages.join "\n"
|
|
178
|
-
end
|
|
171
|
+
end
|
|
179
172
|
|
|
180
|
-
# @api private
|
|
181
173
|
def method_signature_expectation
|
|
182
174
|
@method_signature_expectation ||=
|
|
183
175
|
::RSpec::SleepingKingStudios::Support::MethodSignatureExpectation.new
|
|
184
|
-
end
|
|
176
|
+
end
|
|
185
177
|
|
|
186
|
-
# @api private
|
|
187
178
|
def method_signature_expectation?
|
|
188
179
|
!!@method_signature_expectation
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def tools
|
|
183
|
+
SleepingKingStudios::Tools::Toolbelt.instance
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
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: 2.8.
|
|
4
|
+
version: 2.8.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rob "Merlin" Smith
|
|
@@ -190,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
190
190
|
- !ruby/object:Gem::Version
|
|
191
191
|
version: '0'
|
|
192
192
|
requirements: []
|
|
193
|
-
rubygems_version: 4.0.
|
|
193
|
+
rubygems_version: 4.0.15
|
|
194
194
|
specification_version: 4
|
|
195
195
|
summary: A collection of RSpec patches and custom matchers.
|
|
196
196
|
test_files: []
|