transpec 1.10.4 → 1.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -3
  3. data/CHANGELOG.md +9 -0
  4. data/README.md +96 -18
  5. data/README.md.erb +117 -51
  6. data/lib/transpec/base_rewriter.rb +25 -28
  7. data/lib/transpec/cli.rb +27 -14
  8. data/lib/transpec/configuration.rb +2 -1
  9. data/lib/transpec/converter.rb +54 -32
  10. data/lib/transpec/dynamic_analyzer/helper.rb.erb +44 -0
  11. data/lib/transpec/dynamic_analyzer/node_util.rb +17 -0
  12. data/lib/transpec/dynamic_analyzer/rewriter.rb +12 -4
  13. data/lib/transpec/dynamic_analyzer/runtime_data.rb +3 -4
  14. data/lib/transpec/dynamic_analyzer.rb +14 -52
  15. data/lib/transpec/option_parser.rb +89 -81
  16. data/lib/transpec/processed_source.rb +48 -0
  17. data/lib/transpec/record.rb +2 -2
  18. data/lib/transpec/report.rb +5 -1
  19. data/lib/transpec/rspec_dsl.rb +12 -2
  20. data/lib/transpec/rspec_version.rb +8 -7
  21. data/lib/transpec/spec_suite.rb +114 -0
  22. data/lib/transpec/syntax/example.rb +4 -20
  23. data/lib/transpec/syntax/example_group.rb +38 -0
  24. data/lib/transpec/syntax/have.rb +6 -9
  25. data/lib/transpec/syntax/its.rb +5 -7
  26. data/lib/transpec/syntax/method_stub.rb +12 -13
  27. data/lib/transpec/syntax/mixin/any_instance_block.rb +14 -6
  28. data/lib/transpec/syntax/mixin/context_sensitive.rb +41 -0
  29. data/lib/transpec/syntax/mixin/matcher_owner.rb +16 -26
  30. data/lib/transpec/syntax/mixin/monkey_patch_any_instance.rb +1 -1
  31. data/lib/transpec/syntax/mixin/no_message_allowance.rb +2 -2
  32. data/lib/transpec/syntax/mixin/useless_and_return.rb +2 -2
  33. data/lib/transpec/syntax/oneliner_should.rb +9 -13
  34. data/lib/transpec/syntax/operator.rb +3 -7
  35. data/lib/transpec/syntax/pending.rb +4 -20
  36. data/lib/transpec/syntax/rspec_configure/configuration_modification.rb +86 -0
  37. data/lib/transpec/syntax/rspec_configure/framework.rb +45 -86
  38. data/lib/transpec/syntax/rspec_configure.rb +18 -6
  39. data/lib/transpec/syntax/should.rb +3 -5
  40. data/lib/transpec/syntax/should_receive.rb +1 -1
  41. data/lib/transpec/syntax.rb +8 -0
  42. data/lib/transpec/util.rb +0 -8
  43. data/lib/transpec/version.rb +2 -2
  44. data/spec/acceptance/configuration_modification_spec.rb +132 -0
  45. data/spec/acceptance/conversion_spec.rb +114 -0
  46. data/spec/support/shared_context.rb +6 -12
  47. data/spec/transpec/cli_spec.rb +21 -23
  48. data/spec/transpec/configuration_spec.rb +2 -1
  49. data/spec/transpec/converter_spec.rb +292 -213
  50. data/spec/transpec/dynamic_analyzer/rewriter_spec.rb +3 -3
  51. data/spec/transpec/dynamic_analyzer_spec.rb +8 -2
  52. data/spec/transpec/option_parser_spec.rb +42 -4
  53. data/spec/transpec/processed_source_spec.rb +67 -0
  54. data/spec/transpec/rspec_version_spec.rb +8 -2
  55. data/spec/transpec/spec_suite_spec.rb +107 -0
  56. data/spec/transpec/syntax/allow_spec.rb +9 -27
  57. data/spec/transpec/syntax/example_group_spec.rb +172 -0
  58. data/spec/transpec/syntax/expect_spec.rb +18 -54
  59. data/spec/transpec/syntax/have_spec.rb +35 -14
  60. data/spec/transpec/syntax/its_spec.rb +27 -7
  61. data/spec/transpec/syntax/method_stub_spec.rb +31 -8
  62. data/spec/transpec/syntax/oneliner_should_spec.rb +22 -131
  63. data/spec/transpec/syntax/rspec_configure_spec.rb +118 -15
  64. data/spec/transpec/syntax/should_spec.rb +51 -82
  65. data/tasks/fixtures/guard/COMMIT_EDITMSG +80 -0
  66. data/tasks/fixtures/mail/COMMIT_EDITMSG +84 -0
  67. data/tasks/fixtures/twitter/COMMIT_EDITMSG +36 -0
  68. data/tasks/lib/transpec_test.rb +23 -2
  69. data/tasks/readme.rake +35 -0
  70. metadata +22 -4
  71. data/lib/transpec/parser.rb +0 -9
