rspec-expectations 2.12.1 → 2.13.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +31 -0
- data/README.md +1 -1
- data/features/built_in_matchers/be.feature +6 -4
- data/features/built_in_matchers/be_within.feature +3 -1
- data/features/built_in_matchers/cover.feature +2 -0
- data/features/built_in_matchers/end_with.feature +2 -0
- data/features/built_in_matchers/equality.feature +9 -15
- data/features/built_in_matchers/exist.feature +2 -0
- data/features/built_in_matchers/expect_error.feature +14 -8
- data/features/built_in_matchers/have.feature +11 -5
- data/features/built_in_matchers/include.feature +53 -0
- data/features/built_in_matchers/match.feature +2 -0
- data/features/built_in_matchers/operators.feature +17 -11
- data/features/built_in_matchers/predicates.feature +21 -13
- data/features/built_in_matchers/respond_to.feature +7 -1
- data/features/built_in_matchers/satisfy.feature +2 -0
- data/features/built_in_matchers/start_with.feature +2 -0
- data/features/built_in_matchers/throw_symbol.feature +6 -0
- data/features/built_in_matchers/types.feature +8 -6
- data/lib/rspec/expectations/deprecation.rb +1 -1
- data/lib/rspec/expectations/differ.rb +8 -8
- data/lib/rspec/expectations/fail_with.rb +17 -3
- data/lib/rspec/expectations/syntax.rb +46 -0
- data/lib/rspec/expectations/version.rb +1 -1
- data/lib/rspec/matchers/built_in/be.rb +7 -3
- data/lib/rspec/matchers/built_in/be_within.rb +13 -4
- data/lib/rspec/matchers/built_in/change.rb +2 -2
- data/lib/rspec/matchers/built_in/equal.rb +5 -1
- data/lib/rspec/matchers/built_in/exist.rb +1 -1
- data/lib/rspec/matchers/built_in/have.rb +8 -8
- data/lib/rspec/matchers/built_in/include.rb +19 -3
- data/lib/rspec/matchers/built_in/respond_to.rb +1 -1
- data/lib/rspec/matchers/extensions/instance_eval_with_args.rb +1 -1
- data/lib/rspec/matchers/matcher.rb +4 -3
- data/lib/rspec/matchers/operator_matcher.rb +1 -1
- data/lib/rspec/matchers/pretty.rb +5 -1
- data/spec/rspec/expectations/differ_spec.rb +8 -15
- data/spec/rspec/expectations/expectation_target_spec.rb +18 -8
- data/spec/rspec/expectations/extensions/kernel_spec.rb +15 -15
- data/spec/rspec/expectations/fail_with_spec.rb +41 -16
- data/spec/rspec/expectations/handler_spec.rb +13 -13
- data/spec/rspec/expectations/syntax_spec.rb +70 -8
- data/spec/rspec/matchers/base_matcher_spec.rb +14 -12
- data/spec/rspec/matchers/be_close_spec.rb +1 -1
- data/spec/rspec/matchers/be_instance_of_spec.rb +14 -8
- data/spec/rspec/matchers/be_kind_of_spec.rb +12 -8
- data/spec/rspec/matchers/be_spec.rb +212 -148
- data/spec/rspec/matchers/be_within_spec.rb +91 -42
- data/spec/rspec/matchers/change_spec.rb +52 -38
- data/spec/rspec/matchers/configuration_spec.rb +19 -15
- data/spec/rspec/matchers/cover_spec.rb +19 -19
- data/spec/rspec/matchers/description_generation_spec.rb +86 -86
- data/spec/rspec/matchers/dsl_spec.rb +7 -7
- data/spec/rspec/matchers/eq_spec.rb +17 -11
- data/spec/rspec/matchers/eql_spec.rb +10 -10
- data/spec/rspec/matchers/equal_spec.rb +27 -9
- data/spec/rspec/matchers/exist_spec.rb +35 -21
- data/spec/rspec/matchers/has_spec.rb +33 -29
- data/spec/rspec/matchers/have_spec.rb +165 -151
- data/spec/rspec/matchers/include_matcher_integration_spec.rb +30 -0
- data/spec/rspec/matchers/include_spec.rb +282 -124
- data/spec/rspec/matchers/match_array_spec.rb +90 -49
- data/spec/rspec/matchers/match_spec.rb +21 -21
- data/spec/rspec/matchers/matcher_spec.rb +85 -48
- data/spec/rspec/matchers/matchers_spec.rb +12 -6
- data/spec/rspec/matchers/method_missing_spec.rb +5 -1
- data/spec/rspec/matchers/operator_matcher_spec.rb +216 -237
- data/spec/rspec/matchers/raise_error_spec.rb +132 -132
- data/spec/rspec/matchers/respond_to_spec.rb +109 -112
- data/spec/rspec/matchers/satisfy_spec.rb +16 -16
- data/spec/rspec/matchers/start_with_end_with_spec.rb +36 -32
- data/spec/rspec/matchers/throw_symbol_spec.rb +24 -24
- data/spec/rspec/matchers/yield_spec.rb +7 -7
- data/spec/spec_helper.rb +46 -19
- data/spec/support/in_sub_process.rb +27 -20
- metadata +81 -83
@@ -1,295 +1,292 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "expect(...).to respond_to(:sym)" do
|
4
4
|
it_behaves_like "an RSpec matcher", :valid_value => "s", :invalid_value => 5 do
|
5
5
|
let(:matcher) { respond_to(:upcase) }
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "passes if target responds to :sym" do
|
9
|
-
Object.new.
|
9
|
+
expect(Object.new).to respond_to(:methods)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "fails if target does not respond to :sym" do
|
13
|
-
|
14
|
-
"this string".
|
15
|
-
}.
|
13
|
+
expect {
|
14
|
+
expect("this string").to respond_to(:some_method)
|
15
|
+
}.to fail_with(%q|expected "this string" to respond to :some_method|)
|
16
16
|
end
|
17
|
-
|
18
17
|
end
|
19
18
|
|
20
|
-
describe "
|
19
|
+
describe "expect(...).to respond_to(:sym).with(1).argument" do
|
21
20
|
it "passes if target responds to :sym with 1 arg" do
|
22
21
|
obj = Object.new
|
23
22
|
def obj.foo(arg); end
|
24
|
-
obj.
|
23
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
25
24
|
end
|
26
25
|
|
27
26
|
it "passes if target responds to any number of arguments" do
|
28
27
|
obj = Object.new
|
29
28
|
def obj.foo(*args); end
|
30
|
-
obj.
|
29
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
31
30
|
end
|
32
31
|
|
33
32
|
it "passes if target responds to one or more arguments" do
|
34
33
|
obj = Object.new
|
35
34
|
def obj.foo(a, *args); end
|
36
|
-
obj.
|
35
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
37
36
|
end
|
38
|
-
|
37
|
+
|
39
38
|
it "fails if target does not respond to :sym" do
|
40
39
|
obj = Object.new
|
41
|
-
|
42
|
-
obj.
|
43
|
-
}.
|
40
|
+
expect {
|
41
|
+
expect(obj).to respond_to(:some_method).with(1).argument
|
42
|
+
}.to fail_with(/expected .* to respond to :some_method/)
|
44
43
|
end
|
45
|
-
|
44
|
+
|
46
45
|
it "fails if :sym expects 0 args" do
|
47
46
|
obj = Object.new
|
48
47
|
def obj.foo; end
|
49
|
-
|
50
|
-
obj.
|
51
|
-
}.
|
48
|
+
expect {
|
49
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
50
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
52
51
|
end
|
53
|
-
|
52
|
+
|
54
53
|
it "fails if :sym expects 2 args" do
|
55
54
|
obj = Object.new
|
56
55
|
def obj.foo(arg, arg2); end
|
57
|
-
|
58
|
-
obj.
|
59
|
-
}.
|
56
|
+
expect {
|
57
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
58
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
60
59
|
end
|
61
60
|
|
62
61
|
it "fails if :sym expects 2 or more args" do
|
63
62
|
obj = Object.new
|
64
63
|
def obj.foo(arg, arg2, *args); end
|
65
|
-
|
66
|
-
obj.
|
67
|
-
}.
|
64
|
+
expect {
|
65
|
+
expect(obj).to respond_to(:foo).with(1).argument
|
66
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 1 argument/)
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
71
|
-
describe "
|
72
|
-
|
70
|
+
describe "expect(...).to respond_to(message1, message2)" do
|
73
71
|
it "passes if target responds to both messages" do
|
74
|
-
Object.new.
|
72
|
+
expect(Object.new).to respond_to('methods', 'inspect')
|
75
73
|
end
|
76
|
-
|
74
|
+
|
77
75
|
it "fails if target does not respond to first message" do
|
78
|
-
|
79
|
-
Object.new.
|
80
|
-
}.
|
76
|
+
expect {
|
77
|
+
expect(Object.new).to respond_to('method_one', 'inspect')
|
78
|
+
}.to fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
81
79
|
end
|
82
|
-
|
80
|
+
|
83
81
|
it "fails if target does not respond to second message" do
|
84
|
-
|
85
|
-
Object.new.
|
86
|
-
}.
|
82
|
+
expect {
|
83
|
+
expect(Object.new).to respond_to('inspect', 'method_one')
|
84
|
+
}.to fail_with(/expected #<Object:.*> to respond to "method_one"/)
|
87
85
|
end
|
88
|
-
|
86
|
+
|
89
87
|
it "fails if target does not respond to either message" do
|
90
|
-
|
91
|
-
Object.new.
|
92
|
-
}.
|
88
|
+
expect {
|
89
|
+
expect(Object.new).to respond_to('method_one', 'method_two')
|
90
|
+
}.to fail_with(/expected #<Object:.*> to respond to "method_one", "method_two"/)
|
93
91
|
end
|
94
92
|
end
|
95
93
|
|
96
|
-
describe "
|
94
|
+
describe "expect(...).to respond_to(:sym).with(2).arguments" do
|
97
95
|
it "passes if target responds to :sym with 2 args" do
|
98
96
|
obj = Object.new
|
99
97
|
def obj.foo(a1, a2); end
|
100
|
-
obj.
|
98
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
101
99
|
end
|
102
100
|
|
103
101
|
it "passes if target responds to any number of arguments" do
|
104
102
|
obj = Object.new
|
105
103
|
def obj.foo(*args); end
|
106
|
-
obj.
|
104
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
107
105
|
end
|
108
106
|
|
109
107
|
it "passes if target responds to one or more arguments" do
|
110
108
|
obj = Object.new
|
111
109
|
def obj.foo(a, *args); end
|
112
|
-
obj.
|
110
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
113
111
|
end
|
114
112
|
|
115
113
|
it "passes if target responds to two or more arguments" do
|
116
114
|
obj = Object.new
|
117
115
|
def obj.foo(a, b, *args); end
|
118
|
-
obj.
|
116
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
119
117
|
end
|
120
|
-
|
118
|
+
|
121
119
|
it "fails if target does not respond to :sym" do
|
122
120
|
obj = Object.new
|
123
|
-
|
124
|
-
obj.
|
125
|
-
}.
|
121
|
+
expect {
|
122
|
+
expect(obj).to respond_to(:some_method).with(2).arguments
|
123
|
+
}.to fail_with(/expected .* to respond to :some_method/)
|
126
124
|
end
|
127
|
-
|
125
|
+
|
128
126
|
it "fails if :sym expects 0 args" do
|
129
127
|
obj = Object.new
|
130
128
|
def obj.foo; end
|
131
|
-
|
132
|
-
obj.
|
133
|
-
}.
|
129
|
+
expect {
|
130
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
131
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
134
132
|
end
|
135
|
-
|
133
|
+
|
136
134
|
it "fails if :sym expects 1 args" do
|
137
135
|
obj = Object.new
|
138
136
|
def obj.foo(arg); end
|
139
|
-
|
140
|
-
obj.
|
141
|
-
}.
|
137
|
+
expect {
|
138
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
139
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
142
140
|
end
|
143
141
|
|
144
142
|
it "fails if :sym expects 3 or more args" do
|
145
143
|
obj = Object.new
|
146
144
|
def obj.foo(arg, arg2, arg3, *args); end
|
147
|
-
|
148
|
-
obj.
|
149
|
-
}.
|
145
|
+
expect {
|
146
|
+
expect(obj).to respond_to(:foo).with(2).arguments
|
147
|
+
}.to fail_with(/expected #<Object.*> to respond to :foo with 2 arguments/)
|
150
148
|
end
|
151
149
|
end
|
152
150
|
|
153
|
-
describe "
|
154
|
-
|
151
|
+
describe "expect(...).to_not respond_to(:sym)" do
|
155
152
|
it "passes if target does not respond to :sym" do
|
156
|
-
Object.new.
|
153
|
+
expect(Object.new).not_to respond_to(:some_method)
|
157
154
|
end
|
158
|
-
|
155
|
+
|
159
156
|
it "fails if target responds to :sym" do
|
160
|
-
|
161
|
-
Object.new.
|
162
|
-
}.
|
157
|
+
expect {
|
158
|
+
expect(Object.new).not_to respond_to(:methods)
|
159
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :methods/)
|
163
160
|
end
|
164
|
-
|
165
161
|
end
|
166
162
|
|
167
|
-
describe "
|
163
|
+
describe "expect(...).to_not respond_to(:sym).with(1).argument" do
|
168
164
|
it "fails if target responds to :sym with 1 arg" do
|
169
165
|
obj = Object.new
|
170
166
|
def obj.foo(arg); end
|
171
|
-
|
172
|
-
obj.
|
173
|
-
}.
|
167
|
+
expect {
|
168
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
169
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
174
170
|
end
|
175
171
|
|
176
172
|
it "fails if target responds to :sym with any number of args" do
|
177
173
|
obj = Object.new
|
178
174
|
def obj.foo(*args); end
|
179
|
-
|
180
|
-
obj.
|
181
|
-
}.
|
175
|
+
expect {
|
176
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
177
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
182
178
|
end
|
183
179
|
|
184
180
|
it "fails if target responds to :sym with one or more args" do
|
185
181
|
obj = Object.new
|
186
182
|
def obj.foo(a, *args); end
|
187
|
-
|
188
|
-
obj.
|
189
|
-
}.
|
183
|
+
expect {
|
184
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
185
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :foo with 1 argument/)
|
190
186
|
end
|
191
187
|
|
192
188
|
it "passes if target does not respond to :sym" do
|
193
189
|
obj = Object.new
|
194
|
-
obj.
|
190
|
+
expect(obj).not_to respond_to(:some_method).with(1).argument
|
195
191
|
end
|
196
192
|
|
197
193
|
it "passes if :sym expects 0 args" do
|
198
194
|
obj = Object.new
|
199
195
|
def obj.foo; end
|
200
|
-
obj.
|
196
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
201
197
|
end
|
202
198
|
|
203
199
|
it "passes if :sym expects 2 args" do
|
204
200
|
obj = Object.new
|
205
201
|
def obj.foo(arg, arg2); end
|
206
|
-
obj.
|
202
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
207
203
|
end
|
208
204
|
|
209
205
|
it "passes if :sym expects 2 or more args" do
|
210
206
|
obj = Object.new
|
211
207
|
def obj.foo(arg, arg2, *args); end
|
212
|
-
obj.
|
208
|
+
expect(obj).not_to respond_to(:foo).with(1).argument
|
213
209
|
end
|
214
210
|
end
|
215
211
|
|
216
|
-
describe "
|
212
|
+
describe "expect(...).to_not respond_to(message1, message2)" do
|
217
213
|
it "passes if target does not respond to either message1 or message2" do
|
218
|
-
Object.new.
|
214
|
+
expect(Object.new).not_to respond_to(:some_method, :some_other_method)
|
219
215
|
end
|
220
216
|
|
221
217
|
it "fails if target responds to message1 but not message2" do
|
222
|
-
|
223
|
-
Object.new.
|
224
|
-
}.
|
218
|
+
expect {
|
219
|
+
expect(Object.new).not_to respond_to(:object_id, :some_method)
|
220
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
225
221
|
end
|
226
222
|
|
227
223
|
it "fails if target responds to message2 but not message1" do
|
228
|
-
|
229
|
-
Object.new.
|
230
|
-
}.
|
224
|
+
expect {
|
225
|
+
expect(Object.new).not_to respond_to(:some_method, :object_id)
|
226
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :object_id/)
|
231
227
|
end
|
232
228
|
|
233
229
|
it "fails if target responds to both message1 and message2" do
|
234
|
-
|
235
|
-
Object.new.
|
236
|
-
}.
|
230
|
+
expect {
|
231
|
+
expect(Object.new).not_to respond_to(:class, :object_id)
|
232
|
+
}.to fail_with(/expected #<Object:.*> not to respond to :class, :object_id/)
|
237
233
|
end
|
238
234
|
end
|
239
235
|
|
240
|
-
describe "
|
236
|
+
describe "expect(...).to_not respond_to(:sym).with(2).arguments" do
|
241
237
|
it "fails if target responds to :sym with 2 args" do
|
242
238
|
obj = Object.new
|
243
239
|
def obj.foo(a1, a2); end
|
244
|
-
|
245
|
-
obj.
|
246
|
-
}.
|
240
|
+
expect {
|
241
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
242
|
+
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
247
243
|
end
|
248
244
|
|
249
245
|
it "fails if target responds to :sym with any number args" do
|
250
246
|
obj = Object.new
|
251
247
|
def obj.foo(*args); end
|
252
|
-
|
253
|
-
obj.
|
254
|
-
}.
|
248
|
+
expect {
|
249
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
250
|
+
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
255
251
|
end
|
256
252
|
|
257
253
|
it "fails if target responds to :sym with one or more args" do
|
258
254
|
obj = Object.new
|
259
255
|
def obj.foo(a, *args); end
|
260
|
-
|
261
|
-
obj.
|
262
|
-
}.
|
256
|
+
expect {
|
257
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
258
|
+
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
263
259
|
end
|
264
260
|
|
265
261
|
it "fails if target responds to :sym with two or more args" do
|
266
262
|
obj = Object.new
|
267
263
|
def obj.foo(a, b, *args); end
|
268
|
-
|
269
|
-
obj.
|
270
|
-
}.
|
264
|
+
expect {
|
265
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
266
|
+
}.to fail_with(/expected .* not to respond to :foo with 2 arguments/)
|
271
267
|
end
|
272
268
|
|
273
269
|
it "passes if target does not respond to :sym" do
|
274
270
|
obj = Object.new
|
275
|
-
obj.
|
271
|
+
expect(obj).not_to respond_to(:some_method).with(2).arguments
|
276
272
|
end
|
277
273
|
|
278
274
|
it "passes if :sym expects 0 args" do
|
279
275
|
obj = Object.new
|
280
276
|
def obj.foo; end
|
281
|
-
obj.
|
277
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
282
278
|
end
|
283
279
|
|
284
280
|
it "passes if :sym expects 2 args" do
|
285
281
|
obj = Object.new
|
286
282
|
def obj.foo(arg); end
|
287
|
-
obj.
|
283
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
288
284
|
end
|
289
285
|
|
290
286
|
it "passes if :sym expects 3 or more args" do
|
291
287
|
obj = Object.new
|
292
288
|
def obj.foo(a, b, c, *arg); end
|
293
|
-
obj.
|
289
|
+
expect(obj).not_to respond_to(:foo).with(2).arguments
|
294
290
|
end
|
295
291
|
end
|
292
|
+
|
@@ -1,44 +1,44 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "
|
3
|
+
describe "expect(...).to satisfy { block }" do
|
4
4
|
it_behaves_like "an RSpec matcher", :valid_value => true, :invalid_value => false do
|
5
5
|
let(:matcher) { satisfy { |v| v } }
|
6
6
|
end
|
7
7
|
|
8
8
|
it "describes itself" do
|
9
|
-
satisfy.description.
|
9
|
+
expect(satisfy.description).to eq("satisfy block")
|
10
10
|
end
|
11
11
|
|
12
12
|
it "passes if block returns true" do
|
13
|
-
true.
|
14
|
-
true.
|
13
|
+
expect(true).to satisfy { |val| val }
|
14
|
+
expect(true).to satisfy do |val|
|
15
15
|
val
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
it "fails if block returns false" do
|
20
|
-
|
21
|
-
false.
|
22
|
-
}.
|
23
|
-
|
24
|
-
false.
|
20
|
+
expect {
|
21
|
+
expect(false).to satisfy { |val| val }
|
22
|
+
}.to fail_with("expected false to satisfy block")
|
23
|
+
expect do
|
24
|
+
expect(false).to satisfy do |val|
|
25
25
|
val
|
26
26
|
end
|
27
|
-
end.
|
27
|
+
end.to fail_with("expected false to satisfy block")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe "
|
31
|
+
describe "expect(...).to_not satisfy { block }" do
|
32
32
|
it "passes if block returns false" do
|
33
|
-
false.
|
34
|
-
false.
|
33
|
+
expect(false).not_to satisfy { |val| val }
|
34
|
+
expect(false).not_to satisfy do |val|
|
35
35
|
val
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
it "fails if block returns true" do
|
40
|
-
|
41
|
-
true.
|
42
|
-
}.
|
40
|
+
expect {
|
41
|
+
expect(true).not_to satisfy { |val| val }
|
42
|
+
}.to fail_with("expected true not to satisfy block")
|
43
43
|
end
|
44
44
|
end
|