transpec 1.3.1 → 1.4.0
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/.rubocop.yml +1 -1
- data/.travis.yml +1 -3
- data/CHANGELOG.md +9 -0
- data/README.md +141 -24
- data/README.md.erb +136 -24
- data/lib/transpec/ast/node.rb +7 -3
- data/lib/transpec/cli.rb +1 -1
- data/lib/transpec/configuration.rb +1 -0
- data/lib/transpec/converter.rb +31 -2
- data/lib/transpec/dynamic_analyzer.rb +1 -1
- data/lib/transpec/option_parser.rb +12 -9
- data/lib/transpec/project.rb +23 -12
- data/lib/transpec/rspec_version.rb +18 -4
- data/lib/transpec/static_context_inspector.rb +0 -15
- data/lib/transpec/syntax/example.rb +83 -0
- data/lib/transpec/syntax/expect.rb +5 -0
- data/lib/transpec/syntax/have.rb +111 -54
- data/lib/transpec/syntax/method_stub.rb +58 -37
- data/lib/transpec/syntax/mixin/allow_no_message.rb +2 -0
- data/lib/transpec/syntax/mixin/any_instance.rb +2 -0
- data/lib/transpec/syntax/mixin/should_base.rb +39 -0
- data/lib/transpec/syntax/oneliner_should.rb +218 -0
- data/lib/transpec/syntax/operator_matcher.rb +1 -0
- data/lib/transpec/syntax/should.rb +3 -30
- data/lib/transpec/util.rb +54 -0
- data/lib/transpec/version.rb +2 -2
- data/spec/support/shared_context.rb +21 -29
- data/spec/transpec/ast/node_spec.rb +1 -1
- data/spec/transpec/commit_message_spec.rb +29 -23
- data/spec/transpec/configuration_spec.rb +1 -0
- data/spec/transpec/converter_spec.rb +208 -5
- data/spec/transpec/dynamic_analyzer_spec.rb +2 -2
- data/spec/transpec/option_parser_spec.rb +1 -0
- data/spec/transpec/project_spec.rb +10 -0
- data/spec/transpec/rspec_version_spec.rb +52 -28
- data/spec/transpec/static_context_inspector_spec.rb +2 -2
- data/spec/transpec/syntax/be_boolean_spec.rb +6 -13
- data/spec/transpec/syntax/be_close_spec.rb +2 -9
- data/spec/transpec/syntax/double_spec.rb +2 -9
- data/spec/transpec/syntax/example_spec.rb +249 -0
- data/spec/transpec/syntax/expect_spec.rb +1 -1
- data/spec/transpec/syntax/have_spec.rb +127 -22
- data/spec/transpec/syntax/its_spec.rb +9 -18
- data/spec/transpec/syntax/method_stub_spec.rb +193 -158
- data/spec/transpec/syntax/oneliner_should_spec.rb +653 -0
- data/spec/transpec/syntax/operator_matcher_spec.rb +7 -8
- data/spec/transpec/syntax/raise_error_spec.rb +6 -13
- data/spec/transpec/syntax/rspec_configure_spec.rb +1 -8
- data/spec/transpec/syntax/should_receive_spec.rb +19 -28
- data/spec/transpec/syntax/should_spec.rb +18 -16
- data/spec/transpec/util_spec.rb +30 -0
- data/transpec.gemspec +8 -7
- metadata +49 -28
@@ -0,0 +1,653 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'transpec/syntax/oneliner_should'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
class Syntax
|
8
|
+
describe OnelinerShould do
|
9
|
+
include_context 'parsed objects'
|
10
|
+
include_context 'syntax object', OnelinerShould, :should_object
|
11
|
+
|
12
|
+
let(:record) { should_object.report.records.first }
|
13
|
+
|
14
|
+
describe '#matcher_node' do
|
15
|
+
context 'when it is taking operator matcher' do
|
16
|
+
let(:source) do
|
17
|
+
<<-END
|
18
|
+
describe 'example' do
|
19
|
+
it { should == 1 }
|
20
|
+
end
|
21
|
+
END
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'returns its parent node' do
|
25
|
+
should_object.parent_node.children[1].should == :==
|
26
|
+
should_object.matcher_node.should == should_object.parent_node
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'when it is taking non-operator matcher without argument' do
|
31
|
+
let(:source) do
|
32
|
+
<<-END
|
33
|
+
describe 'example' do
|
34
|
+
it { should be_empty }
|
35
|
+
end
|
36
|
+
END
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'returns its argument node' do
|
40
|
+
should_object.arg_node.children[1].should == :be_empty
|
41
|
+
should_object.matcher_node.should == should_object.arg_node
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when it is taking non-operator matcher with argument' do
|
46
|
+
let(:source) do
|
47
|
+
<<-END
|
48
|
+
describe 'example' do
|
49
|
+
it { should eq(1) }
|
50
|
+
end
|
51
|
+
END
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns its argument node' do
|
55
|
+
should_object.arg_node.children[1].should == :eq
|
56
|
+
should_object.matcher_node.should == should_object.arg_node
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#operator_matcher' do
|
62
|
+
subject { should_object.operator_matcher }
|
63
|
+
|
64
|
+
context 'when it is taking operator matcher' do
|
65
|
+
let(:source) do
|
66
|
+
<<-END
|
67
|
+
describe 'example' do
|
68
|
+
it { should == 1 }
|
69
|
+
end
|
70
|
+
END
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'returns an instance of OperatorMatcher' do
|
74
|
+
should be_an(OperatorMatcher)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when it is taking non-operator matcher' do
|
79
|
+
let(:source) do
|
80
|
+
<<-END
|
81
|
+
describe 'example' do
|
82
|
+
it { should be_empty }
|
83
|
+
end
|
84
|
+
END
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'returns nil' do
|
88
|
+
should be_nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#have_matcher' do
|
94
|
+
subject { should_object.have_matcher }
|
95
|
+
|
96
|
+
context 'when it is taking #have matcher' do
|
97
|
+
let(:source) do
|
98
|
+
<<-END
|
99
|
+
describe 'example' do
|
100
|
+
it { should have(2).items }
|
101
|
+
end
|
102
|
+
END
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns an instance of Have' do
|
106
|
+
should be_an(Have)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when it is taking operator matcher' do
|
111
|
+
let(:source) do
|
112
|
+
<<-END
|
113
|
+
describe 'example' do
|
114
|
+
it { should == 1 }
|
115
|
+
end
|
116
|
+
END
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'returns nil' do
|
120
|
+
should be_nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'when it is taking any other non-operator matcher' do
|
125
|
+
let(:source) do
|
126
|
+
<<-END
|
127
|
+
describe 'example' do
|
128
|
+
it { should be_empty }
|
129
|
+
end
|
130
|
+
END
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'returns nil' do
|
134
|
+
should be_nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#expectize!' do
|
140
|
+
context 'when it has an operator matcher' do
|
141
|
+
let(:source) do
|
142
|
+
<<-END
|
143
|
+
describe 'example' do
|
144
|
+
it { should == 1 }
|
145
|
+
end
|
146
|
+
END
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'invokes OperatorMatcher#convert_operator!' do
|
150
|
+
should_object.operator_matcher.should_receive(:convert_operator!)
|
151
|
+
should_object.expectize!
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when it is `it { should be true }` form' do
|
156
|
+
let(:source) do
|
157
|
+
<<-END
|
158
|
+
describe 'example' do
|
159
|
+
it { should be true }
|
160
|
+
end
|
161
|
+
END
|
162
|
+
end
|
163
|
+
|
164
|
+
let(:expected_source) do
|
165
|
+
<<-END
|
166
|
+
describe 'example' do
|
167
|
+
it { is_expected.to be true }
|
168
|
+
end
|
169
|
+
END
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'converts into `it { is_expected.to be true }` form' do
|
173
|
+
should_object.expectize!
|
174
|
+
rewritten_source.should == expected_source
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'adds record `it { should ... }` -> `it { is_expected.to ... }`' do
|
178
|
+
should_object.expectize!
|
179
|
+
record.original_syntax.should == 'it { should ... }'
|
180
|
+
record.converted_syntax.should == 'it { is_expected.to ... }'
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'when it is `it { should() == 1 }` form' do
|
185
|
+
let(:source) do
|
186
|
+
<<-END
|
187
|
+
describe 'example' do
|
188
|
+
it { should() == 1 }
|
189
|
+
end
|
190
|
+
END
|
191
|
+
end
|
192
|
+
|
193
|
+
let(:expected_source) do
|
194
|
+
<<-END
|
195
|
+
describe 'example' do
|
196
|
+
it { is_expected.to eq(1) }
|
197
|
+
end
|
198
|
+
END
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'converts into `it { is_expected.to eq(1) }` form' do
|
202
|
+
should_object.expectize!
|
203
|
+
rewritten_source.should == expected_source
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
shared_examples 'does not convert if project requires have(n).items matcher' do
|
209
|
+
context 'when rspec-rails is loaded in the spec' do
|
210
|
+
include_context 'dynamic analysis objects'
|
211
|
+
|
212
|
+
let(:source) do
|
213
|
+
<<-END
|
214
|
+
module RSpec
|
215
|
+
module Rails
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
describe [:foo, :bar] do
|
220
|
+
it { should have(2).items }
|
221
|
+
end
|
222
|
+
END
|
223
|
+
end
|
224
|
+
|
225
|
+
it 'does nothing' do
|
226
|
+
rewritten_source.should == source
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when rspec-collection_matchers is loaded in the spec' do
|
231
|
+
include_context 'dynamic analysis objects'
|
232
|
+
|
233
|
+
let(:source) do
|
234
|
+
<<-END
|
235
|
+
module RSpec
|
236
|
+
module CollectionMatchers
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
describe [:foo, :bar] do
|
241
|
+
it { should have(2).items }
|
242
|
+
end
|
243
|
+
END
|
244
|
+
end
|
245
|
+
|
246
|
+
let(:have_object) { should_object.have_matcher }
|
247
|
+
|
248
|
+
it 'does nothing' do
|
249
|
+
rewritten_source.should == source
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe '#convert_have_items_to_standard_should!' do
|
255
|
+
before do
|
256
|
+
should_object.convert_have_items_to_standard_should!
|
257
|
+
end
|
258
|
+
|
259
|
+
include_examples 'does not convert if project requires have(n).items matcher'
|
260
|
+
|
261
|
+
context 'when it is `it { should have(2).items }` form' do
|
262
|
+
let(:source) do
|
263
|
+
<<-END
|
264
|
+
describe 'example' do
|
265
|
+
it { should have(2).items }
|
266
|
+
end
|
267
|
+
END
|
268
|
+
end
|
269
|
+
|
270
|
+
let(:expected_source) do
|
271
|
+
<<-END
|
272
|
+
describe 'example' do
|
273
|
+
it 'has 2 items' do
|
274
|
+
subject.size.should == 2
|
275
|
+
end
|
276
|
+
end
|
277
|
+
END
|
278
|
+
end
|
279
|
+
|
280
|
+
it "converts into `it 'has 2 items' do subject.size.should == 2 end` form" do
|
281
|
+
rewritten_source.should == expected_source
|
282
|
+
end
|
283
|
+
|
284
|
+
it 'adds record ' +
|
285
|
+
'`it { should have(n).items }` -> `it \'has n items\' do subject.size.should == n end`' do
|
286
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
287
|
+
record.converted_syntax.should == "it 'has n items' do subject.size.should == n end"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'when it is `it { should_not have(2).items }` form' do
|
292
|
+
let(:source) do
|
293
|
+
<<-END
|
294
|
+
describe 'example' do
|
295
|
+
it { should_not have(2).items }
|
296
|
+
end
|
297
|
+
END
|
298
|
+
end
|
299
|
+
|
300
|
+
let(:expected_source) do
|
301
|
+
<<-END
|
302
|
+
describe 'example' do
|
303
|
+
it 'does not have 2 items' do
|
304
|
+
subject.size.should_not == 2
|
305
|
+
end
|
306
|
+
end
|
307
|
+
END
|
308
|
+
end
|
309
|
+
|
310
|
+
it "converts into `it 'does not have 2 items' do subject.size.should_not == 2 end` form" do
|
311
|
+
rewritten_source.should == expected_source
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'adds record `it { should_not have(n).items }`' +
|
315
|
+
' -> `it \'does not have n items\' do subject.size.should_not == n end`' do
|
316
|
+
record.original_syntax.should == 'it { should_not have(n).items }'
|
317
|
+
record.converted_syntax.should == "it 'does not have n items' do subject.size.should_not == n end"
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context 'when it is `it { should have(1).items }` form' do
|
322
|
+
let(:source) do
|
323
|
+
<<-END
|
324
|
+
describe 'example' do
|
325
|
+
it { should have(1).items }
|
326
|
+
end
|
327
|
+
END
|
328
|
+
end
|
329
|
+
|
330
|
+
let(:expected_source) do
|
331
|
+
<<-END
|
332
|
+
describe 'example' do
|
333
|
+
it 'has 1 item' do
|
334
|
+
subject.size.should == 1
|
335
|
+
end
|
336
|
+
end
|
337
|
+
END
|
338
|
+
end
|
339
|
+
|
340
|
+
it "converts into `it 'has 1 item' do subject.size.should == 1 end` form" do
|
341
|
+
rewritten_source.should == expected_source
|
342
|
+
end
|
343
|
+
|
344
|
+
it 'adds record ' +
|
345
|
+
'`it { should have(n).items }` -> `it \'has n items\' do subject.size.should == n end`' do
|
346
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
347
|
+
record.converted_syntax.should == "it 'has n items' do subject.size.should == n end"
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
context 'when it is `it { should have(0).items }` form' do
|
352
|
+
let(:source) do
|
353
|
+
<<-END
|
354
|
+
describe 'example' do
|
355
|
+
it { should have(0).items }
|
356
|
+
end
|
357
|
+
END
|
358
|
+
end
|
359
|
+
|
360
|
+
let(:expected_source) do
|
361
|
+
<<-END
|
362
|
+
describe 'example' do
|
363
|
+
it 'has no items' do
|
364
|
+
subject.size.should == 0
|
365
|
+
end
|
366
|
+
end
|
367
|
+
END
|
368
|
+
end
|
369
|
+
|
370
|
+
it "converts into `it 'has no items' do subject.size.should == 0 end` form" do
|
371
|
+
rewritten_source.should == expected_source
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'adds record ' +
|
375
|
+
'`it { should have(n).items }` -> `it \'has n items\' do subject.size.should == n end`' do
|
376
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
377
|
+
record.converted_syntax.should == "it 'has n items' do subject.size.should == n end"
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context 'when it is `it { should have(variable).items }` form' do
|
382
|
+
let(:source) do
|
383
|
+
<<-END
|
384
|
+
describe 'example' do
|
385
|
+
it { should have(number_of).items }
|
386
|
+
end
|
387
|
+
END
|
388
|
+
end
|
389
|
+
|
390
|
+
let(:expected_source) do
|
391
|
+
<<-END
|
392
|
+
describe 'example' do
|
393
|
+
it 'has number_of items' do
|
394
|
+
subject.size.should == number_of
|
395
|
+
end
|
396
|
+
end
|
397
|
+
END
|
398
|
+
end
|
399
|
+
|
400
|
+
it "converts into `it 'has variable items' do subject.size.should == variable end` form" do
|
401
|
+
rewritten_source.should == expected_source
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'adds record ' +
|
405
|
+
'`it { should have(n).items }` -> `it \'has n items\' do subject.size.should == n end`' do
|
406
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
407
|
+
record.converted_syntax.should == "it 'has n items' do subject.size.should == n end"
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context 'when it is `it { should_not have(0).items }` form' do
|
412
|
+
let(:source) do
|
413
|
+
<<-END
|
414
|
+
describe 'example' do
|
415
|
+
it { should_not have(0).items }
|
416
|
+
end
|
417
|
+
END
|
418
|
+
end
|
419
|
+
|
420
|
+
let(:expected_source) do
|
421
|
+
<<-END
|
422
|
+
describe 'example' do
|
423
|
+
it 'does not have 0 items' do
|
424
|
+
subject.size.should_not == 0
|
425
|
+
end
|
426
|
+
end
|
427
|
+
END
|
428
|
+
end
|
429
|
+
|
430
|
+
it "converts into `it 'does not have 0 items' do subject.size.should_not == 0 end` form" do
|
431
|
+
rewritten_source.should == expected_source
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'adds record `it { should_not have(n).items }`' +
|
435
|
+
' -> `it \'does not have n items\' do subject.size.should_not == n end`' do
|
436
|
+
record.original_syntax.should == 'it { should_not have(n).items }'
|
437
|
+
record.converted_syntax.should == "it 'does not have n items' do subject.size.should_not == n end"
|
438
|
+
end
|
439
|
+
end
|
440
|
+
|
441
|
+
context 'when it is multiline `it { should have(2).items }` form' do
|
442
|
+
let(:source) do
|
443
|
+
<<-END
|
444
|
+
describe 'example' do
|
445
|
+
it {
|
446
|
+
should have(2).items
|
447
|
+
}
|
448
|
+
end
|
449
|
+
END
|
450
|
+
end
|
451
|
+
|
452
|
+
let(:expected_source) do
|
453
|
+
<<-END
|
454
|
+
describe 'example' do
|
455
|
+
it 'has 2 items' {
|
456
|
+
subject.size.should == 2
|
457
|
+
}
|
458
|
+
end
|
459
|
+
END
|
460
|
+
end
|
461
|
+
|
462
|
+
it "converts into `it 'has 2 items' { subject.size.should == 2 }` form" do
|
463
|
+
rewritten_source.should == expected_source
|
464
|
+
end
|
465
|
+
|
466
|
+
it 'adds record ' +
|
467
|
+
'`it { should have(n).items }` -> `it \'has n items\' do subject.size.should == n end`' do
|
468
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
469
|
+
record.converted_syntax.should == "it 'has n items' do subject.size.should == n end"
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
context "when it is `it 'has 2 items' do should have(2).items end` form" do
|
474
|
+
let(:source) do
|
475
|
+
<<-END
|
476
|
+
describe 'example' do
|
477
|
+
it 'has 2 items' do
|
478
|
+
should have(2).items
|
479
|
+
end
|
480
|
+
end
|
481
|
+
END
|
482
|
+
end
|
483
|
+
|
484
|
+
let(:expected_source) do
|
485
|
+
<<-END
|
486
|
+
describe 'example' do
|
487
|
+
it 'has 2 items' do
|
488
|
+
subject.size.should == 2
|
489
|
+
end
|
490
|
+
end
|
491
|
+
END
|
492
|
+
end
|
493
|
+
|
494
|
+
it "converts into `it 'has 2 items' do subject.size.should == 2 end` form" do
|
495
|
+
rewritten_source.should == expected_source
|
496
|
+
end
|
497
|
+
|
498
|
+
it 'adds record ' +
|
499
|
+
'`it \'...\' { should have(n).items }` -> `it \'...\' do subject.size.should == n end`' do
|
500
|
+
record.original_syntax.should == "it '...' do should have(n).items end"
|
501
|
+
record.converted_syntax.should == "it '...' do subject.size.should == n end"
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
context 'when it is `it { should have_at_least(2).items }` form' do
|
506
|
+
let(:source) do
|
507
|
+
<<-END
|
508
|
+
describe 'example' do
|
509
|
+
it { should have_at_least(2).items }
|
510
|
+
end
|
511
|
+
END
|
512
|
+
end
|
513
|
+
|
514
|
+
let(:expected_source) do
|
515
|
+
<<-END
|
516
|
+
describe 'example' do
|
517
|
+
it 'has at least 2 items' do
|
518
|
+
subject.size.should >= 2
|
519
|
+
end
|
520
|
+
end
|
521
|
+
END
|
522
|
+
end
|
523
|
+
|
524
|
+
it "converts into `it 'has at least 2 items' do subject.size.should >= 2 end` form" do
|
525
|
+
rewritten_source.should == expected_source
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'adds record `it { should have_at_least(n).items }` ' +
|
529
|
+
'-> `it \'has at least n items\' do subject.size.should >= n end`' do
|
530
|
+
record.original_syntax.should == 'it { should have_at_least(n).items }'
|
531
|
+
record.converted_syntax.should == "it 'has at least n items' do subject.size.should >= n end"
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
context 'when it is `it { should have(2).words }` form' do
|
536
|
+
context 'with runtime information' do
|
537
|
+
include_context 'dynamic analysis objects'
|
538
|
+
|
539
|
+
context 'when the subject responds to #words and #words responds to #size' do
|
540
|
+
let(:source) do
|
541
|
+
<<-END
|
542
|
+
class String
|
543
|
+
def words
|
544
|
+
split(' ')
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe 'a string' do
|
549
|
+
it { should have(2).words }
|
550
|
+
end
|
551
|
+
END
|
552
|
+
end
|
553
|
+
|
554
|
+
let(:expected_source) do
|
555
|
+
<<-END
|
556
|
+
class String
|
557
|
+
def words
|
558
|
+
split(' ')
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
describe 'a string' do
|
563
|
+
it 'has 2 words' do
|
564
|
+
subject.words.size.should == 2
|
565
|
+
end
|
566
|
+
end
|
567
|
+
END
|
568
|
+
end
|
569
|
+
|
570
|
+
it "converts into `it 'has 2 words' do subject.words.size.should == 2 end` form" do
|
571
|
+
rewritten_source.should == expected_source
|
572
|
+
end
|
573
|
+
|
574
|
+
it 'adds record `it { should have(n).words }` ' +
|
575
|
+
'-> `it \'has n words\' do subject.words.size.should == n end`' do
|
576
|
+
record.original_syntax.should == 'it { should have(n).words }'
|
577
|
+
record.converted_syntax.should == "it 'has n words' do subject.words.size.should == n end"
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|
581
|
+
end
|
582
|
+
end
|
583
|
+
|
584
|
+
describe '#convert_have_items_to_standard_expect!' do
|
585
|
+
before do
|
586
|
+
should_object.convert_have_items_to_standard_expect!
|
587
|
+
end
|
588
|
+
|
589
|
+
include_examples 'does not convert if project requires have(n).items matcher'
|
590
|
+
|
591
|
+
context 'when it is `it { should have(2).items }` form' do
|
592
|
+
let(:source) do
|
593
|
+
<<-END
|
594
|
+
describe 'example' do
|
595
|
+
it { should have(2).items }
|
596
|
+
end
|
597
|
+
END
|
598
|
+
end
|
599
|
+
|
600
|
+
let(:expected_source) do
|
601
|
+
<<-END
|
602
|
+
describe 'example' do
|
603
|
+
it 'has 2 items' do
|
604
|
+
expect(subject.size).to eq(2)
|
605
|
+
end
|
606
|
+
end
|
607
|
+
END
|
608
|
+
end
|
609
|
+
|
610
|
+
it "converts into `it 'has 2 items' do expect(subject.size).to eq(2) end` form" do
|
611
|
+
rewritten_source.should == expected_source
|
612
|
+
end
|
613
|
+
|
614
|
+
it 'adds record ' +
|
615
|
+
'`it { should have(n).items }` -> `it \'has n items\' do expect(subject.size).to eq(n) end`' do
|
616
|
+
record.original_syntax.should == 'it { should have(n).items }'
|
617
|
+
record.converted_syntax.should == "it 'has n items' do expect(subject.size).to eq(n) end"
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
context 'when it is `it { should_not have(2).items }` form' do
|
622
|
+
let(:source) do
|
623
|
+
<<-END
|
624
|
+
describe 'example' do
|
625
|
+
it { should_not have(2).items }
|
626
|
+
end
|
627
|
+
END
|
628
|
+
end
|
629
|
+
|
630
|
+
let(:expected_source) do
|
631
|
+
<<-END
|
632
|
+
describe 'example' do
|
633
|
+
it 'does not have 2 items' do
|
634
|
+
expect(subject.size).not_to eq(2)
|
635
|
+
end
|
636
|
+
end
|
637
|
+
END
|
638
|
+
end
|
639
|
+
|
640
|
+
it "converts into `it 'does not have 2 items' do expect(subject.size).not_to eq(2) end` form" do
|
641
|
+
rewritten_source.should == expected_source
|
642
|
+
end
|
643
|
+
|
644
|
+
it 'adds record `it { should_not have(n).items }`' +
|
645
|
+
' -> `it \'does not have n items\' do expect(subject.size).not_to eq(n) end`' do
|
646
|
+
record.original_syntax.should == 'it { should_not have(n).items }'
|
647
|
+
record.converted_syntax.should == "it 'does not have n items' do expect(subject.size).not_to eq(n) end"
|
648
|
+
end
|
649
|
+
end
|
650
|
+
end
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|