synvert-core 0.15.1 → 0.18.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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -2
  3. data/Gemfile +2 -0
  4. data/Guardfile +2 -0
  5. data/Rakefile +2 -0
  6. data/lib/synvert/core.rb +2 -3
  7. data/lib/synvert/core/configuration.rb +2 -1
  8. data/lib/synvert/core/engine.rb +1 -1
  9. data/lib/synvert/core/engine/erb.rb +31 -23
  10. data/lib/synvert/core/exceptions.rb +5 -3
  11. data/lib/synvert/core/node_ext.rb +107 -101
  12. data/lib/synvert/core/rewriter.rb +20 -14
  13. data/lib/synvert/core/rewriter/action.rb +5 -7
  14. data/lib/synvert/core/rewriter/action/append_action.rb +8 -6
  15. data/lib/synvert/core/rewriter/action/insert_action.rb +18 -19
  16. data/lib/synvert/core/rewriter/action/insert_after_action.rb +2 -2
  17. data/lib/synvert/core/rewriter/action/remove_action.rb +2 -2
  18. data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +5 -4
  19. data/lib/synvert/core/rewriter/action/replace_with_action.rb +7 -5
  20. data/lib/synvert/core/rewriter/condition.rb +1 -1
  21. data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +2 -2
  22. data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +2 -3
  23. data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +2 -2
  24. data/lib/synvert/core/rewriter/gem_spec.rb +10 -10
  25. data/lib/synvert/core/rewriter/helper.rb +4 -6
  26. data/lib/synvert/core/rewriter/instance.rb +36 -22
  27. data/lib/synvert/core/rewriter/ruby_version.rb +1 -1
  28. data/lib/synvert/core/rewriter/scope.rb +1 -1
  29. data/lib/synvert/core/rewriter/scope/goto_scope.rb +2 -1
  30. data/lib/synvert/core/rewriter/scope/within_scope.rb +23 -7
  31. data/lib/synvert/core/rewriter/warning.rb +1 -1
  32. data/lib/synvert/core/version.rb +2 -2
  33. data/spec/spec_helper.rb +3 -1
  34. data/spec/support/parser_helper.rb +2 -0
  35. data/spec/synvert/core/configuration_spec.rb +3 -1
  36. data/spec/synvert/core/engine/erb_spec.rb +32 -30
  37. data/spec/synvert/core/node_ext_spec.rb +57 -54
  38. data/spec/synvert/core/rewriter/action/append_action_spec.rb +2 -0
  39. data/spec/synvert/core/rewriter/action/insert_action_spec.rb +10 -8
  40. data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +5 -3
  41. data/spec/synvert/core/rewriter/action/remove_action_spec.rb +3 -1
  42. data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +2 -0
  43. data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +17 -11
  44. data/spec/synvert/core/rewriter/action_spec.rb +2 -0
  45. data/spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb +19 -9
  46. data/spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb +23 -12
  47. data/spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb +19 -9
  48. data/spec/synvert/core/rewriter/condition_spec.rb +2 -0
  49. data/spec/synvert/core/rewriter/gem_spec_spec.rb +13 -10
  50. data/spec/synvert/core/rewriter/helper_spec.rb +36 -31
  51. data/spec/synvert/core/rewriter/instance_spec.rb +118 -66
  52. data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +10 -6
  53. data/spec/synvert/core/rewriter/scope/within_scope.rb +18 -9
  54. data/spec/synvert/core/rewriter/scope_spec.rb +2 -0
  55. data/spec/synvert/core/rewriter/warning_spec.rb +2 -0
  56. data/spec/synvert/core/rewriter_spec.rb +106 -73
  57. data/synvert-core.gemspec +2 -2
  58. metadata +12 -12
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
@@ -10,66 +12,104 @@ module Synvert::Core
10
12
  }
11
13
 
12
14
  it 'parses within_node' do