@@ -5,9 +5,10 @@ require 'transpec/converter'
5
5
 
6
6
  module Transpec
7
7
  describe Converter do
8
- subject(:converter) { Converter.new(configuration, rspec_version) }
9
- let(:rspec_version) { Transpec.required_rspec_version }
8
+ subject(:converter) { Converter.new(spec_suite, configuration, rspec_version) }
9
+ let(:spec_suite) { double('spec_suite', runtime_data: nil).as_null_object }
10
10
  let(:configuration) { Configuration.new }
11
+ let(:rspec_version) { Transpec.required_rspec_version }
11
12
 
12
13
  describe '#convert_file!' do
13
14
  include_context 'isolated environment'
@@ -20,12 +21,23 @@ module Transpec
20
21
  converter.stub(:rewrite).and_return('This is the converted spec')
21
22
  end
22
23
 
23
- it 'overwrites the passed file path' do
24
- converter.convert_file!(file_path)
25
- File.read(file_path).should == 'This is the converted spec'
24
+ context 'when a file path is passed' do
25
+ it 'overwrites the file' do
26
+ converter.convert_file!(file_path)
27
+ File.read(file_path).should == 'This is the converted spec'
28
+ end
26
29
  end
27
30
 
28
- context 'when the source does not need convert' do
31
+ context 'when a processed source is passed' do
32
+ let(:processed_source) { ProcessedSource.parse_file(file_path) }
33
+
34
+ it 'overwrites the file that the processed source was derived from' do
35
+ converter.convert_file!(processed_source)
36
+ File.read(file_path).should == 'This is the converted spec'
37
+ end
38
+ end
39
+
40
+ context 'when the source is not needed to be converted' do
29
41
  before do
30
42
  converter.stub(:rewrite).and_return('This is a spec')
31
43
  end
@@ -37,8 +49,8 @@ module Transpec
37
49
  end
38
50
  end
39
51
 
40
- describe '#convert' do
41
- subject { converter.convert(source) }
52
+ describe '#convert_source' do
53
+ subject { converter.convert_source(source) }
42
54
 
43
55
  let(:source) do
44
56
  <<-END
@@ -51,10 +63,26 @@ module Transpec
51
63
  END
52
64
  end
53
65
 
54
- it 'dispatches found syntax objects to each handler method' do
66
+ it 'dispatches conversion target standalone syntax objects to each handler method' do
55
67
  converter.should_receive(:process_should).with(an_instance_of(Syntax::Should))
56
68
  converter.should_receive(:process_should_receive).with(an_instance_of(Syntax::ShouldReceive))
57
- converter.convert(source)
69
+ converter.should_not_receive(:process_stub)
70
+ converter.convert_source(source)
71
+ end
72
+
73
+ it 'dispatches conversion target non-standalone syntax objects to each handler method' do
74
+ converter.should_receive(:process_operator).with(an_instance_of(Syntax::Operator))
75
+ converter.should_not_receive(:process_have)
76
+ converter.should_not_receive(:process_raise_error)
77
+ converter.convert_source(source)
78
+ end
79
+
80
+ context 'when the source is invalid' do
81
+ let(:source) { '<' }
82
+
83
+ it 'raises Parser::SyntaxError' do
84
+ -> { converter.convert_source(source) }.should raise_error(Parser::SyntaxError)
85
+ end
58
86
  end
59
87
 
60
88
  context 'when the source has overlapped convert targets' do
@@ -79,7 +107,7 @@ module Transpec
79
107
  end
80
108
 
81
109
  before do
