transpec 1.13.1 → 2.0.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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/README.md +63 -22
  5. data/README.md.erb +55 -16
  6. data/lib/transpec/cli.rb +9 -9
  7. data/lib/transpec/commit_message.rb +2 -0
  8. data/lib/transpec/{configuration.rb → config.rb} +7 -6
  9. data/lib/transpec/converter.rb +57 -46
  10. data/lib/transpec/option_parser.rb +23 -25
  11. data/lib/transpec/rspec_version.rb +6 -0
  12. data/lib/transpec/spec_suite.rb +2 -6
  13. data/lib/transpec/syntax/example.rb +2 -15
  14. data/lib/transpec/syntax/example_group.rb +111 -9
  15. data/lib/transpec/syntax/have/dynamic_analysis.rb +1 -1
  16. data/lib/transpec/syntax/mixin/metadata.rb +29 -0
  17. data/lib/transpec/syntax/mixin/rspec_rails.rb +27 -0
  18. data/lib/transpec/syntax/rspec_configure.rb +14 -3
  19. data/lib/transpec/syntax/rspec_configure/{configuration_modification.rb → config_modification.rb} +18 -15
  20. data/lib/transpec/syntax/rspec_configure/framework.rb +7 -7
  21. data/lib/transpec/syntax/rspec_configure/mocks.rb +1 -1
  22. data/lib/transpec/version.rb +3 -3
  23. data/spec/transpec/commit_message_spec.rb +9 -1
  24. data/spec/transpec/{configuration_spec.rb → config_spec.rb} +19 -18
  25. data/spec/transpec/converter_spec.rb +245 -210
  26. data/spec/transpec/option_parser_spec.rb +27 -59
  27. data/spec/transpec/rspec_version_spec.rb +26 -0
  28. data/spec/transpec/syntax/example_group_spec.rb +277 -0
  29. data/spec/transpec/syntax/have_spec.rb +1 -1
  30. data/spec/transpec/syntax/rspec_configure_spec.rb +117 -0
  31. data/tasks/fixtures/guard/2.99.0/COMMIT_EDITMSG +3 -1
  32. data/tasks/fixtures/guard/3.0.0/COMMIT_EDITMSG +3 -1
  33. data/tasks/fixtures/mail/2.99.0/COMMIT_EDITMSG +3 -1
  34. data/tasks/fixtures/mail/3.0.0/COMMIT_EDITMSG +3 -1
  35. data/tasks/fixtures/twitter/2.99.0/COMMIT_EDITMSG +3 -1
  36. data/tasks/fixtures/twitter/3.0.0/COMMIT_EDITMSG +3 -1
  37. data/tasks/readme.rake +3 -2
  38. metadata +8 -6
@@ -5,8 +5,8 @@ require 'transpec/option_parser'
5
5
 
6
6
  module Transpec
7
7
  describe OptionParser do
8
- subject(:parser) { OptionParser.new(configuration) }
9
- let(:configuration) { Configuration.new }
8
+ subject(:parser) { OptionParser.new(config) }
9
+ let(:config) { Config.new }
10
10
 
11
11
  describe '#parse' do
12
12
  subject { parser.parse(args) }
@@ -24,38 +24,18 @@ module Transpec
24
24
  describe '-f/--force option' do
25
25
  let(:args) { ['--force'] }
26
26
 
27
- it 'sets Configuration#forced? true' do
27
+ it 'sets Config#forced? true' do
28
28
  parser.parse(args)
29
- configuration.forced?.should be_true
29
+ config.forced?.should be_true
30
30
  end
31
31
  end
32
32
 
33
33
  describe '-s/--skip-dynamic-analysis option' do
34
34
  let(:args) { ['--skip-dynamic-analysis'] }
35
35
 
36
- it 'sets Configuration#skip_dynamic_analysis? true' do
36
+ it 'sets Config#skip_dynamic_analysis? true' do
37
37
  parser.parse(args)
38
- configuration.skip_dynamic_analysis?.should be_true
39
- end
40
- end
41
-
42
- describe '-m/--generate-commit-message option' do
43
- let(:args) { ['--generate-commit-message'] }
44
-
45
- before do
46
- parser.stub(:warn)
47
- end
48
-
49
- it 'is deprecated' do
50
- parser.should_receive(:warn) do |message|
51
- message.should =~ /--generate-commit-message.+deprecated/i
52
- end
53
-
54
- parser.parse(args)
55
- end
56
-
57
- it 'does not raise error' do
58
- -> { parser.parse(args) }.should_not raise_error
38
+ config.skip_dynamic_analysis?.should be_true
59
39
  end