13
- scope = double()
14
- block = Proc.new {}
15
- expect(Rewriter::WithinScope).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(scope)
15
+ scope = double
16
+ block = proc {}
17
+ expect(Rewriter::WithinScope).to receive(:new)
18
+ .with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block)
19
+ .and_return(scope)
16
20
  expect(scope).to receive(:process)
17
21
  instance.within_node(type: 'send', message: 'create', &block)
18
22
  end
19
23
 
20
24
  it 'parses with_node' do
21
- scope = double()
22
- block = Proc.new {}
23
- expect(Rewriter::WithinScope).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(scope)
25
+ scope = double
26
+ block = proc {}
27
+ expect(Rewriter::WithinScope).to receive(:new)
28
+ .with(instance, { type: 'send', message: 'create' }, { recursive: true }, &block)
29
+ .and_return(scope)
24
30
  expect(scope).to receive(:process)
25
31
  instance.with_node(type: 'send', message: 'create', &block)
26
32
  end
27
33
 
34
+ it 'parses within_direct_node' do
35
+ scope = double
36
+ block = proc {}
37
+ expect(Rewriter::WithinScope).to receive(:new)
38
+ .with(instance, { type: 'send', message: 'create' }, { recursive: false }, &block)
39
+ .and_return(scope)
40
+ expect(scope).to receive(:process)
41
+ instance.within_direct_node(type: 'send', message: 'create', &block)
42
+ end
43
+
44
+ it 'parses with_direct_node' do
45
+ scope = double
46
+ block = proc {}
47
+ expect(Rewriter::WithinScope).to receive(:new)
48
+ .with(instance, { type: 'send', message: 'create' }, { recursive: false }, &block)
49
+ .and_return(scope)
50
+ expect(scope).to receive(:process)
51
+ instance.with_direct_node(type: 'send', message: 'create', &block)
52
+ end
53
+
28
54
  it 'parses goto_node' do
29
- scope = double()
30
- block = Proc.new {}
55
+ scope = double
56
+ block = proc {}
31
57
  expect(Rewriter::GotoScope).to receive(:new).with(instance, :caller, &block).and_return(scope)
32
58
  expect(scope).to receive(:process)
33
59
  instance.goto_node(:caller, &block)
34
60
  end
35
61
 
36
62
  it 'parses if_exist_node' do
37
- condition = double()
38
- block = Proc.new {}
39
- expect(Rewriter::IfExistCondition).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(condition)
63
+ condition = double
64
+ block = proc {}
65
+ expect(Rewriter::IfExistCondition).to receive(:new)
66
+ .with(instance, type: 'send', message: 'create', &block)
67
+ .and_return(condition)
40
68
  expect(condition).to receive(:process)
41
69
  instance.if_exist_node(type: 'send', message: 'create', &block)
42
70
  end
43
71
 
44
72
  it 'parses unless_exist_node' do
45
- condition = double()
46
- block = Proc.new {}
47
- expect(Rewriter::UnlessExistCondition).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(condition)
73
+ condition = double
74
+ block = proc {}
75
+ expect(Rewriter::UnlessExistCondition).to receive(:new)
76
+ .with(instance, type: 'send', message: 'create', &block)
77
+ .and_return(condition)
48
78
  expect(condition).to receive(:process)
49
79
  instance.unless_exist_node(type: 'send', message: 'create', &block)
50
80
  end
51
81
 
52
82
  it 'parses if_only_exist_node' do
53
- condition = double()
54
- block = Proc.new {}
55
- expect(Rewriter::IfOnlyExistCondition).to receive(:new).with(instance, type: 'send', message: 'create', &block).and_return(condition)
83
+ condition = double
84
+ block = proc {}
85
+ expect(Rewriter::IfOnlyExistCondition).to receive(:new)
86
+ .with(instance, type: 'send', message: 'create', &block)
87
+ .and_return(condition)
56
88
  expect(condition).to receive(:process)
57
89
  instance.if_only_exist_node(type: 'send', message: 'create', &block)
58
90
  end
59
91
 
60
92
  it 'parses append' do
61
93
  expect(Rewriter::AppendAction).to receive(:new).with(instance, 'include FactoryGirl::Syntax::Methods', {})