82
- configuration.convert_stub_with_hash_to_stub_and_return = true
110
+ configuration.convert_stub_with_hash_to_allow_to_receive_and_return = true
83
111
  end
84
112
 
85
113
  it 'converts all targets properly' do
@@ -87,7 +115,7 @@ module Transpec
87
115
  end
88
116
 
89
117
  it 'adds records for only completed conversions' do
90
- converter.convert(source)
118
+ converter.convert_source(source)
91
119
  converter.report.records.count.should == 2
92
120
  end
93
121
  end
@@ -119,7 +147,7 @@ module Transpec
119
147
  end
120
148
 
121
149
  it 'adds the conversion error to the report' do
122
- converter.convert(source)
150
+ converter.convert_source(source)
123
151
  converter.report.should have(1).conversion_error
124
152
  end
125
153
  end
@@ -136,7 +164,7 @@ module Transpec
136
164
  before { configuration.negative_form_of_to = 'not_to' }
137
165
 
138
166
  it 'invokes Should#expectize! with "not_to"' do
139
- should_object.should_receive(:expectize!).with('not_to', anything)
167
+ should_object.should_receive(:expectize!).with('not_to')
140
168
  converter.process_should(should_object)
141
169
  end
142
170
  end
@@ -145,25 +173,7 @@ module Transpec
145
173
  before { configuration.negative_form_of_to = 'to_not' }
146
174
 
147
175
  it 'invokes Should#expectize! with "to_not"' do
148
- should_object.should_receive(:expectize!).with('to_not', anything)
149
- converter.process_should(should_object)
150
- end
151
- end
152
-
153
- context 'and Configuration#parenthesize_matcher_arg is true' do
154
- before { configuration.parenthesize_matcher_arg = true }
155
-
156
- it 'invokes Should#expectize! with true as second argument' do
157
- should_object.should_receive(:expectize!).with(anything, true)
158
- converter.process_should(should_object)
159
- end
160
- end
161
-
162
- context 'and Configuration#parenthesize_matcher_arg is false' do
163
- before { configuration.parenthesize_matcher_arg = false }
164
-
165
- it 'invokes Should#expectize! with false as second argument' do
166
- should_object.should_receive(:expectize!).with(anything, false)
176
+ should_object.should_receive(:expectize!).with('to_not')
167
177
  converter.process_should(should_object)
168
178
  end
169
179
  end
@@ -177,57 +187,19 @@ module Transpec
177
187
  converter.process_should(should_object)
178
188
  end
179
189
  end
180
-
181
- context 'when Configuration#convert_have_items? is true' do
182
- before { configuration.convert_have_items = true }
183
-
184
- context 'and Configuration#parenthesize_matcher_arg is true' do
185
- before { configuration.parenthesize_matcher_arg = true }
186
-
187
- it 'invokes Have#convert_to_standard_expectation! with true' do
188
- should_object.have_matcher.should_receive(:convert_to_standard_expectation!).with(true)
189
- converter.process_should(should_object)
190
- end
191
- end
192
-
193
- context 'and Configuration#parenthesize_matcher_arg is false' do
194
- before { configuration.parenthesize_matcher_arg = false }
195
-
196
- it 'invokes Have#convert_to_standard_expectation! with false' do
197
- should_object.have_matcher.should_receive(:convert_to_standard_expectation!).with(false)
198
- converter.process_should(should_object)
199
- end
200
- end
201
-
202
- context 'and Configuration#convert_should? is true' do
203
- before { configuration.convert_should = true }
204
-
205
- it 'invokes Should#expectize! then Have#convert_to_standard_expectation!' do
206
- should_object.should_receive(:expectize!).ordered
207
- should_object.have_matcher.should_receive(:convert_to_standard_expectation!).ordered
208
- converter.process_should(should_object)
209
- end
210
- end
211
- end
212
-
213
- context 'when Configuration#convert_have_items? is false' do
214
- before { configuration.convert_have_items = false }
215
-
216
- it 'does not invoke Have#convert_to_standard_expectation!' do
217
- should_object.have_matcher.should_not_receive(:convert_to_standard_expectation!)
218
- converter.process_should(should_object)
219
- end
220
- end
221
-
222
- it 'invokes #process_raise_error with its #raise_error_matcher' do
223
- converter.should_receive(:process_raise_error).with(raise_error_object)
224
- converter.process_should(should_object)
225
- end
226
190
  end