60
40
  end
61
41
 
@@ -73,9 +53,9 @@ module Transpec
73
53
  context "when #{cli_type.inspect} is specified" do
74
54
  let(:args) { ['--keep', cli_type] }
75
55
 
76
- it "sets Configuration##{config_attr} false" do
56
+ it "sets Config##{config_attr} false" do
77
57
  parser.parse(args)
78
- configuration.send(config_attr).should be_false
58
+ config.send(config_attr).should be_false
79
59
  end
80
60
  end
81
61
  end
@@ -85,8 +65,8 @@ module Transpec
85
65
 
86
66
  it 'handles all of them' do
87
67
  parser.parse(args)
88
- configuration.convert_should_receive?.should be_false
89
- configuration.convert_deprecated_method?.should be_false
68
+ config.convert_should_receive?.should be_false
69
+ config.convert_deprecated_method?.should be_false
90
70
  end
91
71
  end
92
72
 
@@ -110,9 +90,9 @@ module Transpec
110
90
  context "when #{cli_type.inspect} is specified" do
111
91
  let(:args) { ['--convert', cli_type] }
112
92
 
113
- it "sets Configuration##{config_attr} true" do
93
+ it "sets Config##{config_attr} true" do
114
94
  parser.parse(args)
115
- configuration.send(config_attr).should be_true
95
+ config.send(config_attr).should be_true
116
96
  end
117
97
  end
118
98
  end
@@ -133,9 +113,9 @@ module Transpec
133
113
  context "when #{form.inspect} is specified" do
134
114
  let(:args) { ['--negative-form', form] }
135
115
 
136
- it "sets Configuration#negative_form_of_to #{form.inspect}" do
116
+ it "sets Config#negative_form_of_to #{form.inspect}" do
137
117
  parser.parse(args)
138
- configuration.negative_form_of_to.should == form
118
+ config.negative_form_of_to.should == form
139
119
  end
140
120
  end
141
121
  end
@@ -146,18 +126,18 @@ module Transpec
146
126
  ['truthy,falsey', :conditional, 'be_falsey'],
147
127
  ['truthy,falsy', :conditional, 'be_falsy'],
148
128
  ['true,false', :exact, 'be_falsey']
149
- ].each do |cli_type, configuration_type, form_of_be_falsey|
129
+ ].each do |cli_type, config_type, form_of_be_falsey|
150
130
  context "when #{cli_type.inspect} is specified" do
151
131
  let(:args) { ['--boolean-matcher', cli_type] }
152
132
 
153
- it "sets Configuration#boolean_matcher_type #{configuration_type.inspect}" do
133
+ it "sets Config#boolean_matcher_type #{config_type.inspect}" do
154
134
  parser.parse(args)
155
- configuration.boolean_matcher_type.should == configuration_type
135
+ config.boolean_matcher_type.should == config_type
156
136
  end
157
137
 
158
- it "sets Configuration#form_of_be_falsey #{form_of_be_falsey.inspect}" do
138
+ it "sets Config#form_of_be_falsey #{form_of_be_falsey.inspect}" do
159
139
  parser.parse(args)
160
- configuration.form_of_be_falsey.should == form_of_be_falsey
140
+ config.form_of_be_falsey.should == form_of_be_falsey
161
141
  end
162
142
  end
163
143
  end
@@ -176,40 +156,28 @@ module Transpec
176
156
  describe '-a/--no-yield-any-instance option' do
177
157
  let(:args) { ['--no-yield-any-instance'] }
178
158
 
179
- it 'sets Configuration#add_receiver_arg_to_any_instance_implementation_block? false' do
159
+ it 'sets Config#add_receiver_arg_to_any_instance_implementation_block? false' do
180
160
  parser.parse(args)
181
- configuration.add_receiver_arg_to_any_instance_implementation_block?
161
+ config.add_receiver_arg_to_any_instance_implementation_block?
182
162
  .should be_false
183
163
  end
184
164
  end
185
165
 