62
- instance.append "include FactoryGirl::Syntax::Methods"
94
+ instance.append 'include FactoryGirl::Syntax::Methods'
63
95
  end
64
96
 
65
97
  it 'parses insert' do
66
- expect(Rewriter::InsertAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods', {})
67
- instance.insert "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
98
+ expect(Rewriter::InsertAction).to receive(:new).with(
99
+ instance,
100
+ '{{arguments.first}}.include FactoryGirl::Syntax::Methods',
101
+ {}
102
+ )
103
+ instance.insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
68
104
  end
69
105
 
70
106
  it 'parses insert_after' do
71
- expect(Rewriter::InsertAfterAction).to receive(:new).with(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods', {})
72
- instance.insert_after "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
107
+ expect(Rewriter::InsertAfterAction).to receive(:new).with(
108
+ instance,
109
+ '{{arguments.first}}.include FactoryGirl::Syntax::Methods',
110
+ {}
111
+ )
112
+ instance.insert_after '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
73
113
  end
74
114
 
75
115
  it 'parses replace_with' do
@@ -91,25 +131,28 @@ module Synvert::Core
91
131
  let(:rewriter) { Rewriter.new('foo', 'bar') }
92
132
 
93
133
  it 'writes new code to file' do
94
- instance = Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
95
- with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
96
- replace_with 'create {{arguments}}'
134
+ instance =
135
+ Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
136
+ with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
137
+ replace_with 'create {{arguments}}'
138
+ end
97
139
  end
98
- end
99
- input = """
140
+ input =
141
+ "
100
142
  it 'uses factory_girl' do
101
143
  user = FactoryGirl.create :user
102
144
  post = FactoryGirl.create :post, user: user
103
145
  assert post.valid?
104
146
  end
105
- """
106
- output = """
147
+ "
148
+ output =
149
+ "
107
150
  it 'uses factory_girl' do
108
151
  user = create :user
109
152
  post = create :post, user: user
110
153
  assert post.valid?
111
154
  end
112
- """
155
+ "
113
156
  expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb'])
114
157
  expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
115
158
  expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
@@ -117,23 +160,26 @@ end
117
160
  end
118
161
 
119
162
  it 'does not write if file content is not changed' do
120
- instance = Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
121
- with_node type: 'block', caller: {receiver: 'RSpec', message: 'configure'} do
122
- unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
123
- insert "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
163
+ instance =
164
+ Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
165
+ with_node type: 'block', caller: { receiver: 'RSpec', message: 'configure' } do
166
+ unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
167
+ insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
168
+ end
124
169
  end
125
170
  end
126
- end
127
- input = """
171
+ input =
172
+ '
128
173
  RSpec.configure do |config|
129
174
  config.include FactoryGirl::Syntax::Methods
130
175
  end
131
- """
132
- output = """
176
+ '
177
+ output =
178
+ '
133
179
  RSpec.configure do |config|
134
180
  config.include FactoryGirl::Syntax::Methods
135
181
  end
136
- """
182
+ '
137
183
  expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb'])
138
184
  expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input)
139
185
  expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
@@ -141,23 +187,26 @@ end
141
187
  end
142
188
 
143
189
  it 'does not read file if already read' do
144
- instance = Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
145
- with_node type: 'block', caller: {receiver: 'RSpec', message: 'configure'} do
146
- unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
147
- insert "{{arguments.first}}.include FactoryGirl::Syntax::Methods"
190
+ instance =
191
+ Rewriter::Instance.new rewriter, 'spec/spec_helper.rb' do
192
+ with_node type: 'block', caller: { receiver: 'RSpec', message: 'configure' } do
193
+ unless_exist_node type: 'send', message: 'include', arguments: ['FactoryGirl::Syntax::Methods'] do
194
+ insert '{{arguments.first}}.include FactoryGirl::Syntax::Methods'
195
+ end
148
196
  end
149
197
  end
150
- end
151
- input = """
198
+ input =
199
+ '
152
200
  RSpec.configure do |config|
153
201
  config.include FactoryGirl::Syntax::Methods
154
202
  end
155
- """
156
- output = """
203
+ '
204
+ output =
205
+ '
157
206
  RSpec.configure do |config|
158
207
  config.include FactoryGirl::Syntax::Methods
159
208
  end
160
- """
209
+ '
161
210
  expect(Dir).to receive(:glob).with('./spec/spec_helper.rb').and_return(['spec/spec_helper.rb']).twice
162
211
  expect(File).to receive(:read).with('spec/spec_helper.rb').and_return(input).once
163
212
  expect(File).not_to receive(:write).with('spec/spec_helper.rb', output)
@@ -166,25 +215,28 @@ end
166
215
  end
167
216
 
168
217
  it 'updates file_source and file_ast when writing a file' do
169
- instance = Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
170
- with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
171
- replace_with 'create {{arguments}}'
218
+ instance =
219
+ Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
220
+ with_node type: 'send', receiver: 'FactoryGirl', message: 'create' do
221
+ replace_with 'create {{arguments}}'
222
+ end
172
223
  end
173
- end
174
- input = """
224
+ input =
225
+ "
175
226
  it 'uses factory_girl' do
176
227
  user = FactoryGirl.create :user
177
228
  post = FactoryGirl.create :post, user: user
178
229
  assert post.valid?
179
230
  end
180
- """
181
- output = """
231
+ "
232
+ output =
233
+ "
182
234
  it 'uses factory_girl' do
183
235
  user = create :user
184
236
  post = create :post, user: user
185
237
  assert post.valid?
186
238
  end
187
- """
239
+ "
188
240
  expect(Dir).to receive(:glob).with('./spec/**/*_spec.rb').and_return(['spec/models/post_spec.rb']).twice
189
241
  expect(File).to receive(:read).with('spec/models/post_spec.rb').and_return(input)
190
242
  expect(File).to receive(:write).with('spec/models/post_spec.rb', output)
@@ -194,10 +246,10 @@ end
194
246
  end
195
247
  end
196
248
 
197
- describe "#get_conflict_actions" do
249
+ describe '#get_conflict_actions' do
198
250
  let(:rewriter) { Rewriter.new('foo', 'bar') }
199
251
 
200
- it "has no conflict" do
252
+ it 'has no conflict' do
201
253
  action1 = double(begin_pos: 10, end_pos: 20)
202
254
  action2 = double(begin_pos: 30, end_pos: 40)
203
255
  action3 = double(begin_pos: 50, end_pos: 60)
@@ -205,10 +257,10 @@ end
205
257
  instance.instance_variable_set :@actions, [action1, action2, action3]
206
258
  conflict_actions = instance.send(:get_conflict_actions)
207
259
  expect(conflict_actions).to eq []
208
- expect(instance.instance_variable_get :@actions).to eq [action1, action2, action3]
260
+ expect(instance.instance_variable_get(:@actions)).to eq [action1, action2, action3]
209
261
  end
210
262
 
211
- it "has no conflict" do
263
+ it 'has no conflict' do
212
264
  action1 = double(begin_pos: 30, end_pos: 40)
213
265
  action2 = double(begin_pos: 50, end_pos: 60)
214
266
  action3 = double(begin_pos: 10, end_pos: 20)
@@ -216,14 +268,14 @@ end
216
268
  instance.instance_variable_set :@actions, [action1, action2, action3]
217
269
  conflict_actions = instance.send(:get_conflict_actions)
218
270
  expect(conflict_actions).to eq [action2, action1]
219
- expect(instance.instance_variable_get :@actions).to eq [action3]
271
+ expect(instance.instance_variable_get(:@actions)).to eq [action3]
220
272
  end
221
273
  end
222
274
 
223
275
  describe '#process_with_node' do
224
276
  it 'resets current_node' do
225
- node1 = double()
226
- node2 = double()
277
+ node1 = double
278
+ node2 = double
227
279
  instance.process_with_node(node1) do
228
280
  instance.current_node = node2
229
281
  expect(instance.current_node).to eq node2
@@ -234,9 +286,9 @@ end
234
286
 
235
287
  describe '#process_with_other_node' do
236
288
  it 'resets current_node' do
237
- node1 = double()
238
- node2 = double()
239
- node3 = double()
289
+ node1 = double
290
+ node2 = double
291
+ node3 = double
240
292
  instance.current_node = node1
241
293
  instance.process_with_other_node(node2) do
242
294
  instance.current_node = node3
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
@@ -6,10 +8,11 @@ module Synvert::Core
6
8
  rewriter = Rewriter.new('foo', 'bar')
7
9
  Rewriter::Instance.new(rewriter, 'file pattern')
8
10
  }
