transpec 0.1.3 → 0.2.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/CHANGELOG.md +5 -0
  3. data/README.md +35 -3
  4. data/README.md.erb +35 -3
  5. data/lib/transpec/cli.rb +50 -4
  6. data/lib/transpec/commit_message.rb +25 -0
  7. data/lib/transpec/git.rb +18 -0
  8. data/lib/transpec/record.rb +28 -0
  9. data/lib/transpec/report.rb +109 -0
  10. data/lib/transpec/rewriter.rb +17 -8
  11. data/lib/transpec/syntax.rb +25 -22
  12. data/lib/transpec/syntax/be_close.rb +6 -0
  13. data/lib/transpec/syntax/double.rb +5 -0
  14. data/lib/transpec/syntax/matcher.rb +17 -1
  15. data/lib/transpec/syntax/method_stub.rb +40 -8
  16. data/lib/transpec/syntax/raise_error.rb +17 -0
  17. data/lib/transpec/syntax/send_node_syntax.rb +4 -0
  18. data/lib/transpec/syntax/should.rb +23 -2
  19. data/lib/transpec/syntax/should_receive.rb +54 -2
  20. data/lib/transpec/version.rb +2 -2
  21. data/spec/.rubocop.yml +1 -1
  22. data/spec/support/shared_context.rb +10 -0
  23. data/spec/transpec/cli_spec.rb +76 -29
  24. data/spec/transpec/commit_message_spec.rb +63 -0
  25. data/spec/transpec/configuration_spec.rb +1 -1
  26. data/spec/transpec/git_spec.rb +114 -38
  27. data/spec/transpec/record_spec.rb +18 -0
  28. data/spec/transpec/report_spec.rb +89 -0
  29. data/spec/transpec/rewriter_spec.rb +5 -0
  30. data/spec/transpec/syntax/be_close_spec.rb +10 -1
  31. data/spec/transpec/syntax/double_spec.rb +10 -0
  32. data/spec/transpec/syntax/matcher_spec.rb +31 -0
  33. data/spec/transpec/syntax/method_stub_spec.rb +53 -44
  34. data/spec/transpec/syntax/raise_error_spec.rb +64 -24
  35. data/spec/transpec/syntax/should_receive_spec.rb +67 -7
  36. data/spec/transpec/syntax/should_spec.rb +26 -0
  37. data/tasks/test.rake +27 -12
  38. metadata +11 -2
@@ -20,16 +20,18 @@ module Transpec
20
20
  fail 'No raise_error node is found!'
21
21
  end
22
22
 
23
+ let(:record) { raise_error_object.report.records.first }
24
+
23
25
  describe '#remove_error_specification_with_negative_expectation!' do
24
26
  before do
25
27
  raise_error_object.remove_error_specification_with_negative_expectation!
26
28
  end
27
29
 
28
- context 'when it is `lambda { ... }.should raise_error(SomeErrorClass)` form' do
30
+ context 'when it is `lambda { }.should raise_error(SpecificErrorClass)` form' do
29
31
  let(:source) do
30
32
  <<-END
31
- it 'raises SomeErrorClass' do
32
- lambda { do_something }.should raise_error(SomeErrorClass)
33
+ it 'raises SpecificErrorClass' do
34
+ lambda { do_something }.should raise_error(SpecificErrorClass)
33
35
  end
34
36
  END
35
37
  end
@@ -37,13 +39,17 @@ module Transpec
37
39
  it 'does nothing' do
38
40
  rewritten_source.should == source
39
41
  end
42
+
43
+ it 'reports nothing' do
44
+ raise_error_object.report.records.should be_empty
45
+ end
40
46
  end
41
47
 
42
- context 'when it is `expect { ... }.to raise_error(SomeErrorClass)` form' do
48
+ context 'when it is `expect { }.to raise_error(SpecificErrorClass)` form' do
43
49
  let(:source) do
44
50
  <<-END