227
191
 
228
192
  describe '#process_oneliner_should' do
229
- let(:should_object) { double('oneliner_should_object', raise_error_matcher: raise_error_object).as_null_object }
193
+ let(:should_object) do
194
+ double(
195
+ 'oneliner_should_object',
196
+ raise_error_matcher: raise_error_object,
197
+ have_matcher: have_object
198
+ ).as_null_object
199
+ end
200
+
230
201
  let(:raise_error_object) { double('raise_error_object').as_null_object }
202
+ let(:have_object) { double('have_object').as_null_object }
231
203
 
232
204
  shared_examples 'does nothing' do
233
205
  it 'does nothing' do
@@ -239,7 +211,7 @@ module Transpec
239
211
  end
240
212
 
241
213
  shared_examples 'invokes OnelinerShould#expectize! if available' do
242
- context 'when RSpecVersion#oneliner_is_expected_available? returns true' do
214
+ context 'and RSpecVersion#oneliner_is_expected_available? returns true' do
243
215
  before { rspec_version.stub(:oneliner_is_expected_available?).and_return(true) }
244
216
 
245
217
  it 'invokes OnelinerShould#expectize!' do
@@ -248,7 +220,7 @@ module Transpec
248
220
  end
249
221
  end
250
222
 
251
- context 'when RSpecVersion#oneliner_is_expected_available? returns false' do
223
+ context 'and RSpecVersion#oneliner_is_expected_available? returns false' do
252
224
  before { rspec_version.stub(:oneliner_is_expected_available?).and_return(false) }
253
225
  include_examples 'does nothing'
254
226
  end
@@ -277,29 +249,14 @@ module Transpec
277
249
  context 'when Configuration#convert_oneliner? is true' do
278
250
  before { configuration.convert_oneliner = true }
279
251
 
280
- context 'and the OnelinerShould has #have matcher' do
252
+ context 'and the #have matcher is conversion target' do
281
253
  before do
282
- should_object.stub(:have_matcher).and_return(double('have_matcher').as_null_object)
254
+ have_object.stub(:conversion_target?).and_return(true)
283
255
  end
284
256
 
285
257
  context 'and Configuration#convert_have_items? is true' do
286
258
  before { configuration.convert_have_items = true }
287
-
288
- context 'and Have#project_requires_collection_matcher? is true' do
289
- before do
290
- should_object.have_matcher
291
- .stub(:project_requires_collection_matcher?).and_return(true)
292
- end
293
- include_examples 'invokes OnelinerShould#expectize! if available'
294
- end
295
-
296
- context 'and Have#project_requires_collection_matcher? is false' do
297
- before do
298
- should_object.have_matcher
299
- .stub(:project_requires_collection_matcher?).and_return(false)
300
- end
301
- include_examples 'converts to standard expecatations'
302
- end
259
+ include_examples 'converts to standard expecatations'
303
260
  end
304
261
 
305
262
  context 'and Configuration#convert_have_items? is false' do
@@ -308,9 +265,9 @@ module Transpec
308
265
  end
309
266
  end
310
267
 
311
- context 'and the OnelinerShould does not have #have matcher' do
268
+ context 'and the #have matcher is not conversion target' do
312
269
  before do
313
- should_object.stub(:have_matcher).and_return(nil)
270
+ have_object.stub(:conversion_target?).and_return(false)
314
271
  end
315
272
 
316
273
  context 'and Configuration#convert_have_items? is true' do
@@ -328,29 +285,14 @@ module Transpec
328
285
  context 'when Configuration#convert_oneliner? is false' do
329
286
  before { configuration.convert_oneliner = false }
330
287
 
331
- context 'and the OnelinerShould has #have matcher' do
288
+ context 'and the #have matcher is conversion target' do
332
289
  before do
333
- should_object.stub(:have_matcher).and_return(double('have_matcher').as_null_object)
290
+ have_object.stub(:conversion_target?).and_return(true)
334
291
  end
335
292
 
336
293
  context 'and Configuration#convert_have_items? is true' do
337
294
  before { configuration.convert_have_items = true }