186
- describe '-t/--convert-stub-with-hash option' do
187
- let(:args) { ['--convert-stub-with-hash'] }
188
-
189
- before do
190
- parser.stub(:warn)
191
- end
192
-
193
- it 'sets Configuration#convert_stub_with_hash_to_allow_to_receive_and_return? true' do
194
- parser.parse(args)
195
- configuration.convert_stub_with_hash_to_allow_to_receive_and_return?.should be_true
196
- end
197
-
198
- it 'is deprecated' do
199
- parser.should_receive(:warn) do |message|
200
- message.should =~ /--convert-stub-with-hash.+deprecated/i
201
- end
166
+ describe '-t/--no-explicit-spec-type option' do
167
+ let(:args) { ['--no-explicit-spec-type'] }
202
168
 
169
+ it 'sets Config#add_explicit_type_metadata_to_example_group? false' do
203
170
  parser.parse(args)
171
+ config.add_explicit_type_metadata_to_example_group?.should be_false
204
172
  end
205
173
  end
206
174
 
207
175
  describe '-p/--no-parentheses-matcher-arg option' do
208
176
  let(:args) { ['--no-parentheses-matcher-arg'] }
209
177
 
210
- it 'sets Configuration#parenthesize_matcher_arg? false' do
178
+ it 'sets Config#parenthesize_matcher_arg? false' do
211
179
  parser.parse(args)
212
- configuration.parenthesize_matcher_arg.should be_false
180
+ config.parenthesize_matcher_arg.should be_false
213
181
  end
214
182
  end
215
183
 
@@ -32,9 +32,11 @@ module Transpec
32
32
  ['2.14.0', false],
33
33
  ['2.99.0.beta1', true],
34
34
  ['2.99.0.beta2', true],
35
+ ['2.99.0.rc1', true],
35
36
  ['2.99.0', true],
36
37
  ['3.0.0.beta1', true],
37
38
  ['3.0.0.beta2', true],
39
+ ['3.0.0.rc1', true],
38
40
  ['3.0.0', true]
39
41
  ]
40
42
  end
@@ -47,9 +49,27 @@ module Transpec
47
49
  ['2.14.0', false],
48
50
  ['2.99.0.beta1', false],
49
51
  ['2.99.0.beta2', true],
52
+ ['2.99.0.rc1', true],
50
53
  ['2.99.0', true],
51
54
  ['3.0.0.beta1', false],
52
55
  ['3.0.0.beta2', true],
56
+ ['3.0.0.rc1', true],
57
+ ['3.0.0', true]
58
+ ]
59
+ end
60
+
61
+ [
62
+ :implicit_spec_type_disablement_available?
63
+ ].each do |method|
64
+ include_examples 'version comparisons', method, [
65
+ ['2.14.0', false],
66
+ ['2.99.0.beta1', false],
67
+ ['2.99.0.beta2', false],
68
+ ['2.99.0.rc1', true],
69
+ ['2.99.0', true],
70
+ ['3.0.0.beta1', false],
71
+ ['3.0.0.beta2', false],
72
+ ['3.0.0.rc1', true],
53
73
  ['3.0.0', true]
54
74
  ]
55
75
  end
@@ -61,9 +81,11 @@ module Transpec
61
81
  ['2.14.0', false],
62
82
  ['2.99.0.beta1', false],
63
83
  ['2.99.0.beta2', false],
84
+ ['2.99.0.rc1', false],
64
85
  ['2.99.0', false],
65
86
  ['3.0.0.beta1', true],
66
87
  ['3.0.0.beta2', true],
88
+ ['3.0.0.rc1', true],
67
89
  ['3.0.0', true]
68
90
  ]
69
91
  end
@@ -78,9 +100,11 @@ module Transpec
78
100
  ['2.14.0', false],
79
101
  ['2.99.0.beta1', false],
80
102
  ['2.99.0.beta2', false],
103
+ ['2.99.0.rc1', false],
81
104
  ['2.99.0', false],
82
105
  ['3.0.0.beta1', false],
83
106
  ['3.0.0.beta2', true],
107
+ ['3.0.0.rc1', true],
84
108
  ['3.0.0', true]
85
109
  ]
86
110
  end
@@ -89,9 +113,11 @@ module Transpec
89
113
  ['2.14.0', false],