45
- it 'raises SomeErrorClass' do
46
- expect { do_something }.to raise_error(SomeErrorClass)
51
+ it 'raises SpecificErrorClass' do
52
+ expect { do_something }.to raise_error(SpecificErrorClass)
47
53
  end
48
54
  END
49
55
  end
@@ -51,13 +57,17 @@ module Transpec
51
57
  it 'does nothing' do
52
58
  rewritten_source.should == source
53
59
  end
60
+
61
+ it 'reports nothing' do
62
+ raise_error_object.report.records.should be_empty
63
+ end
54
64
  end
55
65
 
56
- context 'when it is `lambda { ... }.should_not raise_error(SomeErrorClass)` form' do
66
+ context 'when it is `lambda { }.should_not raise_error(SpecificErrorClass)` form' do
57
67
  let(:source) do
58
68
  <<-END
59
69
  it 'does not raise error' do
60
- lambda { do_something }.should_not raise_error(SomeErrorClass)
70
+ lambda { do_something }.should_not raise_error(SpecificErrorClass)
61
71
  end
62
72
  END
63
73
  end
@@ -70,16 +80,22 @@ module Transpec
70
80
  END
71
81
  end
72
82
 
73
- it 'converts into `lambda { ... }.should_not raise_error` form' do
83
+ it 'converts into `lambda { }.should_not raise_error` form' do
74
84
  rewritten_source.should == expected_source
75
85
  end
86
+
87
+ it 'adds record ' +
88
+ '"`expect { }.not_to raise_error(SpecificErrorClass)` -> `expect { }.not_to raise_error`\"' do
89
+ record.original_syntax.should == 'expect { }.not_to raise_error(SpecificErrorClass)'
90
+ record.converted_syntax.should == 'expect { }.not_to raise_error'
91
+ end
76
92
  end
77
93
 
78
- context 'when it is `expect { ... }.not_to raise_error(SomeErrorClass)` form' do
94
+ context 'when it is `expect { }.not_to raise_error(SpecificErrorClass)` form' do
79
95
  let(:source) do
80
96
  <<-END
81
97
  it 'does not raise error' do
82
- expect { do_something }.not_to raise_error(SomeErrorClass)
98
+ expect { do_something }.not_to raise_error(SpecificErrorClass)
83
99
  end
84
100
  END
85
101
  end
@@ -92,16 +108,16 @@ module Transpec
92
108
  END
93
109
  end
94
110
 
95
- it 'converts into `expect { ... }.not_to raise_error` form' do
111
+ it 'converts into `expect { }.not_to raise_error` form' do
96
112
  rewritten_source.should == expected_source
97
113
  end
98
114
  end
99
115
 
100
- context 'when it is `expect { ... }.to_not raise_error(SomeErrorClass)` form' do
116
+ context 'when it is `expect { }.to_not raise_error(SpecificErrorClass)` form' do
101
117
  let(:source) do
102
118
  <<-END
103
119
  it 'does not raise error' do
104
- expect { do_something }.to_not raise_error(SomeErrorClass)
120
+ expect { do_something }.to_not raise_error(SpecificErrorClass)
105
121
  end
106
122
  END
107
123
  end
@@ -114,16 +130,22 @@ module Transpec
114
130
  END
115
131
  end
116
132
 
117
- it 'converts into `expect { ... }.to_not raise_error` form' do
133
+ it 'converts into `expect { }.to_not raise_error` form' do
118
134
  rewritten_source.should == expected_source
119
135
  end
136
+
137
+ it 'adds record ' +
138
+ '"`expect { }.not_to raise_error(SpecificErrorClass)` -> `expect { }.not_to raise_error`\"' do
139
+ record.original_syntax.should == 'expect { }.not_to raise_error(SpecificErrorClass)'
140
+ record.converted_syntax.should == 'expect { }.not_to raise_error'
141
+ end
120
142
  end
121
143
 
122
- context 'when it is `expect { ... }.not_to raise_error SomeErrorClass` form' do
144
+ context 'when it is `expect { }.not_to raise_error SpecificErrorClass` form' do
123
145
  let(:source) do
