transpec 1.1.2 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +10 -2
- data/Guardfile +1 -1
- data/README.md +41 -2
- data/README.md.erb +42 -3
- data/lib/transpec/cli.rb +16 -7
- data/lib/transpec/configuration.rb +25 -7
- data/lib/transpec/converter.rb +18 -3
- data/lib/transpec/dynamic_analyzer.rb +8 -23
- data/lib/transpec/option_parser.rb +22 -3
- data/lib/transpec/project.rb +49 -0
- data/lib/transpec/rspec_version.rb +25 -0
- data/lib/transpec/syntax/be_boolean.rb +38 -0
- data/lib/transpec/syntax/method_stub.rb +29 -12
- data/lib/transpec/version.rb +2 -2
- data/lib/transpec.rb +24 -0
- data/spec/support/cache_helper.rb +13 -2
- data/spec/transpec/cli_spec.rb +38 -7
- data/spec/transpec/configuration_spec.rb +43 -8
- data/spec/transpec/converter_spec.rb +70 -6
- data/spec/transpec/option_parser_spec.rb +33 -1
- data/spec/transpec/project_spec.rb +73 -0
- data/spec/transpec/rspec_version_spec.rb +44 -0
- data/spec/transpec/syntax/be_boolean_spec.rb +183 -0
- data/spec/transpec/syntax/method_stub_spec.rb +122 -49
- data/spec/transpec_spec.rb +16 -0
- data/tasks/test.rake +3 -3
- metadata +13 -2
@@ -0,0 +1,183 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'transpec/syntax/be_boolean'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
class Syntax
|
8
|
+
describe BeBoolean do
|
9
|
+
include_context 'parsed objects'
|
10
|
+
|
11
|
+
subject(:be_boolean_object) do
|
12
|
+
ast.each_node do |node|
|
13
|
+
next unless BeBoolean.target_node?(node)
|
14
|
+
return BeBoolean.new(node, source_rewriter)
|
15
|
+
end
|
16
|
+
fail 'No be_boolean node is found!'
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:record) { be_boolean_object.report.records.last }
|
20
|
+
|
21
|
+
describe '#convert_to_conditional_matcher!' do
|
22
|
+
before do
|
23
|
+
be_boolean_object.convert_to_conditional_matcher!(arg)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:arg) { 'be_falsey' }
|
27
|
+
|
28
|
+
context 'when it is `be_true`' do
|
29
|
+
let(:source) do
|
30
|
+
<<-END
|
31
|
+
describe 'example' do
|
32
|
+
it 'is truthy' do
|
33
|
+
1.should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
END
|
37
|
+
end
|
38
|
+
|
39
|
+
let(:expected_source) do
|
40
|
+
<<-END
|
41
|
+
describe 'example' do
|
42
|
+
it 'is truthy' do
|
43
|
+
1.should be_truthy
|
44
|
+
end
|
45
|
+
end
|
46
|
+
END
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'converts into `be_truthy`' do
|
50
|
+
rewritten_source.should == expected_source
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'adds record "`be_true` -> `be_truthy`"' do
|
54
|
+
record.original_syntax.should == 'be_true'
|
55
|
+
record.converted_syntax.should == 'be_truthy'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when it is `be_false`' do
|
60
|
+
let(:source) do
|
61
|
+
<<-END
|
62
|
+
describe 'example' do
|
63
|
+
it 'is falsey' do
|
64
|
+
nil.should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
END
|
68
|
+
end
|
69
|
+
|
70
|
+
let(:expected_source) do
|
71
|
+
<<-END
|
72
|
+
describe 'example' do
|
73
|
+
it 'is falsey' do
|
74
|
+
nil.should be_falsey
|
75
|
+
end
|
76
|
+
end
|
77
|
+
END
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'converts into `be_falsey`' do
|
81
|
+
rewritten_source.should == expected_source
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'adds record "`be_false` -> `be_falsey`"' do
|
85
|
+
record.original_syntax.should == 'be_false'
|
86
|
+
record.converted_syntax.should == 'be_falsey'
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'and "be_falsy" is passed' do
|
90
|
+
let(:arg) { 'be_falsy' }
|
91
|
+
|
92
|
+
let(:expected_source) do
|
93
|
+
<<-END
|
94
|
+
describe 'example' do
|
95
|
+
it 'is falsey' do
|
96
|
+
nil.should be_falsy
|
97
|
+
end
|
98
|
+
end
|
99
|
+
END
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'converts into `be_falsy`' do
|
103
|
+
rewritten_source.should == expected_source
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'adds record "`be_false` -> `be_falsy`"' do
|
107
|
+
record.original_syntax.should == 'be_false'
|
108
|
+
record.converted_syntax.should == 'be_falsy'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#convert_to_exact_matcher!' do
|
115
|
+
before do
|
116
|
+
be_boolean_object.convert_to_exact_matcher!
|
117
|
+
end
|
118
|
+
|
119
|
+
context 'when it is `be_true`' do
|
120
|
+
let(:source) do
|
121
|
+
<<-END
|
122
|
+
describe 'example' do
|
123
|
+
it 'is true' do
|
124
|
+
true.should be_true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
END
|
128
|
+
end
|
129
|
+
|
130
|
+
let(:expected_source) do
|
131
|
+
<<-END
|
132
|
+
describe 'example' do
|
133
|
+
it 'is true' do
|
134
|
+
true.should be true
|
135
|
+
end
|
136
|
+
end
|
137
|
+
END
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'converts into `be true`' do
|
141
|
+
rewritten_source.should == expected_source
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'adds record "`be_true` -> `be true`"' do
|
145
|
+
record.original_syntax.should == 'be_true'
|
146
|
+
record.converted_syntax.should == 'be true'
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'when it is `be_false`' do
|
151
|
+
let(:source) do
|
152
|
+
<<-END
|
153
|
+
describe 'example' do
|
154
|
+
it 'is false' do
|
155
|
+
false.should be_false
|
156
|
+
end
|
157
|
+
end
|
158
|
+
END
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:expected_source) do
|
162
|
+
<<-END
|
163
|
+
describe 'example' do
|
164
|
+
it 'is false' do
|
165
|
+
false.should be false
|
166
|
+
end
|
167
|
+
end
|
168
|
+
END
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'converts into `be false`' do
|
172
|
+
rewritten_source.should == expected_source
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'adds record "`be_false` -> `be false`"' do
|
176
|
+
record.original_syntax.should == 'be_false'
|
177
|
+
record.converted_syntax.should == 'be false'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
@@ -296,36 +296,72 @@ module Transpec
|
|
296
296
|
end
|
297
297
|
|
298
298
|
context "when it is `subject.#{method}(:method => value)` form" do
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
299
|
+
context 'and #receive_messages is available' do
|
300
|
+
let(:source) do
|
301
|
+
<<-END
|
302
|
+
describe 'example' do
|
303
|
+
it 'responds to #foo and returns 1' do
|
304
|
+
subject.#{method}(:foo => 1)
|
305
|
+
end
|
304
306
|
end
|
305
|
-
|
306
|
-
|
307
|
-
end
|
307
|
+
END
|
308
|
+
end
|
308
309
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
310
|
+
let(:expected_source) do
|
311
|
+
<<-END
|
312
|
+
describe 'example' do
|
313
|
+
it 'responds to #foo and returns 1' do
|
314
|
+
allow(subject).to receive_messages(:foo => 1)
|
315
|
+
end
|
314
316
|
end
|
315
|
-
|
316
|
-
|
317
|
-
end
|
317
|
+
END
|
318
|
+
end
|
318
319
|
|
319
|
-
|
320
|
-
|
321
|
-
|
320
|
+
it 'converts into `allow(subject).to receive_messages(:method => value)` form' do
|
321
|
+
method_stub_object.allowize!(true)
|
322
|
+
rewritten_source.should == expected_source
|
323
|
+
end
|
324
|
+
|
325
|
+
it 'adds record ' +
|
326
|
+
"\"`obj.#{method}(:message => value)` -> `allow(obj).to receive_messages(:message => value)`\"" do
|
327
|
+
method_stub_object.allowize!(true)
|
328
|
+
record.original_syntax.should == "obj.#{method}(:message => value)"
|
329
|
+
record.converted_syntax.should == 'allow(obj).to receive_messages(:message => value)'
|
330
|
+
end
|
322
331
|
end
|
323
332
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
333
|
+
context 'and #receive_messages is not available' do
|
334
|
+
let(:source) do
|
335
|
+
<<-END
|
336
|
+
describe 'example' do
|
337
|
+
it 'responds to #foo and returns 1' do
|
338
|
+
subject.#{method}(:foo => 1)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
END
|
342
|
+
end
|
343
|
+
|
344
|
+
let(:expected_source) do
|
345
|
+
<<-END
|
346
|
+
describe 'example' do
|
347
|
+
it 'responds to #foo and returns 1' do
|
348
|
+
allow(subject).to receive(:foo).and_return(1)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
END
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'converts into `allow(subject).to receive(:method).and_return(value)` form' do
|
355
|
+
method_stub_object.allowize!
|
356
|
+
rewritten_source.should == expected_source
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'adds record ' +
|
360
|
+
"\"`obj.#{method}(:message => value)` -> `allow(obj).to receive(:message).and_return(value)`\"" do
|
361
|
+
method_stub_object.allowize!
|
362
|
+
record.original_syntax.should == "obj.#{method}(:message => value)"
|
363
|
+
record.converted_syntax.should == 'allow(obj).to receive(:message).and_return(value)'
|
364
|
+
end
|
329
365
|
end
|
330
366
|
end
|
331
367
|
|
@@ -399,36 +435,73 @@ module Transpec
|
|
399
435
|
end
|
400
436
|
|
401
437
|
context 'when the statement continues over multi lines' do
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
438
|
+
context 'and #receive_messages is available' do
|
439
|
+
let(:source) do
|
440
|
+
<<-END
|
441
|
+
describe 'example' do
|
442
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
443
|
+
subject
|
444
|
+
.#{method}(
|
445
|
+
:foo => 1,
|
446
|
+
:bar => 2
|
447
|
+
)
|
448
|
+
end
|
411
449
|
end
|
412
|
-
|
413
|
-
|
414
|
-
end
|
450
|
+
END
|
451
|
+
end
|
415
452
|
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
453
|
+
let(:expected_source) do
|
454
|
+
<<-END
|
455
|
+
describe 'example' do
|
456
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
457
|
+
allow(subject)
|
458
|
+
.to receive_messages(
|
459
|
+
:foo => 1,
|
460
|
+
:bar => 2
|
461
|
+
)
|
462
|
+
end
|
424
463
|
end
|
425
|
-
|
426
|
-
|
464
|
+
END
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'keeps the style' do
|
468
|
+
method_stub_object.allowize!(true)
|
469
|
+
rewritten_source.should == expected_source
|
470
|
+
end
|
427
471
|
end
|
428
472
|
|
429
|
-
|
430
|
-
|
431
|
-
|
473
|
+
context 'and #receive_messages is not available' do
|
474
|
+
let(:source) do
|
475
|
+
<<-END
|
476
|
+
describe 'example' do
|
477
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
478
|
+
subject
|
479
|
+
.#{method}(
|
480
|
+
:foo => 1,
|
481
|
+
:bar => 2
|
482
|
+
)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
END
|
486
|
+
end
|
487
|
+
|
488
|
+
let(:expected_source) do
|
489
|
+
<<-END
|
490
|
+
describe 'example' do
|
491
|
+
it 'responds to #foo and returns 1, and responds to #bar and returns 2' do
|
492
|
+
allow(subject)
|
493
|
+
.to receive(:foo).and_return(1)
|
494
|
+
allow(subject)
|
495
|
+
.to receive(:bar).and_return(2)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
END
|
499
|
+
end
|
500
|
+
|
501
|
+
it 'keeps the style except around the hash' do
|
502
|
+
method_stub_object.allowize!
|
503
|
+
rewritten_source.should == expected_source
|
504
|
+
end
|
432
505
|
end
|
433
506
|
end
|
434
507
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'transpec'
|
5
|
+
|
6
|
+
module Transpec
|
7
|
+
[:required_rspec_version, :current_rspec_version].each do |method|
|
8
|
+
describe ".#{method}" do
|
9
|
+
subject { Transpec.send(method) }
|
10
|
+
|
11
|
+
it 'returns an instance of RSpecVersion' do
|
12
|
+
should be_a(RSpecVersion)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/tasks/test.rake
CHANGED
@@ -13,13 +13,13 @@ namespace :test do
|
|
13
13
|
# rubocop:disable LineLength
|
14
14
|
tests = [
|
15
15
|
TranspecTest.new(File.expand_path('.'), nil, ['--quiet']),
|
16
|
-
TranspecTest.new('https://github.com/
|
17
|
-
TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec-test', bundler_args)
|
16
|
+
TranspecTest.new('https://github.com/yujinakayama/twitter.git', 'transpec-test-rspec-2-99', bundler_args),
|
17
|
+
TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec-test-rspec-2-99', bundler_args)
|
18
18
|
]
|
19
19
|
|
20
20
|
# Sometimes Guard fails with JRuby randomly.
|
21
21
|
unless RUBY_ENGINE == 'jruby'
|
22
|
-
tests << TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec-test', bundler_args + %w(--without development))
|
22
|
+
tests << TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec-test-rspec-2-99', bundler_args + %w(--without development))
|
23
23
|
end
|
24
24
|
# rubocop:enable LineLength
|
25
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transpec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -198,10 +198,13 @@ files:
|
|
198
198
|
- lib/transpec/file_finder.rb
|
199
199
|
- lib/transpec/git.rb
|
200
200
|
- lib/transpec/option_parser.rb
|
201
|
+
- lib/transpec/project.rb
|
201
202
|
- lib/transpec/record.rb
|
202
203
|
- lib/transpec/report.rb
|
204
|
+
- lib/transpec/rspec_version.rb
|
203
205
|
- lib/transpec/static_context_inspector.rb
|
204
206
|
- lib/transpec/syntax.rb
|
207
|
+
- lib/transpec/syntax/be_boolean.rb
|
205
208
|
- lib/transpec/syntax/be_close.rb
|
206
209
|
- lib/transpec/syntax/double.rb
|
207
210
|
- lib/transpec/syntax/expect.rb
|
@@ -236,9 +239,12 @@ files:
|
|
236
239
|
- spec/transpec/file_finder_spec.rb
|
237
240
|
- spec/transpec/git_spec.rb
|
238
241
|
- spec/transpec/option_parser_spec.rb
|
242
|
+
- spec/transpec/project_spec.rb
|
239
243
|
- spec/transpec/record_spec.rb
|
240
244
|
- spec/transpec/report_spec.rb
|
245
|
+
- spec/transpec/rspec_version_spec.rb
|
241
246
|
- spec/transpec/static_context_inspector_spec.rb
|
247
|
+
- spec/transpec/syntax/be_boolean_spec.rb
|
242
248
|
- spec/transpec/syntax/be_close_spec.rb
|
243
249
|
- spec/transpec/syntax/double_spec.rb
|
244
250
|
- spec/transpec/syntax/expect_spec.rb
|
@@ -251,6 +257,7 @@ files:
|
|
251
257
|
- spec/transpec/syntax/should_receive_spec.rb
|
252
258
|
- spec/transpec/syntax/should_spec.rb
|
253
259
|
- spec/transpec/util_spec.rb
|
260
|
+
- spec/transpec_spec.rb
|
254
261
|
- tasks/ci/spec.rake
|
255
262
|
- tasks/demo.rake
|
256
263
|
- tasks/lib/transpec_demo.rb
|
@@ -298,9 +305,12 @@ test_files:
|
|
298
305
|
- spec/transpec/file_finder_spec.rb
|
299
306
|
- spec/transpec/git_spec.rb
|
300
307
|
- spec/transpec/option_parser_spec.rb
|
308
|
+
- spec/transpec/project_spec.rb
|
301
309
|
- spec/transpec/record_spec.rb
|
302
310
|
- spec/transpec/report_spec.rb
|
311
|
+
- spec/transpec/rspec_version_spec.rb
|
303
312
|
- spec/transpec/static_context_inspector_spec.rb
|
313
|
+
- spec/transpec/syntax/be_boolean_spec.rb
|
304
314
|
- spec/transpec/syntax/be_close_spec.rb
|
305
315
|
- spec/transpec/syntax/double_spec.rb
|
306
316
|
- spec/transpec/syntax/expect_spec.rb
|
@@ -313,4 +323,5 @@ test_files:
|
|
313
323
|
- spec/transpec/syntax/should_receive_spec.rb
|
314
324
|
- spec/transpec/syntax/should_spec.rb
|
315
325
|
- spec/transpec/util_spec.rb
|
326
|
+
- spec/transpec_spec.rb
|
316
327
|
has_rdoc:
|