90
114
  ['2.99.0.beta1', true],
91
115
  ['2.99.0.beta2', true],
116
+ ['2.99.0.rc1', true],
92
117
  ['2.99.0', true],
93
118
  ['3.0.0.beta1', false],
94
119
  ['3.0.0.beta2', false],
120
+ ['3.0.0.rc1', false],
95
121
  ['3.0.0', false]
96
122
  ]
97
123
  end
@@ -49,6 +49,20 @@ module Transpec
49
49
  end
50
50
  end
51
51
 
52
+ context "with expression `RSpec.describe 'something' do ... end`" do
53
+ let(:source) do
54
+ <<-END
55
+ RSpec.describe 'something' do
56
+ end
57
+ END
58
+ end
59
+
60
+ it 'does nothing' do
61
+ example_group.convert_to_non_monkey_patch!
62
+ rewritten_source.should == source
63
+ end
64
+ end
65
+
52
66
  context 'when the #describe is in a module' do
53
67
  let(:source) do
54
68
  <<-END
@@ -167,6 +181,269 @@ module Transpec
167
181
  end
168
182
  end
169
183
  end
184
+
185
+ describe '#add_explicit_type_metadata!' do
186
+ before do
187
+ example_group.add_explicit_type_metadata!
188
+ end
189
+
190
+ context 'when it is in top level scope' do
191
+ context "and expression `describe 'something' do ... end`" do
192
+ let(:source) do
193
+ <<-END
194
+ describe 'something' do
195
+ end
196
+ END
197
+ end
198
+
199
+ {
200
+ 'controllers' => :controller,
201
+ 'helpers' => :helper,
202
+ 'mailers' => :mailer,
203
+ 'models' => :model,
204
+ 'requests' => :request,
205
+ 'integration' => :request,
206
+ 'api' => :request,
207
+ 'routing' => :routing,
208
+ 'views' => :view,
209
+ 'features' => :feature
210
+ }.each do |directory, type|
211
+ context "and the file path is \"spec/#{directory}/some_spec.rb\"" do
212
+ let(:source_path) { "spec/#{directory}/some_spec.rb" }
213
+
214
+ let(:expected_source) do
215
+ <<-END
216
+ describe 'something', :type => #{type.inspect} do
217
+ end
218
+ END
219
+ end
220
+
221
+ it "adds metadata \":type => #{type.inspect}\"" do
222
+ rewritten_source.should == expected_source
223
+ end
224
+
225
+ it "adds record `describe 'some #{type}' { }` " \
226
+ "-> `describe 'some #{type}', :type => #{type.inspect} { }`" do
227
+ record.original_syntax.should == "describe 'some #{type}' { }"
228
+ record.converted_syntax.should == "describe 'some #{type}', :type => #{type.inspect} { }"
229
+ end
230
+ end
231
+ end
232
+
233
+ context 'and the file path is "spec/contollers/some_namespace/some_spec.rb"' do
234
+ let(:source_path) { 'spec/controllers/some_namespace/some_spec.rb' }
235
+
236
+ let(:expected_source) do
237
+ <<-END
238
+ describe 'something', :type => :controller do
239
+ end
240
+ END
241
+ end
242
+
243
+ it 'adds metadata ":type => :controller' do
244
+ rewritten_source.should == expected_source
245
+ end
246
+ end
247
+
248
+ context 'and the file path is "spec/unit/some_spec.rb"' do
249
+ let(:source_path) { 'spec/unit/some_spec.rb' }
250
+
251
+ it 'does nothing' do
252
+ rewritten_source.should == source
253
+ end
254
+ end
255
+
256
+ context 'and the file path is "features/controllers/some_spec.rb"' do
257
+ let(:source_path) { 'features/controllers/some_spec.rb' }
258
+
259
+ it 'does nothing' do
260
+ rewritten_source.should == source
261
+ end
262
+ end
263
+ end
264
+
265
+ context "and expression `describe 'something', :foo => :bar do ... end`" do
266
+ let(:source) do
267
+ <<-END
268
+ describe 'something', :foo => :bar do
269
+ end
270
+ END
271
+ end
272
+
273
+ context 'and the file path is "spec/controllers/some_spec.rb"' do
274
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
275
+
276
+ let(:expected_source) do
277
+ <<-END
278
+ describe 'something', :type => :controller, :foo => :bar do
279
+ end
280
+ END
281
+ end
282
+
283
+ it 'adds metadata ":type => :controller"' do
284
+ rewritten_source.should == expected_source
285
+ end
286
+ end
287
+ end
288
+
289
+ context "and expression `describe 'something', foo: :bar do ... end`" do
290
+ let(:source) do
291
+ <<-END
292
+ describe 'something', foo: :bar do
293
+ end
294
+ END
295
+ end
296
+
297
+ context 'and the file path is "spec/controllers/some_spec.rb"' do
298
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
299
+
300
+ let(:expected_source) do
301
+ <<-END
302
+ describe 'something', type: :controller, foo: :bar do
303
+ end
304
+ END
305
+ end
306
+
307
+ it 'adds metadata "type: :controller"' do
308
+ rewritten_source.should == expected_source
309
+ end
310
+ end
311
+ end
312
+
313
+ context "and expression `describe 'something', :type => :foo do ... end`" do
314
+ let(:source) do
315
+ <<-END
316
+ describe 'something', :type => :foo do
317
+ end
318
+ END
319
+ end
320
+
321
+ context 'and the file path is "spec/controllers/some_spec.rb"' do
322
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
323
+
324
+ it 'does nothing' do
325
+ rewritten_source.should == source
326
+ end
327
+ end
328
+ end
329
+
330
+ context "and expression `RSpec.describe 'something' do ... end`" do
331
+ let(:source) do
332
+ <<-END
333
+ RSpec.describe 'something' do
334
+ end
335
+ END
336
+ end
337
+
338
+ context 'and the file path is "spec/controllers/some_spec.rb"' do
339
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
340
+
341
+ let(:expected_source) do
342
+ <<-END
343
+ RSpec.describe 'something', :type => :controller do
344
+ end
345
+ END
346
+ end
347
+
348
+ it 'adds metadata ":type => :controller"' do
349
+ rewritten_source.should == expected_source
350
+ end
351
+ end
352
+ end
353
+
354
+ context "and expression `shared_examples 'something' do ... end`" do
355
+ let(:source) do
356
+ <<-END
357
+ shared_examples 'something' do
358
+ end
359
+ END
360
+ end
361
+
362
+ context 'and the file path is "spec/controllers/some_spec.rb"' do
363
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
364
+
365
+ it 'does nothing' do
366
+ rewritten_source.should == source
367
+ end
368
+ end
369
+ end
370
+ end
371
+
372
+ context 'when #describes are nested' do
373
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
374
+
375
+ let(:source) do
376
+ <<-END
377
+ describe 'something' do
378
+ describe '#some_method' do
379
+ end
380
+ end
381
+ END
382
+ end
383
+
384
+ let(:expected_source) do
385
+ <<-END
386
+ describe 'something', :type => :controller do
387
+ describe '#some_method' do
388
+ end
389
+ end
390
+ END
391
+ end
392
+
393
+ it 'adds the metadata only to the outmost #describe' do
394
+ rewritten_source.should == expected_source
395
+ end
396
+ end
397
+
398
+ context 'with runtime information' do
399
+ include_context 'dynamic analysis objects'
400
+
401
+ let(:source_path) { 'spec/controllers/some_spec.rb' }
402
+
403
+ context 'when rspec-rails is loaded in the spec' do
404
+ let(:source) do
405
+ <<-END
406
+ module RSpec
407
+ module Rails
408
+ end
409
+ end
410
+
411
+ describe 'something' do
412
+ end
413
+ END
414
+ end
415
+
416
+ let(:expected_source) do
417
+ <<-END
418
+ module RSpec
419
+ module Rails
420
+ end
421
+ end
422
+
423
+ describe 'something', :type => :controller do
424
+ end
425
+ END
426
+ end
427
+
428
+ it 'adds the metadata' do
429
+ rewritten_source.should == expected_source
430
+ end
431
+ end
432
+
433
+ context 'when rspec-rails is not loaded in the spec' do
434
+ let(:source) do
435
+ <<-END
436
+ describe 'something' do
437
+ end
438
+ END
439
+ end
440
+
441
+ it 'does nothing' do
442
+ rewritten_source.should == source
443
+ end
444
+ end
445
+ end
446
+ end
170
447
  end
171
448
  end
172
449
  end