9
- let(:source) {'''
11
+ let(:source) {
12
+ '
10
13
  Factory.define :user do |user|
11
14
  end
12
- '''
15
+ '
13
16
  }
14
17
  let(:node) { Parser::CurrentRuby.parse(source) }
15
18
  before do
@@ -21,10 +24,11 @@ end
21
24
  it 'call block with child node' do
22
25
  run = false
23
26
  type_in_scope = nil
24
- scope = Rewriter::GotoScope.new instance, :caller do
25
- run = true
26
- type_in_scope = node.type
27
- end
27
+ scope =
28
+ Rewriter::GotoScope.new instance, :caller do
29
+ run = true
30
+ type_in_scope = node.type
31
+ end
28
32
  scope.process
29
33
  expect(run).to be_truthy
30
34
  expect(type_in_scope).to eq :send
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
@@ -6,13 +8,14 @@ module Synvert::Core
6
8
  rewriter = Rewriter.new('foo', 'bar')
7
9
  Rewriter::Instance.new(rewriter, 'file pattern')
8
10
  }
9
- let(:source) {"""
11
+ let(:source) {
12
+ "
10
13
  describe Post do
11
14
  it 'gets post' do
12
15
  FactoryGirl.create :post
13
16
  end
14
17
  end
15
- """
18
+ "
16
19
  }