338
-
339
- context 'and Have#project_requires_collection_matcher? is true' do
340
- before do
341
- should_object.have_matcher
342
- .stub(:project_requires_collection_matcher?).and_return(true)
343
- end
344
- include_examples 'does nothing'
345
- end
346
-
347
- context 'and Have#project_requires_collection_matcher? is false' do
348
- before do
349
- should_object.have_matcher
350
- .stub(:project_requires_collection_matcher?).and_return(false)
351
- end
352
- include_examples 'converts to standard expecatations'
353
- end
295
+ include_examples 'converts to standard expecatations'
354
296
  end
355
297
 
356
298
  context 'and Configuration#convert_have_items? is false' do
@@ -359,9 +301,9 @@ module Transpec
359
301
  end
360
302
  end
361
303
 
362
- context 'and the OnelinerShould does not have #have matcher' do
304
+ context 'and the #have matcher is not conversion target' do
363
305
  before do
364
- should_object.stub(:have_matcher).and_return(nil)
306
+ have_object.stub(:conversion_target?).and_return(false)
365
307
  end
366
308
 
367
309
  context 'and Configuration#convert_have_items? is true' do
@@ -375,83 +317,6 @@ module Transpec
375
317
  end
376
318
  end
377
319
  end
378
-
379
- it 'invokes #process_raise_error with its #raise_error_matcher' do
380
- converter.should_receive(:process_raise_error).with(raise_error_object)
381
- converter.process_oneliner_should(should_object)
382
- end
383
- end
384
-
385
- describe '#process_expect' do
386
- let(:expect_object) do
387
- double('expect_object',
388
- receive_matcher: receive_object,
389
- raise_error_matcher: raise_error_object
390
- ).as_null_object
391
- end
392
- let(:receive_object) { double('receive_object').as_null_object }
393
- let(:raise_error_object) { double('raise_error_object').as_null_object }
394
-
395
- context 'when Configuration#convert_have_items? is true' do
396
- before { configuration.convert_have_items = true }
397
-
398
- context 'and Configuration#parenthesize_matcher_arg is true' do
399
- before { configuration.parenthesize_matcher_arg = true }
400
-
401
- it 'invokes Have#convert_to_standard_expectation! with true' do
402
- expect_object.have_matcher.should_receive(:convert_to_standard_expectation!).with(true)
403
- converter.process_expect(expect_object)
404
- end
405
- end
406
-
407
- context 'and Configuration#parenthesize_matcher_arg is false' do
408
- before { configuration.parenthesize_matcher_arg = false }
409
-
410
- it 'invokes Have#convert_to_standard_expectation! with false' do
411
- expect_object.have_matcher.should_receive(:convert_to_standard_expectation!).with(false)
412
- converter.process_expect(expect_object)
413
- end
414
- end
415
- end
416
-
417
- context 'when Configuration#convert_have_items? is false' do
418
- before { configuration.convert_have_items = false }
419
-
420
- it 'does not invoke Have#convert_to_standard_expectation!' do
421
- expect_object.have_matcher.should_not_receive(:convert_to_standard_expectation!)
422
- converter.process_expect(expect_object)
423
- end
424
- end
425
-
426
- it "invokes #process_useless_and_return with the expect's #receive matcher" do
427
- converter.should_receive(:process_useless_and_return).with(receive_object)
428
- converter.process_expect(expect_object)
429
- end
430
-
431
- it "invokes #process_any_instance_block with the expect's #receive matcher" do
432
- converter.should_receive(:process_any_instance_block).with(receive_object)
433
- converter.process_expect(expect_object)
434
- end
435
-
436
- it 'invokes #process_raise_error with its #raise_error_matcher' do
437
- converter.should_receive(:process_raise_error).with(raise_error_object)
438
- converter.process_expect(expect_object)
439
- end
440
- end
441
-
442
- describe '#process_allow' do
443
- let(:allow_object) { double('allow_object', receive_matcher: receive_object).as_null_object }
444
- let(:receive_object) { double('receive_object').as_null_object }
445
-
446
- it "invokes #process_useless_and_return with the allow's #receive matcher" do
447
- converter.should_receive(:process_useless_and_return).with(receive_object)
448
- converter.process_allow(allow_object)
449
- end
450
-
451
- it "invokes #process_any_instance_block with the allow's #receive matcher" do
452
- converter.should_receive(:process_any_instance_block).with(receive_object)
453
- converter.process_allow(allow_object)
454
- end
455
320
  end
456
321
 
