transpec 1.10.2 → 1.10.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f63ab80111ffedb4a472083d734b97e3546a2378
4
- data.tar.gz: e14e5cae27aa6e42915b8c82d3062122e156b711
3
+ metadata.gz: 81c1501cb0bedfa4aa3c8a489b27cff42d227aa0
4
+ data.tar.gz: bebe4a68c3997619529e74e6bcdca7cda64fe5c1
5
5
  SHA512:
6
- metadata.gz: 017fccc8bed755513a5efaafcc11e32233457fc0cc87e40ba0606458898f48ce97a23127e783944193aff0d8ace73428858e0c8cffded85f857a93da15649a44
7
- data.tar.gz: 22b1175c44bcc0f151c2d5bf307aabc866650190be0fc690e4aa7fd1b8ebaac78ec344c7e42109e4ea68334222eb28b2b8b2481bffba865b5284710d813e1a15
6
+ metadata.gz: 63483d99b750ee2ac2db638fdbe1b654151bb0960609595243b49083238117fca9d975710221aa34ea5e57aa53ec65d6b09c7a51b06685f890220ca09692de45
7
+ data.tar.gz: 0c99b74e4fdfef91915484fc71a6f5579625849c9f7cd3ea82fb12d254109c13f77cd3721908e69d7ca362cf5879150fc75ae7d1e328b0c8619b602b348af7f2
data/CHANGELOG.md CHANGED
@@ -2,9 +2,13 @@
2
2
 
3
3
  ## Development
4
4
 