17
20
  let(:node) { Parser::CurrentRuby.parse(source) }
18
21
  before do
@@ -23,9 +26,10 @@ end
23
26
  describe '#process' do
24
27
  it 'not call block if no matching node' do
25
28
  run = false
26
- scope = Rewriter::WithinScope.new instance, type: 'send', message: 'missing' do
27
- run = true
28
- end
29
+ scope =
30
+ Rewriter::WithinScope.new instance, type: 'send', message: 'missing' do
31
+ run = true
32
+ end
29
33
  scope.process
30
34
  expect(run).to be_falsey
31
35
  end
@@ -33,10 +37,15 @@ end
33
37
  it 'call block if there is matching node' do
34
38
  run = false
35
39
  type_in_scope = nil
36
- scope = Rewriter::WithinScope.new instance, type: 'send', receiver: 'FactoryGirl', message: 'create', arguments: [':post'] do
37
- run = true
38
- type_in_scope = node.type
39
- end
40
+ scope =
41
+ Rewriter::WithinScope.new instance,
42
+ type: 'send',
43
+ receiver: 'FactoryGirl',
44
+ message: 'create',
45
+ arguments: [':post'] do
46
+ run = true
47
+ type_in_scope = node.type
48
+ end
40
49
  scope.process
41
50
  expect(run).to be_truthy
42
51
  expect(type_in_scope).to eq :send
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
@@ -1,28 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  module Synvert::Core
4
6
  describe Rewriter do
7
+ it '.execute' do
8
+ run = false
9
+ Rewriter.execute { run = true }
10
+ expect(run).to be_truthy
11
+ end
12
+
5
13
  it 'parses description' do
6
- rewriter = Rewriter.new 'group', 'name' do
7
- description 'rewriter description'
8
- end
14
+ rewriter =
15
+ Rewriter.new 'group', 'name' do
16
+ description 'rewriter description'
17
+ end
9
18
  rewriter.process