457
322
  describe '#process_should_receive' do
@@ -683,8 +548,8 @@ module Transpec
683
548
  context 'and MethodStub#hash_arg? is true' do
684
549
  before { method_stub_object.stub(:hash_arg?).and_return(true) }
685
550
 
686
- context 'and Configuration#convert_stub_with_hash_to_stub_and_return? is true' do
687
- before { configuration.convert_stub_with_hash_to_stub_and_return = true }
551
+ context 'and Configuration#convert_stub_with_hash_to_allow_to_receive_and_return? is true' do
552
+ before { configuration.convert_stub_with_hash_to_allow_to_receive_and_return = true }
688
553
 
689
554
  context 'and RSpecVersion#receive_messages_available? is true' do
690
555
  before { rspec_version.stub(:receive_messages_available?).and_return(true) }
@@ -701,8 +566,8 @@ module Transpec
701
566
  end
702
567
  end
703
568
 
704
- context 'and Configuration#convert_stub_with_hash_to_stub_and_return? is false' do
705
- before { configuration.convert_stub_with_hash_to_stub_and_return = false }
569
+ context 'and Configuration#convert_stub_with_hash_to_allow_to_receive_and_return? is false' do
570
+ before { configuration.convert_stub_with_hash_to_allow_to_receive_and_return = false }
706
571
 
707
572
  context 'and RSpecVersion#receive_messages_available? is true' do
708
573
  before { rspec_version.stub(:receive_messages_available?).and_return(true) }
@@ -786,6 +651,65 @@ module Transpec
786
651
  end
787
652
  end
788
653
 
654
+ describe '#process_operator' do
655
+ let(:operator_object) { double('operator_object').as_null_object }
656
+
657
+ context 'when Configuration#convert_should? is true' do
658
+ before { configuration.convert_should = true }
659
+
660
+ context 'and Configuration#parenthesize_matcher_arg is true' do
661
+ before { configuration.parenthesize_matcher_arg = true }
662
+
663
+ it 'invokes Operator#convert_operator! with true' do
664
+ operator_object.should_receive(:convert_operator!).with(true)
665
+ converter.process_operator(operator_object)
666
+ end
667
+ end
668
+
669
+ context 'and Configuration#parenthesize_matcher_arg is false' do
670
+ before { configuration.parenthesize_matcher_arg = false }
671
+
672
+ it 'invokes Should#expectize! with false as second argument' do
673
+ operator_object.should_receive(:convert_operator!).with(false)
674
+ converter.process_operator(operator_object)
675
+ end
676
+ end
677
+
678
+ context 'and the expectation is one-liner should' do
679
+ before do
680
+ operator_object.stub(:expectation).and_return(Syntax::OnelinerShould.new(nil))
681
+ end
682
+
683
+ context 'and RSpecVersion#oneliner_is_expected_available? returns true' do
684
+ before { rspec_version.stub(:oneliner_is_expected_available?).and_return(true) }
685
+
686
+ it 'invokes Operator#convert_operator!' do
687
+ operator_object.should_receive(:convert_operator!)
688
+ converter.process_operator(operator_object)
689
+ end
690
+ end
691
+
692
+ context 'and RSpecVersion#oneliner_is_expected_available? returns false' do
693
+ before { rspec_version.stub(:oneliner_is_expected_available?).and_return(false) }
694
+
695
+ it 'does not invoke Operator#convert_operator!' do
696
+ operator_object.should_not_receive(:convert_operator!)
697
+ converter.process_operator(operator_object)
698
+ end
699
+ end
700
+ end
701
+ end
702
+
703
+ context 'when Configuration#convert_should? is false' do
704
+ before { configuration.convert_should = false }
705
+
706
+ it 'does not invoke Operator#convert_operator!' do
707
+ operator_object.should_not_receive(:convert_operator!)
708
+ converter.process_operator(operator_object)
709
+ end
710
+ end
711
+ end
712
+
789
713
  describe '#process_be_boolean' do
790
714
  let(:be_boolean_object) { double('be_boolean_object').as_null_object }
791
715
 
@@ -871,6 +795,41 @@ module Transpec
871
795
  end
872
796
  end
873
797
 