124
146
  <<-END
125
147
  it 'does not raise error' do
126
- expect { do_something }.not_to raise_error SomeErrorClass
148
+ expect { do_something }.not_to raise_error SpecificErrorClass
127
149
  end
128
150
  END
129
151
  end
@@ -136,16 +158,22 @@ module Transpec
136
158
  END
137
159
  end
138
160
 
139
- it 'converts into `expect { ... }.not_to raise_error` form' do
161
+ it 'converts into `expect { }.not_to raise_error` form' do
140
162
  rewritten_source.should == expected_source
141
163
  end
164
+
165
+ it 'adds record ' +
166
+ '"`expect { }.not_to raise_error(SpecificErrorClass)` -> `expect { }.not_to raise_error`\"' do
167
+ record.original_syntax.should == 'expect { }.not_to raise_error(SpecificErrorClass)'
168
+ record.converted_syntax.should == 'expect { }.not_to raise_error'
169
+ end
142
170
  end
143
171
 
144
- context "when it is `expect { ... }.not_to raise_error(SomeErrorClass, 'message')` form" do
172
+ context 'when it is `expect { }.not_to raise_error(SpecificErrorClass, message)` form' do
145
173
  let(:source) do
146
174
  <<-END
147
175
  it 'does not raise error' do
148
- expect { do_something }.not_to raise_error(SomeErrorClass, 'message')
176
+ expect { do_something }.not_to raise_error(SpecificErrorClass, message)
149
177
  end
150
178
  END
151
179
  end
@@ -158,16 +186,22 @@ module Transpec
158
186
  END
159
187
  end
160
188
 
161
- it 'converts into `expect { ... }.not_to raise_error` form' do
189
+ it 'converts into `expect { }.not_to raise_error` form' do
162
190
  rewritten_source.should == expected_source
163
191
  end
192
+
193
+ it 'adds record ' +
194
+ '"`expect { }.not_to raise_error(SpecificErrorClass, message)` -> `expect { }.not_to raise_error`"' do
195
+ record.original_syntax.should == 'expect { }.not_to raise_error(SpecificErrorClass, message)'
196
+ record.converted_syntax.should == 'expect { }.not_to raise_error'
197
+ end
164
198
  end
165
199
 
166
- context "when it is `expect { ... }.not_to raise_error(nil, 'message')` form" do
200
+ context 'when it is `expect { }.not_to raise_error(message)` form' do
167
201
  let(:source) do
168
202
  <<-END
169
203
  it 'does not raise error' do
170
- expect { do_something }.not_to raise_error(nil, 'message')
204
+ expect { do_something }.not_to raise_error(message)
171
205
  end
172
206
  END
173
207
  end
@@ -180,9 +214,15 @@ module Transpec
180
214
  END
181
215
  end
182
216
 
183
- it 'converts into `expect { ... }.not_to raise_error` form' do
217
+ it 'converts into `expect { }.not_to raise_error` form' do
184
218
  rewritten_source.should == expected_source
185
219
  end
220
+
221
+ it 'adds record ' +
222
+ '"`expect { }.not_to raise_error(message)` -> `expect { }.not_to raise_error`"' do
223
+ record.original_syntax.should == 'expect { }.not_to raise_error(message)'
224
+ record.converted_syntax.should == 'expect { }.not_to raise_error'
225
+ end
186
226
  end
187
227
  end
188
228
  end
@@ -20,6 +20,8 @@ module Transpec
20
20
  fail 'No should_receive node is found!'
21
21
  end
22
22
 
23
+ let(:record) { should_receive_object.report.records.first }
24
+
23
25
  before do
24
26
  should_receive_object.context.stub(:in_example_group?).and_return(true)
25
27
  end
@@ -46,6 +48,12 @@ module Transpec
46
48
  should_receive_object.expectize!
47
49
  rewritten_source.should == expected_source
48
50
  end