5
+ ## v1.10.3
6
+
7
+ * Suggest using `-c/--rspec-command` option and exit gracefully when dynamic analysis failed ([#52](https://github.com/yujinakayama/transpec/issues/52))
8
+
5
9
  ## v1.10.2
6
10
 
7
- * Fix a bug where `expect(an_array + another_array).to have(2).items` was converted to `expect((an_array +(another_array).size).to eq(2)`
11
+ * Fix a bug where `expect(an_array + another_array).to have(2).items` was converted to `expect(an_array +(another_array).size).to eq(2)`
8
12
 
9
13
  ## v1.10.1
10
14
 
data/Guardfile CHANGED
@@ -4,14 +4,14 @@
4
4
  # This group allows to skip running RuboCop if RSpec failed,
5
5
  # like Red > Green (RSpec) > Refactor (RuboCop).
6
6
  group :red_green_refactor, halt_on_fail: true do
7
- guard :rspec, all_on_start: true, cmd: 'bundle exec rspec' do
7
+ guard :rspec, all_on_start: true, cmd: 'bundle exec rspec --format Fuubar' do
8
8
  watch(%r{^spec/.+_spec\.rb$})
9
9
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
10
10
  watch('spec/spec_helper.rb') { "spec" }
11
11
  watch(%r{^spec/support/.+\.rb$}) { "spec" }
12
12
  end
13
13
 
14
- guard :rubocop do
14
+ guard :rubocop, cli: '--format fuubar' do
15
15
  watch(%r{.+\.rb$})
16
16
  watch(%r{.+\.rake$})
17
17
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
data/README.md CHANGED
@@ -144,7 +144,8 @@ After the conversion, run `rspec` again and check whether everything is green:
144
144
  $ bundle exec rspec
145
145
  ```
146
146
 
147
- If it's green, commit the changes with an auto-generated message that describes the conversion summary:
147
+ If it's green, commit the changes with an auto-generated message
148
+ that describes the conversion summary and helps your team members to understand the new syntax:
148
149
 
149
150
  ```bash
150
151
  $ git commit -aeF .git/COMMIT_EDITMSG
data/README.md.erb CHANGED
@@ -118,7 +118,8 @@ After the conversion, run `rspec` again and check whether everything is green:
118
118
  $ bundle exec rspec
119
119
  ```
120
120
 
121
- If it's green, commit the changes with an auto-generated message that describes the conversion summary:
121
+ If it's green, commit the changes with an auto-generated message
122
+ that describes the conversion summary and helps your team members to understand the new syntax:
122
123
 
123
124
  ```bash
124
125
  $ git commit -aeF .git/COMMIT_EDITMSG
data/lib/transpec/cli.rb CHANGED
@@ -47,12 +47,7 @@ module Transpec
47
47
  runtime_data = nil
48
48
 
49
49
  unless configuration.skip_dynamic_analysis?
50
- puts 'Copying the project for dynamic analysis...'
51
- DynamicAnalyzer.new(rspec_command: configuration.rspec_command) do |analyzer|
52
- puts "Running dynamic analysis with command #{analyzer.rspec_command.inspect}..."
53
- runtime_data = analyzer.analyze(paths)
54
- end
55
- puts
50
+ runtime_data = run_dynamic_analysis(paths)
56
51
  end
57
52
 
58
53
  FileFinder.find(paths).each do |file_path|
@@ -83,11 +78,32 @@ module Transpec
83
78
  end
84
79
 
85
80
  if project.rspec_version < Transpec.required_rspec_version
86
- fail "Your project must have rspec gem dependency #{Transpec.required_rspec_version} " +
81
+ fail "Your project must have rspec gem dependency #{Transpec.required_rspec_version} " \
87
82
  "or later but currently it's #{project.rspec_version}. Aborting."
88
83
  end
89
84
  end
90
85
 
86
+ def run_dynamic_analysis(paths)
87
+ runtime_data = nil
88
+
89
+ puts 'Copying the project for dynamic analysis...'
90
+
91
+ DynamicAnalyzer.new(rspec_command: configuration.rspec_command) do |analyzer|
92
+ puts "Running dynamic analysis with command #{analyzer.rspec_command.inspect}..."
93
+ runtime_data = analyzer.analyze(paths)
94
+ end
95
+
96
+ puts
97
+
98
+ runtime_data
99
+ rescue DynamicAnalyzer::AnalysisError
100
+ warn 'Failed running dynamic analysis. ' \
101
+ 'Transpec needs to run your specs in a copied project directory for dynamic analysis. ' \
102
+ 'If your project requires some special setup or commands to run specs, ' \
103
+ 'use -c/--rspec-command option.'
104
+ exit(1)
105
+ end
106
+
91
107
  def display_summary
92
108
  puts
93
109
 
@@ -16,7 +16,7 @@ module Transpec
16
16
  private
17
17
 
18
18
  def build_message(original_syntax, target_syntax)
19
- "Cannot convert #{original_syntax} into #{target_syntax} " +
19
+ "Cannot convert #{original_syntax} into #{target_syntax} " \
20
20
  "since #{target_syntax} is not available in the context."
21
21
  end
22
22
  end
@@ -86,22 +86,18 @@ module Transpec
86
86
 
87
87
  def analyze(paths = [])
88
88
  in_copied_project do
89
- rewriter = Rewriter.new
90
-
91
- FileFinder.find(paths).each do |file_path|
92
- begin
93
- rewriter.rewrite_file!(file_path)
94
- rescue Parser::SyntaxError # rubocop:disable HandleExceptions
95
- # Syntax errors will be reported in CLI with Converter.
96
- end
97
- end
89
+ rewrite_specs(paths)
98
90
 
99
91
  File.write(HELPER_FILE, HELPER_SOURCE)
100
92
 
101
93
  run_rspec(paths)
102
94
 
103
- File.open(RESULT_FILE) do |file|
104
- RuntimeData.load(file)
95
+ begin
96
+ File.open(RESULT_FILE) do |file|
97
+ RuntimeData.load(file)
98
+ end
99
+ rescue
100
+ raise AnalysisError
105
101
  end
106
102
  end
107
103
  end
@@ -154,6 +150,18 @@ module Transpec
154
150
 
155
151
  private
156
152
 
153
+ def rewrite_specs(paths)
154
+ rewriter = Rewriter.new
155
+
156
+ FileFinder.find(paths).each do |file_path|
157
+ begin
158
+ rewriter.rewrite_file!(file_path)
159
+ rescue Parser::SyntaxError # rubocop:disable HandleExceptions
160
+ # Syntax errors will be reported in CLI with Converter.
161
+ end
162
+ end
163
+ end
164
+
157
165
  def copy(source, destination)
158
166
  if File.symlink?(source)
159
167
  File.symlink(File.readlink(source), destination)
@@ -175,5 +183,7 @@ module Transpec
175
183
  File.chmod(source_mode, destination) unless File.symlink?(destination)
176
184
  end
177
185
  end
186
+
187
+ class AnalysisError < StandardError; end
178
188
  end
179
189
  end
@@ -20,7 +20,7 @@ module Transpec
20
20
 
21
21
  def base_paths(paths)
22
22
  if paths.empty?
23
- if Dir.exists?('spec')
23
+ if Dir.exist?('spec')
24
24
  ['spec']
25
25
  else
26
26
  fail ArgumentError, 'Specify target files or directories.'
@@ -5,7 +5,7 @@ module Transpec
5
5
  module Version
6
6
  MAJOR = 1
7
7
  MINOR = 10
8
- PATCH = 2
8
+ PATCH = 3
9
9
 
10
10
  def self.to_s
11
11
  [MAJOR, MINOR, PATCH].join('.')
@@ -148,6 +148,28 @@ module Transpec
148
148
  end
149
149
  end
150
150
 
151
+ context 'when analysis error is raised in the dynamic analysis' do
152
+ before do
153
+ Git.stub(:command_available?).and_return(false)
154
+ DynamicAnalyzer.any_instance.stub(:analyze).and_raise(DynamicAnalyzer::AnalysisError)
155
+ end
156
+
157
+ it 'suggests using -c/--rspec-command option' do
158
+ cli.stub(:exit)
159
+
160
+ cli.should_receive(:warn) do |message|
161
+ message.should include('-c/--rspec-command')
162
+ end
163
+
164
+ cli.run(args)
165
+ end
166
+
167
+ it 'exits with status 1' do
168
+ cli.should_receive(:exit).with(1)
169
+ cli.run(args)
170
+ end
171
+ end
172
+
151
173
  context 'when a syntax error is raised while processing files' do
152
174
  let(:args) { [invalid_syntax_file_path, valid_syntax_file_path] }
153
175
  let(:invalid_syntax_file_path) { 'invalid_example.rb' }
@@ -137,8 +137,8 @@ module Transpec
137
137
  context 'when analysis result data file is not found' do
138
138
  let(:source) { 'exit!' }
139
139
 
140
- it 'raises error' do
141
- -> { dynamic_analyzer.analyze }.should raise_error
140
+ it 'raises AnalysisError' do
141
+ -> { dynamic_analyzer.analyze }.should raise_error(DynamicAnalyzer::AnalysisError)
142
142
  end
143
143
  end
144
144
 
@@ -18,7 +18,7 @@ module Transpec
18
18
 
19
19
  let(:arg) { 'be_falsey' }
20
20
 
21
- context 'when it is `be_true`' do
21
+ context 'with expression `be_true`' do
22
22
  let(:source) do
23
23
  <<-END
24
24
  describe 'example' do
@@ -39,7 +39,7 @@ module Transpec
39
39
  END
40
40
  end
41
41
 
42
- it 'converts into `be_truthy`' do
42
+ it 'converts to `be_truthy`' do
43
43
  rewritten_source.should == expected_source
44
44
  end
45
45
 
@@ -49,7 +49,7 @@ module Transpec
49
49
  end
50
50
  end
51
51
 
52
- context 'when it is `be_false`' do
52
+ context 'with expression `be_false`' do
53
53
  let(:source) do
54
54
  <<-END
55
55
  describe 'example' do
@@ -70,7 +70,7 @@ module Transpec
70
70
  END
71
71
  end
72
72
 
73
- it 'converts into `be_falsey`' do
73
+ it 'converts to `be_falsey`' do
74
74
  rewritten_source.should == expected_source
75
75
  end
76
76
 
@@ -92,7 +92,7 @@ module Transpec
92
92
  END
93
93
  end
94
94
 
95
- it 'converts into `be_falsy`' do
95
+ it 'converts to `be_falsy`' do
96
96
  rewritten_source.should == expected_source
97
97
  end
98
98
 
@@ -109,7 +109,7 @@ module Transpec
109
109
  be_boolean_object.convert_to_exact_matcher!
110
110
  end
111
111
 
112
- context 'when it is `be_true`' do
112
+ context 'with expression `be_true`' do
113
113
  let(:source) do
114
114
  <<-END
115
115
  describe 'example' do
@@ -130,7 +130,7 @@ module Transpec
130
130
  END
131
131
  end
132
132
 
133
- it 'converts into `be true`' do
133
+ it 'converts to `be true`' do
134
134
  rewritten_source.should == expected_source
135
135
  end
136
136
 
@@ -140,7 +140,7 @@ module Transpec
140
140
  end
141
141
  end
142
142
 
143
- context 'when it is `be_false`' do
143
+ context 'with expression `be_false`' do
144
144
  let(:source) do
145
145
  <<-END
146
146
  describe 'example' do
@@ -161,7 +161,7 @@ module Transpec
161
161
  END
162
162
  end
163
163
 
164
- it 'converts into `be false`' do
164
+ it 'converts to `be false`' do
165
165
  rewritten_source.should == expected_source
166
166
  end
167
167
 
@@ -14,7 +14,7 @@ module Transpec
14
14
  be_close_object.convert_to_be_within!
15
15
  end
16
16
 
17
- context 'when it is `be_close(expected, delta)` form' do
17
+ context 'with expression `be_close(expected, delta)`' do
18
18
  let(:source) do
19
19
  <<-END
20
20
  describe 'example' do
@@ -35,7 +35,7 @@ module Transpec
35
35
  END
36
36
  end
37
37
 
38
- it 'converts into `be_within(delta).of(expected)` form' do
38
+ it 'converts to `be_within(delta).of(expected)` form' do
39
39
  rewritten_source.should == expected_source
40
40
  end
41
41
 
@@ -17,7 +17,7 @@ module Transpec
17
17
  end
18
18
 
19
19
  (RSpecDSL::EXAMPLE_METHODS + RSpecDSL::HOOK_METHODS).each do |method|
20
- context "when it is `#{method} do example end` form" do
20
+ context "with expression `#{method} do example end`" do
21
21
  let(:source) do
22
22
  <<-END
23
23
  describe 'example' do
@@ -38,7 +38,7 @@ module Transpec
38
38
  END
39
39
  end
40
40
 
41
- it "converts into `#{method} do |example| example end` form" do
41
+ it "converts to `#{method} do |example| example end` form" do
42
42
  rewritten_source.should == expected_source
43
43
  end
44
44
 
@@ -50,7 +50,7 @@ module Transpec
50
50
  end
51
51
 
52
52
  RSpecDSL::HELPER_METHODS.each do |method|
53
- context "when it is `#{method}(:name) do example end` form" do
53
+ context "with expression `#{method}(:name) do example end`" do
54
54
  let(:source) do
55
55
  <<-END
56
56
  describe 'example' do
@@ -71,7 +71,7 @@ module Transpec
71
71
  END
72
72
  end
73
73
 
74
- it "converts into `#{method}(:name) do |example| example end` form" do
74
+ it "converts to `#{method}(:name) do |example| example end` form" do
75
75
  rewritten_source.should == expected_source
76
76
  end
77
77
 
@@ -82,7 +82,7 @@ module Transpec
82
82
  end
83
83
  end
84
84
 
85
- context 'when it is `after { example }` form' do
85
+ context 'with expression `after { example }`' do
86
86
  let(:source) do
87
87
  <<-END
88
88
  describe 'example' do
@@ -103,12 +103,12 @@ module Transpec
103
103
  END
104
104
  end
105
105
 
106
- it 'converts into `after { |example| example }` form' do
106
+ it 'converts to `after { |example| example }` form' do
107
107
  rewritten_source.should == expected_source
108
108
  end
109
109
  end
110
110
 
111
- context 'when it is `after do running_example end` form' do
111
+ context 'with expression `after do running_example end`' do
112
112
  let(:source) do
113
113
  <<-END
114
114
  describe 'example' do
@@ -129,7 +129,7 @@ module Transpec
129
129
  END
130
130
  end
131
131
 
132
- it 'converts into `after do |example| example end` form' do
132
+ it 'converts to `after do |example| example end` form' do
133
133
  rewritten_source.should == expected_source
134
134
  end
135
135
  end
@@ -173,7 +173,7 @@ module Transpec
173
173
  end
174
174
  end
175
175
 
176
- context 'when it is `around do |ex| example end` form' do
176
+ context 'with expression `around do |ex| example end`' do
177
177
  let(:source) do
178
178
  <<-END
179
179
  describe 'example' do
@@ -194,12 +194,12 @@ module Transpec
194
194
  END
195
195
  end
196
196
 
197
- it 'converts into `around do |ex| ex end` form' do
197
+ it 'converts to `around do |ex| ex end` form' do
198
198
  rewritten_source.should == expected_source
199
199
  end
200
200
  end
201
201
 
202
- context "when it is `example 'it does something' do do_something end` form", :no_auto_convert do
202
+ context "with expression `example 'it does something' do do_something end`", :no_auto_convert do
203
203
  let(:source) do
204
204
  <<-END
205
205
  describe 'example' do
@@ -215,7 +215,7 @@ module Transpec
215
215
  end
216
216
  end
217
217
 
218
- context 'when it is `def helper_method example; end` form' do
218
+ context 'with expression `def helper_method example; end`' do
219
219
  let(:source) do
220
220
  <<-END
221
221
  module Helper
@@ -252,7 +252,7 @@ module Transpec
252
252
  END
253
253
  end
254
254
 
255
- it 'converts into `def helper_method RSpec.current_example; end` form' do
255
+ it 'converts to `def helper_method RSpec.current_example; end` form' do
256
256
  rewritten_source.should == expected_source
257
257
  end
258
258
 
@@ -117,7 +117,7 @@ module Transpec
117
117
  end
118
118
 
119
119
  [:mock, :stub].each do |method|
120
- context "when it is ##{method}" do
120
+ context "with expression `#{method}('something')`" do
121
121
  let(:source) do
122
122
  <<-END
123
123
  describe 'example' do
@@ -140,7 +140,7 @@ module Transpec
140
140
  END
141
141
  end
142
142
 
143
- it 'replaces with #double' do
143
+ it "converts to `#{method}('something')`" do
144
144
  rewritten_source.should == expected_source
145
145
  end
146
146
 
@@ -152,7 +152,7 @@ module Transpec
152
152
  end
153
153
  end
154
154
 
155
- context 'when it is #double' do
155
+ context "with expression `double('something')`" do
156
156
  let(:source) do
157
157
  <<-END
158
158
  describe 'example' do
@@ -70,7 +70,7 @@ module Transpec
70
70
  describe '#metadata_key_nodes' do
71
71
  subject { example_object.metadata_key_nodes }
72
72
 
73
- context 'when it is `it { }` form' do
73
+ context 'with expression `it { }`' do
74
74
  let(:source) do
75
75
  <<-END
76
76
  describe 'example' do
@@ -84,7 +84,7 @@ module Transpec
84
84
  end
85
85
  end
86
86
 
87
- context "when it is `it 'description' { }` form" do
87
+ context "with expression `it 'description' { }`" do
88
88
  let(:source) do
89
89
  <<-END
90
90
  describe 'example' do
@@ -100,7 +100,7 @@ module Transpec
100
100
  end
101
101
  end
102
102
 
103
- context "when it is `it 'description', :foo { }` form" do
103
+ context "with expression `it 'description', :foo { }`" do
104
104
  let(:source) do
105
105
  <<-END
106
106
  describe 'example' do
@@ -116,7 +116,7 @@ module Transpec
116
116
  end
117
117
  end
118
118
 
119
- context "when it is `it 'description', foo: true { }` form" do
119
+ context "with expression `it 'description', foo: true { }`" do
120
120
  let(:source) do
121
121
  <<-END
122
122
  describe 'example' do
@@ -132,7 +132,7 @@ module Transpec
132
132
  end
133
133
  end
134
134
 
135
- context "when it is `it 'description', :foo, :bar, baz: true { }` form" do
135
+ context "with expression `it 'description', :foo, :bar, baz: true { }`" do
136
136
  let(:source) do
137
137
  <<-END
138
138
  describe 'example' do
@@ -154,7 +154,7 @@ module Transpec
154
154
  example_object.convert_pending_to_skip!
155
155
  end
156
156
 
157
- context "when it is `pending 'is an example' { }` form" do
157
+ context "with expression `pending 'is an example' { }`" do
158
158
  let(:source) do
159
159
  <<-END
160
160
  describe 'example' do
@@ -175,7 +175,7 @@ module Transpec
175
175
  END
176
176
  end
177
177
 
178
- it "converts into `skip 'is an example' { }` form" do
178
+ it "converts to `skip 'is an example' { }` form" do
179
179
  rewritten_source.should == expected_source
180
180
  end
181
181
 
@@ -185,7 +185,7 @@ module Transpec
185
185
  end
186
186
  end
187
187
 
188
- context "when it is `it 'is an example' { }` form" do
188
+ context "with expression `it 'is an example' { }`" do
189
189
  let(:source) do
190
190
  <<-END
191
191
  describe 'example' do
@@ -201,7 +201,7 @@ module Transpec
201
201
  end
202
202
  end
203
203
 
204
- context "when it is `it 'is an example', :pending { }` form" do
204
+ context "with expression `it 'is an example', :pending { }`" do
205
205
  let(:source) do
206
206
  <<-END
207
207
  describe 'example' do
@@ -222,7 +222,7 @@ module Transpec
222
222
  END
223
223
  end
224
224
 
225
- it "converts into `it 'is an example', :skip { }` form" do
225
+ it "converts to `it 'is an example', :skip { }` form" do
226
226
  rewritten_source.should == expected_source
227
227
  end
228
228
 
@@ -232,7 +232,7 @@ module Transpec
232
232
  end
233
233
  end
234
234
 
235
- context "when it is `it 'description', :pending => true { }` form" do
235
+ context "with expression `it 'description', :pending => true { }`" do
236
236
  let(:source) do
237
237
  <<-END
238
238
  describe 'example' do
@@ -253,7 +253,7 @@ module Transpec
253
253
  END
254
254
  end
255
255
 
256
- it "converts into `it 'description', :skip => true { }` form" do
256
+ it "converts to `it 'description', :skip => true { }` form" do
257
257
  rewritten_source.should == expected_source
258
258
  end
259
259
 
@@ -263,7 +263,7 @@ module Transpec
263
263
  end
264
264
  end
265
265
 
266
- context "when it is `it 'description', pending: true { }` form" do
266
+ context "with expression `it 'description', pending: true { }`" do
267
267
  let(:source) do
268
268
  <<-END
269
269
  describe 'example' do
@@ -284,7 +284,7 @@ module Transpec
284
284
  END
285
285
  end
286
286
 
287
- it "converts into `it 'description', skip: true { }` form" do
287
+ it "converts to `it 'description', skip: true { }` form" do
288
288
  rewritten_source.should == expected_source
289
289
  end
290
290