798
+ describe '#process_have' do
799
+ let(:have_object) { double('have_object').as_null_object }
800
+
801
+ context 'when Configuration#convert_have_items? is true' do
802
+ before { configuration.convert_have_items = true }
803
+
804
+ context 'and Configuration#parenthesize_matcher_arg is true' do
805
+ before { configuration.parenthesize_matcher_arg = true }
806
+
807
+ it 'invokes Have#convert_to_standard_expectation! with true' do
808
+ have_object.should_receive(:convert_to_standard_expectation!).with(true)
809
+ converter.process_have(have_object)
810
+ end
811
+ end
812
+
813
+ context 'and Configuration#parenthesize_matcher_arg is false' do
814
+ before { configuration.parenthesize_matcher_arg = false }
815
+
816
+ it 'invokes Have#convert_to_standard_expectation! with false' do
817
+ have_object.should_receive(:convert_to_standard_expectation!).with(false)
818
+ converter.process_have(have_object)
819
+ end
820
+ end
821
+ end
822
+
823
+ context 'when Configuration#convert_have_items? is false' do
824
+ before { configuration.convert_have_items = false }
825
+
826
+ it 'does not invoke Have#convert_to_standard_expectation!' do
827
+ have_object.should_not_receive(:convert_to_standard_expectation!)
828
+ converter.process_have(have_object)
829
+ end
830
+ end
831
+ end
832
+
874
833
  describe '#process_raise_error' do
875
834
  let(:raise_error_object) { double('raise_error_object').as_null_object }
876
835
 
@@ -1079,6 +1038,45 @@ module Transpec
1079
1038
  end
1080
1039
  end
1081
1040
 
1041
+ describe '#process_example_group' do
1042
+ let(:example_group) { double('example_group').as_null_object }
1043
+
1044
+ context 'when RSpecVersion#non_monkey_patch_example_group_available? returns true' do
1045
+ before { rspec_version.stub(:non_monkey_patch_example_group_available?).and_return(true) }
1046
+
1047
+ context 'and Configuration#convert_example_group? is true' do
1048
+ before { configuration.convert_example_group = true }
1049
+
1050
+ it 'invokes ExampleGroup#convert_to_non_monkey_patch!' do
1051
+ example_group.should_receive(:convert_to_non_monkey_patch!)
1052
+ converter.process_example_group(example_group)
1053
+ end
1054
+ end
1055
+
1056
+ context 'and Configuration#convert_example_group? is false' do
1057
+ before { configuration.convert_example_group = false }
1058
+
1059
+ it 'does nothing' do
1060
+ example_group.should_not_receive(:convert_to_non_monkey_patch!)
1061
+ converter.process_example_group(example_group)
1062
+ end
1063
+ end
1064
+ end
1065
+
1066
+ context 'when RSpecVersion#non_monkey_patch_example_group_available? returns false' do
1067
+ before { rspec_version.stub(:non_monkey_patch_example_group_available?).and_return(false) }
1068
+
1069
+ context 'and Configuration#convert_example_group? is true' do
1070
+ before { configuration.convert_example_group = true }
1071
+
1072
+ it 'does nothing' do
1073
+ example_group.should_not_receive(:convert_to_non_monkey_patch!)
1074
+ converter.process_example_group(example_group)
1075
+ end
1076
+ end
1077
+ end
1078
+ end
1079
+
1082
1080
  describe '#process_rspec_configure' do
1083
1081
  let(:rspec_configure) do