51
+
52
+ it 'adds record "`obj.should_receive(:message)` -> `expect(obj).to receive(:message)`"' do
53
+ should_receive_object.expectize!
54
+ record.original_syntax.should == 'obj.should_receive(:message)'
55
+ record.converted_syntax.should == 'expect(obj).to receive(:message)'
56
+ end
49
57
  end
50
58
 
51
59
  context 'when it is `subject.should_not_receive(:method)` form' do
@@ -70,6 +78,13 @@ module Transpec
70
78
  rewritten_source.should == expected_source
71
79
  end
72
80
 
81
+ it 'adds record ' +
82
+ '"`obj.should_not_receive(:message)` -> `expect(obj).not_to receive(:message)`"' do
83
+ should_receive_object.expectize!
84
+ record.original_syntax.should == 'obj.should_not_receive(:message)'
85
+ record.converted_syntax.should == 'expect(obj).not_to receive(:message)'
86
+ end
87
+
73
88
  context 'and "to_not" is passed as negative form' do
74
89
  let(:expected_source) do
75
90
  <<-END
@@ -83,6 +98,13 @@ module Transpec
83
98
  should_receive_object.expectize!('to_not')
84
99
  rewritten_source.should == expected_source
85
100
  end
101
+
102
+ it 'adds record ' +
103
+ '"`obj.should_not_receive(:message)` -> `expect(obj).to_not receive(:message)`"' do
104
+ should_receive_object.expectize!('to_not')
105
+ record.original_syntax.should == 'obj.should_not_receive(:message)'
106
+ record.converted_syntax.should == 'expect(obj).to_not receive(:message)'
107
+ end
86
108
  end
87
109
  end
88
110
 
@@ -281,6 +303,13 @@ module Transpec
281
303
  should_receive_object.expectize!
282
304
  rewritten_source.should == expected_source
283
305
  end
306
+
307
+ it 'adds record "`SomeClass.any_instance.should_receive(:message)` ' +
308
+ '-> `expect_any_instance_of(SomeClass).to receive(:message)`"' do
309
+ should_receive_object.expectize!
310
+ record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message)'
311
+ record.converted_syntax.should == 'expect_any_instance_of(SomeClass).to receive(:message)'
312
+ end
284
313
  end
285
314
  end
286
315
 
@@ -349,6 +378,10 @@ module Transpec
349
378
  end
350
379
 
351
380
  describe '#allowize_useless_expectation!' do
381
+ before do
382
+ should_receive_object.allowize_useless_expectation!
383
+ end
384
+
352
385
  context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
353
386
  let(:source) do
354
387
  <<-END
@@ -367,9 +400,14 @@ module Transpec
367
400
  end
368
401
 
369
402
  it 'converts into `allow(subject).to receive(:method)` form' do
370
- should_receive_object.allowize_useless_expectation!
371
403
  rewritten_source.should == expected_source
372
404
  end
405
+
406
+ it 'adds record ' +
407
+ '"`obj.should_receive(:message).any_number_of_times` -> `allow(obj).to receive(:message)`"' do
408
+ record.original_syntax.should == 'obj.should_receive(:message).any_number_of_times'
409
+ record.converted_syntax.should == 'allow(obj).to receive(:message)'
410
+ end
373
411
  end
374
412
 
375
413
  context 'when it is `SomeClass.any_instance.should_receive(:method).any_number_of_times` form' do
@@ -390,9 +428,14 @@ module Transpec
390
428
  end
391
429
 
392
430
  it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
393
- should_receive_object.allowize_useless_expectation!
394
431
  rewritten_source.should == expected_source
395
432
  end
433
+
434
+ it 'adds record "`SomeClass.any_instance.should_receive(:message).any_number_of_times` ' +
435
+ '-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
436
+ record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).any_number_of_times'
437
+ record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
438
+ end
396
439
  end
397
440
 
398
441
  context 'when it is `subject.should_receive(:method).at_least(0)` form' do
@@ -413,9 +456,14 @@ module Transpec
413
456
  end
414
457
 
415
458
  it 'converts into `allow(subject).to receive(:method)` form' do
