transpec 2.3.4 → 2.3.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/transpec/base_rewriter.rb +3 -3
- data/lib/transpec/cli.rb +15 -5
- data/lib/transpec/dynamic_analyzer.rb +1 -1
- data/lib/transpec/processed_source.rb +19 -22
- data/lib/transpec/report.rb +5 -5
- data/lib/transpec/spec_suite.rb +1 -1
- data/lib/transpec/version.rb +1 -1
- data/spec/support/shared_context.rb +1 -1
- data/spec/transpec/cli_spec.rb +31 -4
- data/spec/transpec/converter_spec.rb +1 -1
- data/spec/transpec/dynamic_analyzer_spec.rb +1 -1
- data/spec/transpec/processed_source_spec.rb +44 -18
- data/spec/transpec/report_spec.rb +3 -3
- data/transpec.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a673a8ed54eae74d68ffe6c597ee95b5a2bbc1d9
|
4
|
+
data.tar.gz: 840daba419607526564f7b5375268a56e811993b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 851f291d709b03c6dc94610aee361813967280d3da164fcbc0e21ab525bde5f941322aa4c6c85d926806bde439f3508b00d2b8b860bdc70233e2b3c090e977d9
|
7
|
+
data.tar.gz: d0dd0b1cc61f6f31ee6dfc78bbf4adc01866f500d0cb854c209e5c1cff7177ca256227361247bb18a7480f745026dd54b15dfde676eb779ce7ba8302d866ce9c
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## Development
|
4
4
|
|
5
|
+
## v2.3.5
|
6
|
+
|
7
|
+
* Avoid crash on processing invalid encoding source files and warn of the encoding errors. ([#81](https://github.com/yujinakayama/transpec/issues/81))
|
8
|
+
|
5
9
|
## v2.3.4
|
6
10
|
|
7
11
|
* Detect whether RSpec configuration `config.raise_errors_for_deprecations!` which interferes with Transpec's dynamic analysis is enabled in the user's specs and abort processing if so. ([#80](https://github.com/yujinakayama/transpec/issues/80))
|
@@ -6,7 +6,7 @@ module Transpec
|
|
6
6
|
class BaseRewriter
|
7
7
|
def rewrite_file!(arg)
|
8
8
|
processed_source = case arg
|
9
|
-
when String then ProcessedSource.
|
9
|
+
when String then ProcessedSource.from_file(arg)
|
10
10
|
when ProcessedSource then arg
|
11
11
|
else fail "Invalid argument: #{arg}"
|
12
12
|
end
|
@@ -19,12 +19,12 @@ module Transpec
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def rewrite_source(source, path = nil)
|
22
|
-
processed_source = ProcessedSource.
|
22
|
+
processed_source = ProcessedSource.new(source, path)
|
23
23
|
rewrite(processed_source)
|
24
24
|
end
|
25
25
|
|
26
26
|
def rewrite(processed_source)
|
27
|
-
fail processed_source.
|
27
|
+
fail processed_source.error if processed_source.error
|
28
28
|
|
29
29
|
source_rewriter = create_source_rewriter(processed_source)
|
30
30
|
incomplete = false
|
data/lib/transpec/cli.rb
CHANGED
@@ -90,9 +90,9 @@ module Transpec
|
|
90
90
|
|
91
91
|
warn_annotations(converter.report)
|
92
92
|
report << converter.report
|
93
|
-
rescue Parser::SyntaxError => error
|
94
|
-
|
95
|
-
|
93
|
+
rescue Parser::SyntaxError, EncodingError => error
|
94
|
+
warn_file_error(error, spec.path)
|
95
|
+
report.file_errors << error
|
96
96
|
end
|
97
97
|
|
98
98
|
private
|
@@ -145,8 +145,18 @@ module Transpec
|
|
145
145
|
puts "Done! Now run #{'rspec'.bright} and check if everything is green."
|
146
146
|
end
|
147
147
|
|
148
|
-
def
|
149
|
-
|
148
|
+
def warn_file_error(error, path)
|
149
|
+
message = case error
|
150
|
+
when Parser::SyntaxError
|
151
|
+
"Syntax error at #{error.diagnostic.location}."
|
152
|
+
when EncodingError
|
153
|
+
"Encoding error in #{path}."
|
154
|
+
else
|
155
|
+
"#{error.message.capitalize} in #{path}."
|
156
|
+
end
|
157
|
+
|
158
|
+
message << ' Skipping the file.'
|
159
|
+
warn message.color(:red)
|
150
160
|
end
|
151
161
|
|
152
162
|
def warn_annotations(report)
|
@@ -12,37 +12,34 @@ require 'transpec/ast/builder'
|
|
12
12
|
|
13
13
|
module Transpec
|
14
14
|
class ProcessedSource
|
15
|
-
attr_reader :buffer, :ast, :path, :
|
15
|
+
attr_reader :buffer, :ast, :path, :error
|
16
16
|
|
17
|
-
def self.
|
17
|
+
def self.from_file(path)
|
18
18
|
source = File.read(path)
|
19
|
-
|
19
|
+
new(source, path)
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
buffer = Parser::Source::Buffer.new(path || '(string)')
|
24
|
-
buffer.source = source
|
25
|
-
|
26
|
-
builder = AST::Builder.new
|
27
|
-
parser = Parser::CurrentRuby.new(builder)
|
28
|
-
|
29
|
-
begin
|
30
|
-
ast = parser.parse(buffer)
|
31
|
-
new(buffer, ast, path)
|
32
|
-
rescue Parser::SyntaxError => error
|
33
|
-
new(buffer, nil, path, error)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(buffer, ast, path = nil, syntax_error = nil)
|
38
|
-
@buffer = buffer
|
39
|
-
@ast = ast
|
22
|
+
def initialize(source, path = nil)
|
40
23
|
@path = path
|
41
|
-
|
24
|
+
parse(source)
|
42
25
|
end
|
43
26
|
|
44
27
|
def to_s
|
45
28
|
buffer.source
|
46
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse(source)
|
34
|
+
@buffer = Parser::Source::Buffer.new(@path || '(string)')
|
35
|
+
@buffer.source = source
|
36
|
+
|
37
|
+
builder = AST::Builder.new
|
38
|
+
parser = Parser::CurrentRuby.new(builder)
|
39
|
+
|
40
|
+
@ast = parser.parse(@buffer)
|
41
|
+
rescue Parser::SyntaxError, EncodingError => error
|
42
|
+
@error = error
|
43
|
+
end
|
47
44
|
end
|
48
45
|
end
|
data/lib/transpec/report.rb
CHANGED
@@ -4,18 +4,18 @@ require 'rainbow'
|
|
4
4
|
|
5
5
|
module Transpec
|
6
6
|
class Report
|
7
|
-
attr_reader :records, :conversion_errors, :
|
7
|
+
attr_reader :records, :conversion_errors, :file_errors
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
@records = []
|
11
11
|
@conversion_errors = []
|
12
|
-
@
|
12
|
+
@file_errors = []
|
13
13
|
end
|
14
14
|
|
15
15
|
def <<(other)
|
16
16
|
records.concat(other.records)
|
17
17
|
conversion_errors.concat(other.conversion_errors)
|
18
|
-
|
18
|
+
file_errors.concat(other.file_errors)
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
@@ -113,13 +113,13 @@ module Transpec
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def error_stats(base_color)
|
116
|
-
color = if
|
116
|
+
color = if file_errors.empty?
|
117
117
|
base_color
|
118
118
|
else
|
119
119
|
:red
|
120
120
|
end
|
121
121
|
|
122
|
-
colorize(pluralize(
|
122
|
+
colorize(pluralize(file_errors.count, 'error'), color)
|
123
123
|
end
|
124
124
|
|
125
125
|
def pluralize(number, thing, options = {})
|
data/lib/transpec/spec_suite.rb
CHANGED
data/lib/transpec/version.rb
CHANGED
data/spec/transpec/cli_spec.rb
CHANGED
@@ -139,7 +139,7 @@ module Transpec
|
|
139
139
|
|
140
140
|
include_examples 'aborts processing'
|
141
141
|
|
142
|
-
it 'warns to the
|
142
|
+
it 'warns to the version' do
|
143
143
|
cli.should_receive(:warn).with(/rspec.+dependency/i)
|
144
144
|
cli.run(args)
|
145
145
|
end
|
@@ -176,6 +176,33 @@ module Transpec
|
|
176
176
|
end
|
177
177
|
end
|
178
178
|
|
179
|
+
context 'when an encoding error is raised while processing files' do
|
180
|
+
let(:args) { [invalid_encoding_file_path, valid_encoding_file_path] }
|
181
|
+
let(:invalid_encoding_file_path) { 'spec/invalid_example.rb' }
|
182
|
+
let(:valid_encoding_file_path) { 'spec/valid_example.rb' }
|
183
|
+
|
184
|
+
before do
|
185
|
+
create_file(invalid_encoding_file_path, <<-END)
|
186
|
+
# coding: utf-8
|
187
|
+
\xff
|
188
|
+
END
|
189
|
+
|
190
|
+
create_file(valid_encoding_file_path, 'this_is_valid_encoding')
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'warns of the error' do
|
194
|
+
cli.should_receive(:warn)
|
195
|
+
.with('Encoding error in spec/invalid_example.rb. Skipping the file.')
|
196
|
+
cli.run(args)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'continues processing files' do
|
200
|
+
cli.should_receive(:puts).with("Converting #{invalid_encoding_file_path}")
|
201
|
+
cli.should_receive(:puts).with("Converting #{valid_encoding_file_path}")
|
202
|
+
cli.run(args)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
179
206
|
context 'when any other error is raised while running' do
|
180
207
|
let(:args) { ['non-existent-file'] }
|
181
208
|
|
@@ -215,7 +242,7 @@ module Transpec
|
|
215
242
|
let(:processed_source) do
|
216
243
|
path = 'example.rb'
|
217
244
|
create_file(path, source)
|
218
|
-
ProcessedSource.
|
245
|
+
ProcessedSource.from_file(path)
|
219
246
|
end
|
220
247
|
|
221
248
|
let(:spec_suite) { SpecSuite.new }
|
@@ -241,7 +268,7 @@ module Transpec
|
|
241
268
|
END
|
242
269
|
end
|
243
270
|
|
244
|
-
it 'warns
|
271
|
+
it 'warns of the conversion error' do
|
245
272
|
cli.should_receive(:warn) do |message|
|
246
273
|
message.should =~ /cannot/i
|
247
274
|
message.should =~ /context/i
|
@@ -262,7 +289,7 @@ module Transpec
|
|
262
289
|
END
|
263
290
|
end
|
264
291
|
|
265
|
-
it 'warns
|
292
|
+
it 'warns of less accurate conversion' do
|
266
293
|
cli.should_receive(:warn).with(/converted.+but.+incorrect/i)
|
267
294
|
cli.convert_spec(processed_source, spec_suite)
|
268
295
|
end
|
@@ -29,7 +29,7 @@ module Transpec
|
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'when a processed source is passed' do
|
32
|
-
let(:processed_source) { ProcessedSource.
|
32
|
+
let(:processed_source) { ProcessedSource.from_file(file_path) }
|
33
33
|
|
34
34
|
it 'overwrites the file that the processed source was derived from' do
|
35
35
|
converter.convert_file!(processed_source)
|
@@ -10,7 +10,7 @@ module Transpec
|
|
10
10
|
include_context 'isolated environment'
|
11
11
|
|
12
12
|
def find_node_in_file(file_path, &block)
|
13
|
-
processed_source = ProcessedSource.
|
13
|
+
processed_source = ProcessedSource.from_file(file_path)
|
14
14
|
processed_source.ast.each_node.find(&block)
|
15
15
|
end
|
16
16
|
|
@@ -16,38 +16,64 @@ module Transpec
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'parses the file and returns processed source' do
|
19
|
-
processed_source = ProcessedSource.
|
19
|
+
processed_source = ProcessedSource.from_file(spec_path)
|
20
20
|
processed_source.path.should == spec_path
|
21
21
|
processed_source.ast.should_not be_nil
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
subject(:processed_source) { ProcessedSource.new(source) }
|
26
|
+
|
27
|
+
describe '#ast' do
|
28
|
+
let(:source) { "puts 'foo'" }
|
29
|
+
|
30
|
+
it 'returns the root node of AST' do
|
31
|
+
processed_source.ast.should be_a(Parser::AST::Node)
|
29
32
|
end
|
33
|
+
end
|
30
34
|
|
31
|
-
|
32
|
-
|
35
|
+
describe '#path' do
|
36
|
+
let(:source) { "puts 'foo'" }
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
context 'when a file path is passed to .new' do
|
39
|
+
subject(:processed_source) { ProcessedSource.new(source, '/path/to/file') }
|
40
|
+
|
41
|
+
it 'returns the path' do
|
42
|
+
processed_source.path.should == '/path/to/file'
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
40
|
-
context 'when no file path is passed' do
|
41
|
-
it '
|
42
|
-
processed_source = ProcessedSource.parse("puts 'foo'")
|
46
|
+
context 'when no file path is passed to .new' do
|
47
|
+
it 'returns nil' do
|
43
48
|
processed_source.path.should be_nil
|
44
49
|
end
|
45
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#syntax_error' do
|
54
|
+
context 'when the source is valid' do
|
55
|
+
let(:source) { "puts 'foo'" }
|
56
|
+
|
57
|
+
it 'returns nil' do
|
58
|
+
processed_source.error.should be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'when the source is invalid' do
|
63
|
+
let(:source) { '<' }
|
64
|
+
|
65
|
+
it 'returns syntax error' do
|
66
|
+
processed_source.error.should be_a(Parser::SyntaxError)
|
67
|
+
end
|
68
|
+
end
|
46
69
|
|
47
|
-
context 'when the
|
48
|
-
it '
|
49
|
-
processed_source = ProcessedSource.
|
50
|
-
|
70
|
+
context 'when the source includes invalid byte sequence for the encoding' do
|
71
|
+
it 'returns encoding error' do
|
72
|
+
processed_source = ProcessedSource.new(<<-END)
|
73
|
+
# coding: utf-8
|
74
|
+
\xff
|
75
|
+
END
|
76
|
+
processed_source.error.should be_a(EncodingError)
|
51
77
|
end
|
52
78
|
end
|
53
79
|
end
|
@@ -59,7 +85,7 @@ module Transpec
|
|
59
85
|
"puts 'bar'"
|
60
86
|
].join("\n")
|
61
87
|
|
62
|
-
processed_source = ProcessedSource.
|
88
|
+
processed_source = ProcessedSource.new(source)
|
63
89
|
processed_source.to_s.should == source
|
64
90
|
end
|
65
91
|
end
|
@@ -102,7 +102,7 @@ module Transpec
|
|
102
102
|
report.records << Record.new('obj.stub(:message)', 'allow(obj).to receive(:message)')
|
103
103
|
report.conversion_errors << ContextError.new('#should', '#expect', double('range'))
|
104
104
|
report.conversion_errors << ContextError.new('#stub', '#allow', double('range'))
|
105
|
-
report.
|
105
|
+
report.file_errors << double('file error')
|
106
106
|
report
|
107
107
|
end
|
108
108
|
|
@@ -118,8 +118,8 @@ module Transpec
|
|
118
118
|
concated_report.should have(3).conversion_errors
|
119
119
|
end
|
120
120
|
|
121
|
-
it 'concats
|
122
|
-
concated_report.should have(1).
|
121
|
+
it 'concats file errors' do
|
122
|
+
concated_report.should have(1).file_errors
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
data/transpec.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.required_ruby_version = '>= 1.9.3'
|
24
24
|
|
25
|
-
spec.add_runtime_dependency 'parser', '>= 2.
|
25
|
+
spec.add_runtime_dependency 'parser', '>= 2.2.0.pre.3', '< 3.0'
|
26
26
|
spec.add_runtime_dependency 'astrolabe', '>= 0.5.1', '< 0.6'
|
27
27
|
spec.add_runtime_dependency 'bundler', '~> 1.3'
|
28
28
|
spec.add_runtime_dependency 'rainbow', '>= 1.99.1', '< 3.0'
|
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: 2.3.
|
4
|
+
version: 2.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.2.0.pre.3
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '3.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 2.
|
29
|
+
version: 2.2.0.pre.3
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '3.0'
|