1084
1082
  double(
@@ -1140,21 +1138,67 @@ module Transpec
1140
1138
  context 'and Configuration#convert_deprecated_method? returns true' do
1141
1139
  before { configuration.convert_deprecated_method = true }
1142
1140
 
1143
- context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
1144
- before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
1141
+ context 'and SpecSuite#main_rspec_configure_node? returns true' do
1142
+ before do
1143
+ spec_suite.stub(:main_rspec_configure_node?).and_return(true)
1144
+ end
1145
+
1146
+ context 'and SpecSuite#need_to_modify_yield_receiver_..._configuration? return true' do
1147
+ before do
1148
+ spec_suite.stub(:need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?)
1149
+ .and_return(true)
1150
+ end
1145
1151
 
1146
- it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with true' do
1147
- rspec_configure.mocks.should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(true)
1148
- converter.process_rspec_configure(rspec_configure)
1152
+ context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
1153
+ before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
1154
+
1155
+ it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with true' do
1156
+ rspec_configure.mocks
1157
+ .should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(true)
1158
+ converter.process_rspec_configure(rspec_configure)
1159
+ end
1160
+ end
1161
+
1162
+ context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns false' do
1163
+ before { configuration.add_receiver_arg_to_any_instance_implementation_block = false }
1164
+
1165
+ it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with false' do
1166
+ rspec_configure.mocks
1167
+ .should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(false)
1168
+ converter.process_rspec_configure(rspec_configure)
1169
+ end
1170
+ end
1149
1171
  end
1150
1172
  end
1151
1173
 
1152
- context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns false' do
1153
- before { configuration.add_receiver_arg_to_any_instance_implementation_block = false }
1174
+ context 'and SpecSuite#need_to_modify_yield_receiver_..._configuration? return false' do
1175
+ before do
1176
+ spec_suite.stub(:need_to_modify_yield_receiver_to_any_instance_implementation_blocks_config?)
1177
+ .and_return(false)
1178
+ end
1179
+
1180
+ context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
1181
+ before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
1182
+
1183
+ it 'does not invoke RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks=' do
1184
+ rspec_configure.mocks.should_not_receive(:yield_receiver_to_any_instance_implementation_blocks=)
1185
+ converter.process_rspec_configure(rspec_configure)
1186
+ end
1187
+ end
1188
+ end
1189
+
1190
+ context 'and SpecSuite#main_rspec_configure_node? returns false' do
1191
+ before do
1192
+ spec_suite.stub(:main_rspec_configure_node?).and_return(false)
1193
+ end
1194
+
1195
+ context 'and Configuration#add_receiver_arg_to_any_instance_implementation_block? returns true' do
1196
+ before { configuration.add_receiver_arg_to_any_instance_implementation_block = true }
1154
1197
 
1155
- it 'invokes RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks= with false' do
1156
- rspec_configure.mocks.should_receive(:yield_receiver_to_any_instance_implementation_blocks=).with(false)
1157
- converter.process_rspec_configure(rspec_configure)
1198
+ it 'does not invoke RSpecConfigure.mocks.yield_receiver_to_any_instance_implementation_blocks=' do
1199
+ rspec_configure.mocks.should_not_receive(:yield_receiver_to_any_instance_implementation_blocks=)
1200
+ converter.process_rspec_configure(rspec_configure)
1201
+ end
1158
1202
  end
1159
1203
  end
1160
1204
  end
@@ -1179,6 +1223,41 @@ module Transpec
1179
1223
  converter.process_rspec_configure(rspec_configure)
1180
1224
  end
1181
1225
  end
1226
+
1227
+ context 'when RSpecVersion#non_monkey_patch_example_group_available? returns true' do
1228
+ before { rspec_version.stub(:non_monkey_patch_example_group_available?).and_return(true) }
1229
+
1230
+ context 'and Configuration#convert_example_group? is true' do
1231
+ before { configuration.convert_example_group = true }
1232
+
1233
+ it 'invokes RSpecConfigure#expose_dsl_globally= with false' do
1234
+ rspec_configure.should_receive(:expose_dsl_globally=).with(false)
1235
+ converter.process_rspec_configure(rspec_configure)
1236
+ end
1237
+ end
1238
+
1239
+ context 'and Configuration#convert_example_group? is false' do
1240
+ before { configuration.convert_example_group = false }
1241
+
1242
+ it 'does nothing' do
1243
+ rspec_configure.should_not_receive(:expose_dsl_globally=)
1244
+ converter.process_rspec_configure(rspec_configure)
1245
+ end
1246
+ end
1247
+ end
1248
+
1249
+ context 'when RSpecVersion#non_monkey_patch_example_group_available? returns false' do
1250
+ before { rspec_version.stub(:non_monkey_patch_example_group_available?).and_return(false) }
1251
+
1252
+ context 'and Configuration#convert_example_group? is true' do
1253
+ before { configuration.convert_example_group = true }
1254
+
1255
+ it 'does nothing' do
1256
+ rspec_configure.should_not_receive(:expose_dsl_globally=)
1257
+ converter.process_rspec_configure(rspec_configure)
1258
+ end
1259
+ end
1260
+ end
1182
1261
  end
1183
1262
 
1184
1263
  describe '#process_useless_and_return' do