416
- should_receive_object.allowize_useless_expectation!
417
459
  rewritten_source.should == expected_source
418
460
  end
461
+
462
+ it 'adds record ' +
463
+ '"`obj.should_receive(:message).at_least(0)` -> `allow(obj).to receive(:message)`"' do
464
+ record.original_syntax.should == 'obj.should_receive(:message).at_least(0)'
465
+ record.converted_syntax.should == 'allow(obj).to receive(:message)'
466
+ end
419
467
  end
420
468
 
421
469
  context 'when it is `SomeClass.any_instance.should_receive(:method).at_least(0)` form' do
@@ -436,9 +484,14 @@ module Transpec
436
484
  end
437
485
 
438
486
  it 'converts into `allow_any_instance_of(subject).to receive(:method)` form' do
439
- should_receive_object.allowize_useless_expectation!
440
487
  rewritten_source.should == expected_source
441
488
  end
489
+
490
+ it 'adds record "`SomeClass.any_instance.should_receive(:message).at_least(0)` ' +
491
+ '-> `allow_any_instance_of(SomeClass).to receive(:message)`"' do
492
+ record.original_syntax.should == 'SomeClass.any_instance.should_receive(:message).at_least(0)'
493
+ record.converted_syntax.should == 'allow_any_instance_of(SomeClass).to receive(:message)'
494
+ end
442
495
  end
443
496
 
444
497
  context 'when it is `subject.should_receive(:method)` form' do
@@ -451,13 +504,16 @@ module Transpec
451
504
  end
452
505
 
453
506
  it 'does nothing' do
454
- should_receive_object.allowize_useless_expectation!
455
507
  rewritten_source.should == source
456
508
  end
457
509
  end
458
510
  end
459
511
 
460
512
  describe '#stubize_useless_expectation!' do
513
+ before do
514
+ should_receive_object.stubize_useless_expectation!
515
+ end
516
+
461
517
  context 'when it is `subject.should_receive(:method).any_number_of_times` form' do
462
518
  let(:source) do
463
519
  <<-END
@@ -476,9 +532,14 @@ module Transpec
476
532
  end
477
533
 
478
534
  it 'converts into `subject.stub(:method)` form' do
479
- should_receive_object.stubize_useless_expectation!
480
535
  rewritten_source.should == expected_source
481
536
  end
537
+
538
+ it 'adds record ' +
539
+ '"`obj.should_receive(:message).any_number_of_times` -> `obj.stub(:message)`"' do
540
+ record.original_syntax.should == 'obj.should_receive(:message).any_number_of_times'
541
+ record.converted_syntax.should == 'obj.stub(:message)'
542
+ end
482
543
  end
483
544
 
484
545
  context 'when it is `subject.should_receive(:method)` form' do
@@ -491,7 +552,6 @@ module Transpec
491
552
  end
492
553
 
493
554
  it 'does nothing' do
494
- should_receive_object.stubize_useless_expectation!
495
555
  rewritten_source.should == source
496
556
  end
497
557
  end
@@ -9,6 +9,8 @@ module Transpec
9
9
  include_context 'parsed objects'
10
10
  include_context 'should object'
11
11
 
12
+ let(:record) { should_object.report.records.first }
13
+
12
14
  before do
13
15
  should_object.context.stub(:in_example_group?).and_return(true)
14
16
  end
@@ -121,6 +123,12 @@ module Transpec
121
123
  should_object.expectize!
122
124
  rewritten_source.should == expected_source
123
125
  end
126
+
127
+ it 'adds record "`obj.should` -> `expect(obj).to`"' do
128
+ should_object.expectize!
129
+ record.original_syntax.should == 'obj.should'
130
+ record.converted_syntax.should == 'expect(obj).to'
131
+ end
124
132
  end
125
133
 
126
134
  context 'when it is `subject.should_not` form' do
@@ -145,6 +153,12 @@ module Transpec
145
153
  rewritten_source.should == expected_source
146
154
  end
147
155
 
