transpec 0.0.10 → 0.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/transpec/cli.rb +35 -3
- data/lib/transpec/rewriter.rb +4 -11
- data/lib/transpec/syntax/method_stub.rb +1 -1
- data/lib/transpec/syntax/should.rb +1 -1
- data/lib/transpec/syntax/should_receive.rb +1 -1
- data/lib/transpec/version.rb +2 -2
- data/spec/spec_helper.rb +4 -2
- data/spec/transpec/cli_spec.rb +51 -0
- data/spec/transpec/rewriter_spec.rb +0 -9
- data/transpec.gemspec +3 -2
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abbc3182fd195b7473eea1f3bb4fcf8c7386a7c7
|
4
|
+
data.tar.gz: c3ea7cfb834e1bb4a65c018416dc809da620ec84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36bc1599b648b15dc9ab19f66e45e105a521886832179e2ef29643ddb28519d233d2e6a7ee2de34c6bbc2dfbe316ba84d4f9a95175d900fe6b671113d49b7e82
|
7
|
+
data.tar.gz: cdf7b01444576de368f5359b79d0e98561e96d624e090ed6df1cfb9f17457d3c7c752cfac8d6e9ee882bbd4ea67c6f34804ca47657f78ddef9bec3382cbdf34e
|
data/CHANGELOG.md
CHANGED
data/lib/transpec/cli.rb
CHANGED
@@ -6,6 +6,7 @@ require 'transpec/rewriter'
|
|
6
6
|
require 'transpec/version'
|
7
7
|
require 'optparse'
|
8
8
|
require 'find'
|
9
|
+
require 'rainbow'
|
9
10
|
|
10
11
|
module Transpec
|
11
12
|
class CLI
|
@@ -44,9 +45,7 @@ module Transpec
|
|
44
45
|
end
|
45
46
|
|
46
47
|
target_files(paths).each do |file_path|
|
47
|
-
|
48
|
-
rewriter = Rewriter.new(@configuration)
|
49
|
-
rewriter.rewrite_file!(file_path)
|
48
|
+
process_file(file_path)
|
50
49
|
end
|
51
50
|
|
52
51
|
# TODO: Print summary
|
@@ -57,6 +56,17 @@ module Transpec
|
|
57
56
|
false
|
58
57
|
end
|
59
58
|
|
59
|
+
def process_file(file_path)
|
60
|
+
puts "Processing #{file_path}"
|
61
|
+
|
62
|
+
rewriter = Rewriter.new(@configuration)
|
63
|
+
rewriter.rewrite_file!(file_path)
|
64
|
+
|
65
|
+
rewriter.errors.each do |error|
|
66
|
+
warn_not_in_example_group_context_error(error)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
60
70
|
# rubocop:disable MethodLength
|
61
71
|
def parse_options(args)
|
62
72
|
parser = OptionParser.new
|
@@ -114,6 +124,10 @@ module Transpec
|
|
114
124
|
@configuration.parenthesize_matcher_arg = false
|
115
125
|
end
|
116
126
|
|
127
|
+
parser.on('--no-color', 'Disable color in the output.') do
|
128
|
+
Sickill::Rainbow.enabled = false
|
129
|
+
end
|
130
|
+
|
117
131
|
parser.on('--version', 'Show Transpec version.') do
|
118
132
|
puts Version.to_s
|
119
133
|
exit
|
@@ -162,5 +176,23 @@ module Transpec
|
|
162
176
|
|
163
177
|
fail 'The current Git repository is not clean. Aborting.'
|
164
178
|
end
|
179
|
+
|
180
|
+
def warn_not_in_example_group_context_error(error)
|
181
|
+
message = error.message.color(:yellow) + $RS
|
182
|
+
message << highlighted_source(error)
|
183
|
+
warn message
|
184
|
+
end
|
185
|
+
|
186
|
+
def highlighted_source(error)
|
187
|
+
filename = error.source_buffer.name.color(:cyan)
|
188
|
+
|
189
|
+
line_number = error.source_range.line
|
190
|
+
|
191
|
+
source = error.source_range.source_line
|
192
|
+
highlight_range = error.source_range.column_range
|
193
|
+
source[highlight_range] = source[highlight_range].underline
|
194
|
+
|
195
|
+
[filename, line_number, source].join(':')
|
196
|
+
end
|
165
197
|
end
|
166
198
|
end
|
data/lib/transpec/rewriter.rb
CHANGED
@@ -16,8 +16,11 @@ require 'parser/current'
|
|
16
16
|
|
17
17
|
module Transpec
|
18
18
|
class Rewriter
|
19
|
+
attr_reader :errors
|
20
|
+
|
19
21
|
def initialize(configuration = Configuration.new)
|
20
22
|
@configuration = configuration
|
23
|
+
@errors = []
|
21
24
|
end
|
22
25
|
|
23
26
|
def rewrite_file!(file_path)
|
@@ -78,17 +81,7 @@ module Transpec
|
|
78
81
|
break
|
79
82
|
end
|
80
83
|
rescue Syntax::NotInExampleGroupContextError => error
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
def warn_not_in_example_group_context_error(error)
|
85
|
-
warn error.message
|
86
|
-
warn format(
|
87
|
-
'%s:%d:%s',
|
88
|
-
error.source_buffer.name,
|
89
|
-
error.source_range.line,
|
90
|
-
error.source_range.source_line
|
91
|
-
)
|
84
|
+
@errors << error
|
92
85
|
end
|
93
86
|
|
94
87
|
def process_should(should)
|
@@ -20,7 +20,7 @@ module Transpec
|
|
20
20
|
fail 'Already replaced deprecated method, cannot allowize.' if @replaced_deprecated_method
|
21
21
|
|
22
22
|
unless in_example_group_context?
|
23
|
-
fail NotInExampleGroupContextError.new(
|
23
|
+
fail NotInExampleGroupContextError.new(selector_range, "##{method_name}", '#allow')
|
24
24
|
end
|
25
25
|
|
26
26
|
if arg_node.type == :hash
|
@@ -16,7 +16,7 @@ module Transpec
|
|
16
16
|
|
17
17
|
def expectize!(negative_form = 'not_to', parenthesize_matcher_arg = true)
|
18
18
|
unless in_example_group_context?
|
19
|
-
fail NotInExampleGroupContextError.new(
|
19
|
+
fail NotInExampleGroupContextError.new(selector_range, "##{method_name}", '#expect')
|
20
20
|
end
|
21
21
|
|
22
22
|
if proc_literal?(subject_node)
|
@@ -38,7 +38,7 @@ module Transpec
|
|
38
38
|
|
39
39
|
def convert_to_syntax!(syntax, negative_form)
|
40
40
|
unless in_example_group_context?
|
41
|
-
fail NotInExampleGroupContextError.new(
|
41
|
+
fail NotInExampleGroupContextError.new(selector_range, "##{method_name}", "##{syntax}")
|
42
42
|
end
|
43
43
|
|
44
44
|
if any_instance?
|
data/lib/transpec/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -14,8 +14,10 @@ RSpec.configure do |config|
|
|
14
14
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
15
15
|
config.filter_run_excluding do_not_run_in_converted_spec: ENV['TRANSPEC_CONVERTED_SPEC']
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
config.before(:all) do
|
18
|
+
Sickill::Rainbow.enabled = false
|
19
|
+
|
20
|
+
if ENV['TRAVIS']
|
19
21
|
system('git config --global user.email "you@example.com"')
|
20
22
|
system('git config --global user.name "Your Name"')
|
21
23
|
end
|
data/spec/transpec/cli_spec.rb
CHANGED
@@ -132,6 +132,44 @@ module Transpec
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
describe '#process_file' do
|
136
|
+
include_context 'isolated environment'
|
137
|
+
|
138
|
+
let(:file_path) { 'example.rb' }
|
139
|
+
|
140
|
+
before do
|
141
|
+
FileHelper.create_file(file_path, source)
|
142
|
+
cli.stub(:puts)
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when the source has a monkey-patched expectation outside of example group context' do
|
146
|
+
let(:source) do
|
147
|
+
<<-END
|
148
|
+
describe 'example group' do
|
149
|
+
class SomeClass
|
150
|
+
def some_method
|
151
|
+
1.should == 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'is an example' do
|
156
|
+
SomeClass.new.some_method
|
157
|
+
end
|
158
|
+
end
|
159
|
+
END
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'warns to user' do
|
163
|
+
cli.should_receive(:warn) do |message|
|
164
|
+
message.should =~ /cannot/i
|
165
|
+
message.should =~ /context/i
|
166
|
+
end
|
167
|
+
|
168
|
+
cli.process_file(file_path)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
135
173
|
describe '#parse_options' do
|
136
174
|
subject { cli.parse_options(args) }
|
137
175
|
let(:args) { ['some_file', '--negative-form', 'to_not', 'some_dir'] }
|
@@ -214,6 +252,19 @@ module Transpec
|
|
214
252
|
end
|
215
253
|
end
|
216
254
|
|
255
|
+
describe '--no-color option' do
|
256
|
+
before do
|
257
|
+
Sickill::Rainbow.enabled = true
|
258
|
+
end
|
259
|
+
|
260
|
+
let(:args) { ['--no-color'] }
|
261
|
+
|
262
|
+
it 'disables color in the output' do
|
263
|
+
cli.parse_options(args)
|
264
|
+
Sickill::Rainbow.enabled.should be_false
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
217
268
|
describe '--version option' do
|
218
269
|
before do
|
219
270
|
cli.stub(:puts)
|
@@ -95,15 +95,6 @@ module Transpec
|
|
95
95
|
it 'does not rewrite the expectation to non-monkey-patch syntax' do
|
96
96
|
should == source
|
97
97
|
end
|
98
|
-
|
99
|
-
it 'warns to user' do
|
100
|
-
rewriter.should_receive(:warn) do |message|
|
101
|
-
message.should =~ /cannot/i
|
102
|
-
message.should =~ /context/i
|
103
|
-
end
|
104
|
-
|
105
|
-
rewriter.rewrite(source)
|
106
|
-
end
|
107
98
|
end
|
108
99
|
end
|
109
100
|
|
data/transpec.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.add_runtime_dependency 'parser',
|
23
|
-
spec.add_runtime_dependency 'rspec',
|
22
|
+
spec.add_runtime_dependency 'parser', '~> 2.0.0.pre1'
|
23
|
+
spec.add_runtime_dependency 'rspec', '~> 2.14'
|
24
|
+
spec.add_runtime_dependency 'rainbow', '~> 1.1'
|
24
25
|
|
25
26
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
27
|
spec.add_development_dependency 'rake', '~> 10.1'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transpec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Nakayama
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rainbow
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: bundler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|