transpec 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Guardfile +1 -0
- data/Rakefile +2 -138
- data/lib/transpec/ast/scanner.rb +5 -19
- data/lib/transpec/context.rb +101 -0
- data/lib/transpec/rewriter.rb +3 -4
- data/lib/transpec/syntax.rb +8 -4
- data/lib/transpec/syntax/matcher.rb +74 -36
- data/lib/transpec/syntax/method_stub.rb +7 -28
- data/lib/transpec/syntax/send_node_syntax.rb +12 -0
- data/lib/transpec/syntax/should.rb +2 -2
- data/lib/transpec/syntax/should_receive.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/spec_helper.rb +12 -15
- data/spec/support/shared_context.rb +0 -3
- data/spec/transpec/ast/scanner_spec.rb +0 -53
- data/spec/transpec/context_spec.rb +256 -0
- data/spec/transpec/syntax/be_close_spec.rb +0 -3
- data/spec/transpec/syntax/double_spec.rb +0 -3
- data/spec/transpec/syntax/matcher_spec.rb +171 -3
- data/spec/transpec/syntax/method_stub_spec.rb +22 -3
- data/spec/transpec/syntax/raise_error_spec.rb +0 -3
- data/spec/transpec/syntax/rspec_configure_spec.rb +0 -3
- data/spec/transpec/syntax/should_receive_spec.rb +3 -2
- data/spec/transpec/syntax/should_spec.rb +4 -0
- data/tasks/ci/spec.rake +14 -0
- data/tasks/readme.rake +18 -0
- data/tasks/test.rake +164 -0
- metadata +8 -7
- data/lib/transpec/ast/scope_stack.rb +0 -78
- data/spec/spec_spec.rb +0 -51
- data/spec/transpec/ast/scope_stack_spec.rb +0 -95
@@ -14,15 +14,12 @@ module Transpec
|
|
14
14
|
return BeClose.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No be_close node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
let(:in_example_group_context?) { true }
|
25
|
-
|
26
23
|
describe '#convert_to_be_within!' do
|
27
24
|
context 'when it is `be_close(expected, delta)` form' do
|
28
25
|
let(:source) do
|
@@ -14,15 +14,12 @@ module Transpec
|
|
14
14
|
return Double.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No double node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
let(:in_example_group_context?) { true }
|
25
|
-
|
26
23
|
describe '#method_name' do
|
27
24
|
let(:source) do
|
28
25
|
<<-END
|
@@ -10,11 +10,9 @@ module Transpec
|
|
10
10
|
include_context 'should object'
|
11
11
|
|
12
12
|
subject(:matcher) do
|
13
|
-
Matcher.new(should_object.matcher_node,
|
13
|
+
Matcher.new(should_object.matcher_node, source_rewriter)
|
14
14
|
end
|
15
15
|
|
16
|
-
let(:in_example_group_context?) { true }
|
17
|
-
|
18
16
|
describe '#method_name' do
|
19
17
|
context 'when it is operator matcher' do
|
20
18
|
let(:source) do
|
@@ -133,6 +131,88 @@ module Transpec
|
|
133
131
|
end
|
134
132
|
end
|
135
133
|
|
134
|
+
context 'when it is `==1` form' do
|
135
|
+
let(:source) do
|
136
|
+
<<-END
|
137
|
+
it 'is 1' do
|
138
|
+
subject.should==1
|
139
|
+
end
|
140
|
+
END
|
141
|
+
end
|
142
|
+
|
143
|
+
let(:expected_source) do
|
144
|
+
<<-END
|
145
|
+
it 'is 1' do
|
146
|
+
subject.should eq(1)
|
147
|
+
end
|
148
|
+
END
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'converts into `eq(1)` form' do
|
152
|
+
rewritten_source.should == expected_source
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'and false is passed as `parenthesize_arg` argument' do
|
156
|
+
let(:parenthesize_arg) { false }
|
157
|
+
|
158
|
+
let(:expected_source) do
|
159
|
+
<<-END
|
160
|
+
it 'is 1' do
|
161
|
+
subject.should eq 1
|
162
|
+
end
|
163
|
+
END
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'converts into `eq 1` form' do
|
167
|
+
rewritten_source.should == expected_source
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'when it is `be == 1` form' do
|
173
|
+
let(:source) do
|
174
|
+
<<-END
|
175
|
+
it 'is 1' do
|
176
|
+
subject.should be == 1
|
177
|
+
end
|
178
|
+
END
|
179
|
+
end
|
180
|
+
|
181
|
+
let(:expected_source) do
|
182
|
+
<<-END
|
183
|
+
it 'is 1' do
|
184
|
+
subject.should eq(1)
|
185
|
+
end
|
186
|
+
END
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'converts into `eq(1)` form' do
|
190
|
+
rewritten_source.should == expected_source
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
context 'when it is `be.==(1)` form' do
|
195
|
+
let(:source) do
|
196
|
+
<<-END
|
197
|
+
it 'is 1' do
|
198
|
+
subject.should be.==(1)
|
199
|
+
end
|
200
|
+
END
|
201
|
+
end
|
202
|
+
|
203
|
+
let(:expected_source) do
|
204
|
+
<<-END
|
205
|
+
it 'is 1' do
|
206
|
+
subject.should eq(1)
|
207
|
+
end
|
208
|
+
END
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'converts into `eq(1)` form' do
|
212
|
+
rewritten_source.should == expected_source
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
136
216
|
context 'when it is `== (2 - 1)` form' do
|
137
217
|
let(:source) do
|
138
218
|
<<-END
|
@@ -273,6 +353,50 @@ module Transpec
|
|
273
353
|
end
|
274
354
|
end
|
275
355
|
|
356
|
+
context 'when it is `=~/pattern/` form' do
|
357
|
+
let(:source) do
|
358
|
+
<<-END
|
359
|
+
it 'matches the pattern' do
|
360
|
+
subject.should=~/pattern/
|
361
|
+
end
|
362
|
+
END
|
363
|
+
end
|
364
|
+
|
365
|
+
let(:expected_source) do
|
366
|
+
<<-END
|
367
|
+
it 'matches the pattern' do
|
368
|
+
subject.should match(/pattern/)
|
369
|
+
end
|
370
|
+
END
|
371
|
+
end
|
372
|
+
|
373
|
+
it 'converts into `match(/pattern/)` form' do
|
374
|
+
rewritten_source.should == expected_source
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
context 'when it is `be =~ /pattern/` form' do
|
379
|
+
let(:source) do
|
380
|
+
<<-END
|
381
|
+
it 'matches the pattern' do
|
382
|
+
subject.should be =~ /pattern/
|
383
|
+
end
|
384
|
+
END
|
385
|
+
end
|
386
|
+
|
387
|
+
let(:expected_source) do
|
388
|
+
<<-END
|
389
|
+
it 'matches the pattern' do
|
390
|
+
subject.should match(/pattern/)
|
391
|
+
end
|
392
|
+
END
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'converts into `match(/pattern/)` form' do
|
396
|
+
rewritten_source.should == expected_source
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
276
400
|
context 'when it is `=~ [1, 2]` form' do
|
277
401
|
let(:source) do
|
278
402
|
<<-END
|
@@ -294,6 +418,50 @@ module Transpec
|
|
294
418
|
rewritten_source.should == expected_source
|
295
419
|
end
|
296
420
|
end
|
421
|
+
|
422
|
+
context 'when it is `=~[1, 2]` form' do
|
423
|
+
let(:source) do
|
424
|
+
<<-END
|
425
|
+
it 'contains 1 and 2' do
|
426
|
+
subject.should=~[1, 2]
|
427
|
+
end
|
428
|
+
END
|
429
|
+
end
|
430
|
+
|
431
|
+
let(:expected_source) do
|
432
|
+
<<-END
|
433
|
+
it 'contains 1 and 2' do
|
434
|
+
subject.should match_array([1, 2])
|
435
|
+
end
|
436
|
+
END
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'converts into `match_array([1, 2])` form' do
|
440
|
+
rewritten_source.should == expected_source
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
context 'when it is `be =~ [1, 2]` form' do
|
445
|
+
let(:source) do
|
446
|
+
<<-END
|
447
|
+
it 'contains 1 and 2' do
|
448
|
+
subject.should be =~ [1, 2]
|
449
|
+
end
|
450
|
+
END
|
451
|
+
end
|
452
|
+
|
453
|
+
let(:expected_source) do
|
454
|
+
<<-END
|
455
|
+
it 'contains 1 and 2' do
|
456
|
+
subject.should match_array([1, 2])
|
457
|
+
end
|
458
|
+
END
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'converts into `match_array([1, 2])` form' do
|
462
|
+
rewritten_source.should == expected_source
|
463
|
+
end
|
464
|
+
end
|
297
465
|
end
|
298
466
|
|
299
467
|
describe '#parenthesize!' do
|
@@ -14,15 +14,12 @@ module Transpec
|
|
14
14
|
return MethodStub.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No method stub node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
let(:in_example_group_context?) { true }
|
25
|
-
|
26
23
|
describe '.target_node?' do
|
27
24
|
let(:send_node) do
|
28
25
|
ast.each_descendent_node do |node|
|
@@ -61,6 +58,20 @@ module Transpec
|
|
61
58
|
MethodStub.target_node?(send_node).should be_false
|
62
59
|
end
|
63
60
|
end
|
61
|
+
|
62
|
+
context 'when #stub node with Excon receiver is passed' do
|
63
|
+
let(:source) do
|
64
|
+
<<-END
|
65
|
+
it "is not RSpec's #stub" do
|
66
|
+
::Excon.stub({}, {:body => 'body', :status => 200})
|
67
|
+
end
|
68
|
+
END
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'returns false' do
|
72
|
+
MethodStub.target_node?(send_node).should be_false
|
73
|
+
end
|
74
|
+
end
|
64
75
|
end
|
65
76
|
|
66
77
|
describe '#method_name' do
|
@@ -78,6 +89,10 @@ module Transpec
|
|
78
89
|
end
|
79
90
|
|
80
91
|
describe '#allowize!' do
|
92
|
+
before do
|
93
|
+
method_stub_object.context.stub(:in_example_group?).and_return(true)
|
94
|
+
end
|
95
|
+
|
81
96
|
[:stub, :stub!].each do |method|
|
82
97
|
context "when it is `subject.#{method}(:method)` form" do
|
83
98
|
let(:source) do
|
@@ -359,6 +374,10 @@ module Transpec
|
|
359
374
|
end
|
360
375
|
|
361
376
|
describe '#replace_deprecated_method!' do
|
377
|
+
before do
|
378
|
+
method_stub_object.context.stub(:in_example_group?).and_return(true)
|
379
|
+
end
|
380
|
+
|
362
381
|
[
|
363
382
|
[:stub!, :stub, 'responds to'],
|
364
383
|
[:unstub!, :unstub, 'does not respond to']
|
@@ -14,15 +14,12 @@ module Transpec
|
|
14
14
|
return RaiseError.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No raise_error node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
let(:in_example_group_context?) { true }
|
25
|
-
|
26
23
|
describe '#remove_error_specification_with_negative_expectation!' do
|
27
24
|
before do
|
28
25
|
raise_error_object.remove_error_specification_with_negative_expectation!
|
@@ -14,15 +14,12 @@ module Transpec
|
|
14
14
|
return RSpecConfigure.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No RSpec.configure node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
let(:in_example_group_context?) { true }
|
25
|
-
|
26
23
|
[
|
27
24
|
[:expectation_syntaxes, :expect_with, 'RSpec::Matchers::Configuration'],
|
28
25
|
[:mock_syntaxes, :mock_with, 'RSpec::Mocks::Configuration']
|
@@ -14,14 +14,15 @@ module Transpec
|
|
14
14
|
return ShouldReceive.new(
|
15
15
|
node,
|
16
16
|
ancestor_nodes,
|
17
|
-
in_example_group_context?,
|
18
17
|
source_rewriter
|
19
18
|
)
|
20
19
|
end
|
21
20
|
fail 'No should_receive node is found!'
|
22
21
|
end
|
23
22
|
|
24
|
-
|
23
|
+
before do
|
24
|
+
should_receive_object.context.stub(:in_example_group?).and_return(true)
|
25
|
+
end
|
25
26
|
|
26
27
|
describe '#expectize!' do
|
27
28
|
context 'when it is `subject.should_receive(:method)` form' do
|
@@ -9,6 +9,10 @@ module Transpec
|
|
9
9
|
include_context 'parsed objects'
|
10
10
|
include_context 'should object'
|
11
11
|
|
12
|
+
before do
|
13
|
+
should_object.context.stub(:in_example_group?).and_return(true)
|
14
|
+
end
|
15
|
+
|
12
16
|
describe '#matcher_node' do
|
13
17
|
context 'when it is taking operator matcher' do
|
14
18
|
let(:source) do
|
data/tasks/ci/spec.rake
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
namespace :ci do
|
4
|
+
desc "#{Rake::Task['spec'].comment} for CI environment"
|
5
|
+
task :spec do
|
6
|
+
ENV['CI'] = 'true'
|
7
|
+
|
8
|
+
ENV['CI_REPORTS'] = 'spec/reports'
|
9
|
+
require 'ci/reporter/rake/rspec'
|
10
|
+
Rake::Task['ci:setup:rspec'].invoke
|
11
|
+
|
12
|
+
Rake::Task['spec'].invoke
|
13
|
+
end
|
14
|
+
end
|
data/tasks/readme.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
desc 'Generate README.md'
|
4
|
+
task :readme do
|
5
|
+
require 'erb'
|
6
|
+
require 'transpec/cli'
|
7
|
+
|
8
|
+
gem_specification = Gem::Specification.load('transpec.gemspec')
|
9
|
+
rspec_dependency = gem_specification.dependencies.find { |d| d.name == 'rspec' }
|
10
|
+
rspec_requirement = rspec_dependency.requirement
|
11
|
+
# rubocop:disable UselessAssignment
|
12
|
+
rspec_version = rspec_requirement.requirements.first.find { |r| r.is_a?(Gem::Version) }
|
13
|
+
# rubocop:enable UselessAssignment
|
14
|
+
|
15
|
+
erb = ERB.new(File.read('README.md.erb'), nil, '-')
|
16
|
+
content = erb.result(binding)
|
17
|
+
File.write('README.md', content)
|
18
|
+
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
class TranspecTest
|
4
|
+
include FileUtils # This is Rake's one.
|
5
|
+
|
6
|
+
attr_reader :url, :ref, :bundler_args
|
7
|
+
|
8
|
+
def self.base_dir
|
9
|
+
@base_dir ||= begin
|
10
|
+
base_dir = File.join('tmp', 'projects')
|
11
|
+
|
12
|
+
unless Dir.exist?(base_dir)
|
13
|
+
require 'fileutils'
|
14
|
+
FileUtils.mkdir_p(base_dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
base_dir
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(url, ref = nil, bundler_args = [])
|
22
|
+
@url = url
|
23
|
+
@ref = ref
|
24
|
+
@bundler_args = bundler_args
|
25
|
+
end
|
26
|
+
|
27
|
+
def name
|
28
|
+
@name ||= File.basename(url, '.git')
|
29
|
+
end
|
30
|
+
|
31
|
+
def project_dir
|
32
|
+
@project_dir ||= File.join(self.class.base_dir, name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def run
|
36
|
+
require 'transpec'
|
37
|
+
|
38
|
+
puts " Testing on #{name} Project ".center(80, '=')
|
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
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def prepare_project
|
54
|
+
if url.start_with?('/')
|
55
|
+
prepare_with_local_dir
|
56
|
+
else
|
57
|
+
prepare_with_git_repo
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def prepare_with_local_dir
|
62
|
+
if Dir.exist?(project_dir)
|
63
|
+
require 'fileutils'
|
64
|
+
FileUtils.rm_rf(project_dir)
|
65
|
+
end
|
66
|
+
|
67
|
+
Dir.mkdir(project_dir)
|
68
|
+
|
69
|
+
Dir.chdir(url) do
|
70
|
+
Dir.new('.').each do |entry|
|
71
|
+
next if ['.', '..', '.git', 'tmp'].include?(entry)
|
72
|
+
FileUtils.cp_r(entry, project_dir)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def prepare_with_git_repo
|
78
|
+
if Dir.exist?(project_dir)
|
79
|
+
if current_ref == ref
|
80
|
+
git_reset_hard
|
81
|
+
else
|
82
|
+
require 'fileutils'
|
83
|
+
FileUtils.rm_rf(project_dir)
|
84
|
+
git_clone
|
85
|
+
end
|
86
|
+
else
|
87
|
+
git_clone
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def in_project_dir(&block)
|
92
|
+
Dir.chdir(project_dir, &block)
|
93
|
+
end
|
94
|
+
|
95
|
+
def current_ref
|
96
|
+
in_project_dir do
|
97
|
+
`git describe --all`.chomp.sub(/\Aheads\//, '')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def git_reset_hard
|
102
|
+
in_project_dir do
|
103
|
+
sh 'git reset --hard'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def git_clone
|
108
|
+
Dir.chdir(self.class.base_dir) do
|
109
|
+
# Disabling checkout here to suppress "detached HEAD" warning.
|
110
|
+
sh "git clone --no-checkout --depth 1 --branch #{ref} #{url}"
|
111
|
+
end
|
112
|
+
|
113
|
+
in_project_dir do
|
114
|
+
sh "git checkout --quiet #{ref}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def with_clean_bundler_env
|
119
|
+
if defined?(Bundler)
|
120
|
+
Bundler.with_clean_env do
|
121
|
+
# Bundler.with_clean_env cleans environment variables
|
122
|
+
# which are set after bundler is loaded.
|
123
|
+
prepare_env
|
124
|
+
yield
|
125
|
+
end
|
126
|
+
else
|
127
|
+
prepare_env
|
128
|
+
yield
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def prepare_env
|
133
|
+
# Disable Coveralls.
|
134
|
+
ENV['CI'] = ENV['JENKINS_URL'] = ENV['COVERALLS_RUN_LOCALLY'] = nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
namespace :test do
|
139
|
+
# On Travis CI, reuse system gems to speed up build.
|
140
|
+
bundler_args = if ENV['TRAVIS']
|
141
|
+
[]
|
142
|
+
else
|
143
|
+
%w(--path vendor/bundle)
|
144
|
+
end
|
145
|
+
|
146
|
+
# rubocop:disable LineLength
|
147
|
+
tests = [
|
148
|
+
TranspecTest.new(File.expand_path('.'), nil, []),
|
149
|
+
TranspecTest.new('https://github.com/sferik/twitter.git', 'v4.1.0', bundler_args),
|
150
|
+
TranspecTest.new('https://github.com/yujinakayama/guard.git', 'transpec', bundler_args + %w(--without development)),
|
151
|
+
TranspecTest.new('https://github.com/yujinakayama/mail.git', 'transpec', bundler_args)
|
152
|
+
]
|
153
|
+
# rubocop:enable LineLength
|
154
|
+
|
155
|
+
desc 'Test Transpec on all projects'
|
156
|
+
task all: tests.map(&:name)
|
157
|
+
|
158
|
+
tests.each do |test|
|
159
|
+
desc "Test Transpec on #{test.name.capitalize} project"
|
160
|
+
task test.name do
|
161
|
+
test.run
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|