10
19
  expect(rewriter.description).to eq 'rewriter description'
11
20
  end
12
21
 
13
22
  it 'parses if_ruby' do
14
- #stub_const("RUBY_VERSION", '2.0.0')
15
- rewriter = Rewriter.new 'group', 'name' do
16
- if_ruby '2.0.0'
17
- end
23
+ expect(Rewriter::RubyVersion).to receive(:new).with('2.0.0')
24
+ rewriter =
25
+ Rewriter.new 'group', 'name' do
26
+ if_ruby '2.0.0'
27
+ end
18
28
  rewriter.process
19
29
  end
20
30
 
21
31
  it 'parses if_gem' do
22
- expect(Rewriter::GemSpec).to receive(:new).with('synvert', {gte: '1.0.0'})
23
- rewriter = Rewriter.new 'group', 'name' do
24
- if_gem 'synvert', {gte: '1.0.0'}
25
- end
32
+ expect(Rewriter::GemSpec).to receive(:new).with('synvert', { gte: '1.0.0' })
33
+ rewriter =
34
+ Rewriter.new 'group', 'name' do
35
+ if_gem 'synvert', { gte: '1.0.0' }
36
+ end
26
37
  rewriter.process
27
38
  end
28
39
 
@@ -30,76 +41,90 @@ module Synvert::Core
30
41
  it 'does nothing if if_ruby does not match' do
31
42
  stub_const('RUBY_VERSION', '2.0.0')
32
43
  expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
33
- rewriter = Rewriter.new 'group', 'name' do
34
- if_ruby '2.2.3'
35
- within_file 'config/routes.rb' do; end
36
- end
44
+ rewriter =
45
+ Rewriter.new 'group', 'name' do
46
+ if_ruby '2.2.3'
47
+ within_file 'config/routes.rb' do
48
+ end
49
+ end
37
50
  rewriter.process
38
51
  end
39
52
 
40
53
  it 'delegates process to instances if if_ruby matches' do
41
54
  stub_const('RUBY_VERSION', '2.0.0')
42
55
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
43
- rewriter = Rewriter.new 'group', 'name' do
44
- if_ruby '1.9.3'
45
- within_file 'config/routes.rb' do; end
46
- end
56
+ rewriter =
57
+ Rewriter.new 'group', 'name' do
58
+ if_ruby '1.9.3'
59
+ within_file 'config/routes.rb' do
60
+ end
61
+ end
47
62
  rewriter.process
48
63
  end
49
64
 
50
65
  it 'does nothing if if_gem does not match' do
51
66
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(false)
52
67
  expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
53
- rewriter = Rewriter.new 'group', 'name' do
54
- if_gem 'synvert', '1.0.0'
55
- within_file 'config/routes.rb' do; end
56
- end
68
+ rewriter =
69
+ Rewriter.new 'group', 'name' do
70
+ if_gem 'synvert', '1.0.0'
71
+ within_file 'config/routes.rb' do
72
+ end
73
+ end
57
74
  rewriter.process
58
75
  end
59
76
 
60
77
  it 'delegates process to instances if if_gem matches' do
61
78
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
62
79
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
63
- rewriter = Rewriter.new 'group', 'name' do
64
- if_gem 'synvert', '1.0.0'
65
- within_file 'config/routes.rb' do; end
66
- end
80
+ rewriter =
81
+ Rewriter.new 'group', 'name' do
82
+ if_gem 'synvert', '1.0.0'
83
+ within_file 'config/routes.rb' do
84
+ end
85
+ end
67
86
  rewriter.process
68
87
  end
69
88
 
70
89
  it 'delegates process to instances if if_ruby and if_gem do not exist' do
71
90
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
72
- rewriter = Rewriter.new 'group', 'name' do
73
- within_file 'config/routes.rb' do; end
74
- end
91
+ rewriter =
92
+ Rewriter.new 'group', 'name' do
93
+ within_file 'config/routes.rb' do
94
+ end
95
+ end
75
96
  rewriter.process
76
97
  end
77
98
 