156
+ it 'adds record "`obj.should_not` -> `expect(obj).not_to`"' do
157
+ should_object.expectize!
158
+ record.original_syntax.should == 'obj.should_not'
159
+ record.converted_syntax.should == 'expect(obj).not_to'
160
+ end
161
+
148
162
  context 'and "to_not" is passed as negative form' do
149
163
  let(:expected_source) do
150
164
  <<-END
@@ -158,6 +172,12 @@ module Transpec
158
172
  should_object.expectize!('to_not')
159
173
  rewritten_source.should == expected_source
160
174
  end
175
+
176
+ it 'adds record "`obj.should_not` -> `expect(obj).to_not`"' do
177
+ should_object.expectize!('to_not')
178
+ record.original_syntax.should == 'obj.should_not'
179
+ record.converted_syntax.should == 'expect(obj).to_not'
180
+ end
161
181
  end
162
182
  end
163
183
 
@@ -234,6 +254,12 @@ module Transpec
234
254
  should_object.expectize!
235
255
  rewritten_source.should == expected_source
236
256
  end
257
+
258
+ it 'adds record "`lambda { }.should` -> `expect { }.to`"' do
259
+ should_object.expectize!
260
+ record.original_syntax.should == 'lambda { }.should'
261
+ record.converted_syntax.should == 'expect { }.to'
262
+ end
237
263
  end
238
264
  end
239
265
 
data/tasks/test.rake CHANGED
@@ -37,14 +37,9 @@ class TranspecTest
37
37
 
38
38
  puts " Testing on #{name} Project ".center(80, '=')
39
39
 
40
- prepare_project
41
-
42
- in_project_dir do
43
- with_clean_bundler_env do
44
- sh 'bundle', 'install', *bundler_args
45
- sh File.join(Transpec.root, 'bin', 'transpec'), '--force'
46
- sh 'bundle exec rspec'
47
- end
40
+ [%w(--force), %w(--force --no-parentheses-matcher-arg)].each do |args|
41
+ prepare_project
42
+ run_test(args)
48
43
  end
49
44
  end
50
45
 
@@ -72,19 +67,31 @@ class TranspecTest
72
67
  FileUtils.cp_r(entry, project_dir)
73
68
  end
74
69
  end
70
+
71
+ bundle_install
75
72
  end
76
73
 
77
74
  def prepare_with_git_repo
78
75
  if Dir.exist?(project_dir)
79
76
  if current_ref == ref
80
77
  git_reset_hard
78
+ return
81
79
  else
82
80
  require 'fileutils'
83
81
  FileUtils.rm_rf(project_dir)
84
- git_clone
85
82
  end
86
- else
87
- git_clone
83
+ end
84
+
85
+ git_clone
86
+ bundle_install
87
+ end
88
+
89
+ def run_test(transpec_args = [])
90
+ in_project_dir do
91
+ with_clean_bundler_env do
92
+ sh File.join(Transpec.root, 'bin', 'transpec'), *transpec_args
93
+ sh 'bundle exec rspec'
94
+ end
88
95
  end
89
96
  end
90
97
 
@@ -115,6 +122,14 @@ class TranspecTest
115
122
  end
116
123
  end
117
124
 
125
+ def bundle_install
126
+ in_project_dir do
127
+ with_clean_bundler_env do
128
+ sh 'bundle', 'install', *bundler_args
129
+ end
130
+ end
131
+ end
132
+
118
133
  def with_clean_bundler_env
119
134
  if defined?(Bundler)
120
135
  Bundler.with_clean_env do
@@ -145,7 +160,7 @@ namespace :test do
145
160
 
146
161
  # rubocop:disable LineLength
147
162
  tests = [
148
- TranspecTest.new(File.expand_path('.'), nil, []),
163
+ TranspecTest.new(File.expand_path('.'), nil, ['--quiet']),
149
164
  TranspecTest.new('https://github.com/sferik/twitter.git', 'v4.1.0', bundler_args),
150
165
  TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec', bundler_args + %w(--without development)),
151
166
  TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec', bundler_args)