78
99
  it 'does nothing in sandbox mode' do
79
100
  expect_any_instance_of(Rewriter::GemSpec).not_to receive(:match?)
80
101
  expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
81
- rewriter = Rewriter.new 'group', 'name' do
82
- if_gem 'synvert', '1.0.0'
83
- within_file 'config/routes.rb' do; end
84
- end
102
+ rewriter =
103
+ Rewriter.new 'group', 'name' do
104
+ if_gem 'synvert', '1.0.0'
105
+ within_file 'config/routes.rb' do
106
+ end
107
+ end
85
108
  rewriter.process_with_sandbox
86
109
  end
87
110
  end
88
111
 
89
112
  describe 'parses add_file' do
90
113
  it 'creates a new file' do
91
- rewriter = Rewriter.new 'group', 'rewriter2' do
92
- add_file 'foo.bar', 'FooBar'
93
- end
114
+ rewriter =
115
+ Rewriter.new 'group', 'rewriter2' do
116
+ add_file 'foo.bar', 'FooBar'
117
+ end
94
118
  rewriter.process
95
- expect(File.read './foo.bar').to eq 'FooBar'
119
+ expect(File.read('./foo.bar')).to eq 'FooBar'
96
120
  FileUtils.rm './foo.bar'
97
121
  end
98
122
 
99
123
  it 'does nothing in sandbox mode' do
100
- rewriter = Rewriter.new 'group', 'rewriter2' do
101
- add_file 'foo.bar', 'FooBar'
102
- end
124
+ rewriter =
125
+ Rewriter.new 'group', 'rewriter2' do
126
+ add_file 'foo.bar', 'FooBar'
127
+ end
103
128
  rewriter.process_with_sandbox
104
129
  expect(File.exist?('./foo.bar')).to be_falsey
105
130
  end
@@ -108,26 +133,29 @@ module Synvert::Core
108
133
  describe 'parses remove_file' do
109
134
  it 'removes a file' do
110
135
  FileUtils.touch './foo.bar'
111
- rewriter = Rewriter.new 'group', 'rewriter2' do
112
- remove_file 'foo.bar'
113
- end
136
+ rewriter =
137
+ Rewriter.new 'group', 'rewriter2' do
138
+ remove_file 'foo.bar'
139
+ end
114
140
  rewriter.process
115
- expect(File.exist? './foo.bar').to be_falsey
141
+ expect(File.exist?('./foo.bar')).to be_falsey
116
142
  end
117
143
 
118
144
  it 'does nothing if file not exist' do
119
- rewriter = Rewriter.new 'group', 'rewriter2' do
120
- remove_file 'foo.bar'
121
- end
145
+ rewriter =
146
+ Rewriter.new 'group', 'rewriter2' do
147
+ remove_file 'foo.bar'
148
+ end
122
149
  rewriter.process
123
- expect(File.exist? './foo.bar').to be_falsey
150
+ expect(File.exist?('./foo.bar')).to be_falsey
124
151
  end
125
152
 
126
153
  it 'does nothing in sandbox mode' do
127
154
  FileUtils.touch './foo.bar'
128
- rewriter = Rewriter.new 'group', 'rewriter2' do
129
- add_file 'foo.bar', 'FooBar'
130
- end
155
+ rewriter =
156
+ Rewriter.new 'group', 'rewriter2' do
157
+ add_file 'foo.bar', 'FooBar'
158
+ end
131
159
  rewriter.process_with_sandbox
132
160
  expect(File.exist?('./foo.bar')).to be_truthy
133
161
  FileUtils.rm './foo.bar'
@@ -137,46 +165,51 @@ module Synvert::Core
137
165
  describe 'parses add_snippet' do
138
166
  it 'processes the rewritter' do
139
167
  rewriter1 = Rewriter.new 'group', 'rewriter1'
140
- rewriter2 = Rewriter.new 'group', 'rewriter2' do
141
- add_snippet :group, :rewriter1
142
- end
168
+ rewriter2 =
169
+ Rewriter.new 'group', 'rewriter2' do
170
+ add_snippet :group, :rewriter1
171
+ end
143
172
  expect(rewriter1).to receive(:process)
144
173
  rewriter2.process
145
174
  end
146
175
 
147
176
  it 'adds sub_snippets' do
148
177
  rewriter1 = Rewriter.new 'group', 'rewriter1'
149
- rewriter2 = Rewriter.new 'group', 'rewriter2' do
150
- add_snippet :group, :rewriter1
151
- end
178
+ rewriter2 =
179
+ Rewriter.new 'group', 'rewriter2' do
180
+ add_snippet :group, :rewriter1
181
+ end
152
182
  expect(rewriter1).to receive(:process)
153
183
  rewriter2.process
154
184
  expect(rewriter2.sub_snippets).to eq [rewriter1]
155
185
  end
156
186
 
157
187
  it 'raises RewriterNotFound' do
158
- rewriter = Rewriter.new 'group', 'name' do
159
- add_snippet :group, :not_exist
160
- end
188
+ rewriter =
189
+ Rewriter.new 'group', 'name' do
190
+ add_snippet :group, :not_exist
191
+ end
161
192
  expect { rewriter.process }.to raise_error(RewriterNotFound)
162
193
  end
163
194
  end
164
195
 
165
196
  it 'parses helper_method' do
166
- rewriter = Rewriter.new 'group', 'name' do
167
- helper_method 'dynamic_helper' do |arg1, arg2|
168
- 'dynamic result'
197
+ rewriter =
198
+ Rewriter.new 'group', 'name' do
199
+ helper_method 'dynamic_helper' do |_arg1, _arg2|
200
+ 'dynamic result'
201
+ end
169
202
  end
170
- end
171
203
  rewriter.process
172
204
  instance = Rewriter::Instance.new(rewriter, '*.rb')
173
205
  expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
174
206
  end
175
207
 
176
208
  it 'parses todo' do
177
- rewriter = Rewriter.new 'group', 'name' do
178
- todo "this rewriter doesn't do blah blah blah"
179
- end
209
+ rewriter =
210
+ Rewriter.new 'group', 'name' do
211
+ todo "this rewriter doesn't do blah blah blah"
212
+ end
180
213
  rewriter.process
181
214
  expect(rewriter.todo).to eq "this rewriter doesn't do blah blah blah"
182
215
  end
@@ -201,18 +234,18 @@ module Synvert::Core
201
234
  expect { Rewriter.call 'group', 'rewriter' }.to raise_error(RewriterNotFound)
202
235
  end
203
236
 
204
- context "exist?" do
237
+ context 'exist?' do
205
238
  it 'returns true if rewriter exists' do
206
239
  Rewriter.new 'group', 'rewriter'
207
- expect(Rewriter.exist? 'group', 'rewriter').to be_truthy
240
+ expect(Rewriter.exist?('group', 'rewriter')).to be_truthy
208
241
  end
209
242
 
210
243
  it 'returns false if rewriter does not exist' do
211
- expect(Rewriter.exist? 'group', 'rewriter').to be_falsey
244
+ expect(Rewriter.exist?('group', 'rewriter')).to be_falsey
212
245
  end
213
246
  end
214
247
 
215
- context "available" do
248
+ context 'available' do
216
249
  it 'lists empty rewriters' do
217
250
  expect(Rewriter.availables).to eq({})
218
251
  end
@@ -220,7 +253,7 @@ module Synvert::Core
220
253
  it 'registers and lists all available rewriters' do
221
254
  rewriter1 = Rewriter.new 'group', 'rewriter1'
222
255
  rewriter2 = Rewriter.new 'group', 'rewriter2'
223
- expect(Rewriter.availables).to eq({'group' => {'rewriter1' => rewriter1, 'rewriter2' => rewriter2}})
256
+ expect(Rewriter.availables).to eq({ 'group' => { 'rewriter1' => rewriter1, 'rewriter2' => rewriter2 } })
224
257
  end
225
258
  end
226
259
  end