synvert 0.0.13 → 0.0.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -0
  3. data/CHANGELOG.md +8 -0
  4. data/README.md +4 -2
  5. data/lib/synvert/cli.rb +87 -18
  6. data/lib/synvert/configuration.rb +9 -0
  7. data/lib/synvert/exceptions.rb +13 -0
  8. data/lib/synvert/node_ext.rb +106 -13
  9. data/lib/synvert/rewriter/action.rb +76 -0
  10. data/lib/synvert/rewriter/condition.rb +14 -0
  11. data/lib/synvert/rewriter/gem_spec.rb +12 -1
  12. data/lib/synvert/rewriter/instance.rb +69 -0
  13. data/lib/synvert/rewriter/scope.rb +10 -0
  14. data/lib/synvert/rewriter.rb +120 -11
  15. data/lib/synvert/snippets/factory_girl/syntax_methods.rb +51 -1
  16. data/lib/synvert/snippets/rails/convert_dynamic_finders.rb +12 -1
  17. data/lib/synvert/snippets/rails/strong_parameters.rb +22 -1
  18. data/lib/synvert/snippets/rails/upgrade_3_0_to_3_1.rb +48 -7
  19. data/lib/synvert/snippets/rails/upgrade_3_1_to_3_2.rb +14 -1
  20. data/lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb +90 -19
  21. data/lib/synvert/snippets/rspec/be_close_to_be_within.rb +7 -1
  22. data/lib/synvert/snippets/rspec/block_to_expect.rb +9 -1
  23. data/lib/synvert/snippets/rspec/boolean_matcher.rb +8 -1
  24. data/lib/synvert/snippets/rspec/collection_matcher.rb +12 -1
  25. data/lib/synvert/snippets/rspec/its_to_it.rb +34 -1
  26. data/lib/synvert/snippets/rspec/message_expectation.rb +14 -1
  27. data/lib/synvert/snippets/rspec/method_stub.rb +22 -1
  28. data/lib/synvert/snippets/rspec/negative_error_expectation.rb +8 -1
  29. data/lib/synvert/snippets/rspec/new_syntax.rb +5 -1
  30. data/lib/synvert/snippets/rspec/one_liner_expectation.rb +20 -1
  31. data/lib/synvert/snippets/rspec/should_to_expect.rb +15 -1
  32. data/lib/synvert/snippets/rspec/stub_and_mock_to_double.rb +8 -1
  33. data/lib/synvert/snippets/ruby/new_hash_syntax.rb +7 -1
  34. data/lib/synvert/snippets/ruby/new_lambda_syntax.rb +7 -1
  35. data/lib/synvert/version.rb +1 -1
  36. data/lib/synvert.rb +2 -1
  37. data/spec/synvert/rewriter/gem_spec_spec.rb +2 -2
  38. data/spec/synvert/rewriter_spec.rb +71 -34
  39. data/spec/synvert/snippets/rails/upgrade_3_0_to_3_1_spec.rb +2 -2
  40. metadata +4 -4
  41. data/lib/synvert/rewriter_not_found.rb +0 -4
@@ -2,10 +2,18 @@ require 'spec_helper'
2
2
 
3
3
  module Synvert
4
4
  describe Rewriter do
5
+ it 'parses description' do
6
+ rewriter = Rewriter.new 'name' do
7
+ description 'rewriter description'
8
+ end
9
+ rewriter.process
10
+ expect(rewriter.description).to eq 'rewriter description'
11
+ end
12
+
5
13
  it 'parses if_gem' do
6
- expect(Rewriter::GemSpec).to receive(:new).with('synvert', '1.0.0')
7
- rewriter = Rewriter.new 'name', 'description' do
8
- if_gem 'synvert', '1.0.0'
14
+ expect(Rewriter::GemSpec).to receive(:new).with('synvert', {gte: '1.0.0'})
15
+ rewriter = Rewriter.new 'name' do
16
+ if_gem 'synvert', {gte: '1.0.0'}
9
17
  end
10
18
  rewriter.process
11
19
  end
@@ -14,7 +22,7 @@ module Synvert
14
22
  it 'does nothing if if_gem not match' do
15
23
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(false)
16
24
  expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
17
- rewriter = Rewriter.new 'name', 'description' do
25
+ rewriter = Rewriter.new 'name' do
18
26
  if_gem 'synvert', '1.0.0'
19
27
  within_file 'config/routes.rb' do; end
20
28
  end
@@ -23,7 +31,7 @@ module Synvert
23
31
 
24
32
  it 'delegates process to instances if if_gem not exist' do
25
33
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
26
- rewriter = Rewriter.new 'name', 'description' do
34
+ rewriter = Rewriter.new 'name' do
27
35
  within_file 'config/routes.rb' do; end
28
36
  end
29
37
  rewriter.process
@@ -32,67 +40,91 @@ module Synvert
32
40
  it 'delegates process to instances if if_gem matches' do
33
41
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
34
42
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
35
- rewriter = Rewriter.new 'name', 'description' do
43
+ rewriter = Rewriter.new 'name' do
36
44
  if_gem 'synvert', '1.0.0'
37
45
  within_file 'config/routes.rb' do; end
38
46
  end
39
47
  rewriter.process
40
48
  end
49
+
50
+ it 'does nothing in sandbox mode' do
51
+ expect_any_instance_of(Rewriter::GemSpec).not_to receive(:match?)
52
+ expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
53
+ rewriter = Rewriter.new 'name' do
54
+ if_gem 'synvert', '1.0.0'
55
+ within_file 'config/routes.rb' do; end
56
+ end
57
+ rewriter.process_with_sandbox
58
+ end
41
59
  end
42
60
 
43
61
  describe 'parses add_file' do
44
- it 'processes the rewriter' do
45
- rewriter = Rewriter.new 'rewriter2', 'description2' do
62
+ it 'creates a new file' do
63
+ rewriter = Rewriter.new 'rewriter2' do
46
64
  add_file './foo.bar', 'FooBar'
47
65
  end
48
66
  rewriter.process
49
67
  expect(File.read './foo.bar').to eq 'FooBar'
50
68
  FileUtils.rm './foo.bar'
51
69
  end
70
+
71
+ it 'does nothing in sandbox mode' do
72
+ rewriter = Rewriter.new 'rewriter2' do
73
+ add_file './foo.bar', 'FooBar'
74
+ end
75
+ rewriter.process_with_sandbox
76
+ expect(File.exist?('./foo.bar')).to be_false
77
+ end
52
78
  end
53
79
 
54
80
  describe 'parses add_snippet' do
55
81
  it 'processes the rewritter' do
56
- rewriter1 = Rewriter.new 'rewriter1', 'description1'
57
- rewriter2 = Rewriter.new 'rewriter2', 'description2' do
82
+ rewriter1 = Rewriter.new 'rewriter1'
83
+ rewriter2 = Rewriter.new 'rewriter2' do
58
84
  add_snippet :rewriter1
59
85
  end
60
86
  expect(rewriter1).to receive(:process)
61
87
  rewriter2.process
62
88
  end
63
89
 
90
+ it 'adds sub_snippets' do
91
+ rewriter1 = Rewriter.new 'rewriter1'
92
+ rewriter2 = Rewriter.new 'rewriter2' do
93
+ add_snippet :rewriter1
94
+ end
95
+ expect(rewriter1).to receive(:process)
96
+ rewriter2.process
97
+ expect(rewriter2.sub_snippets).to eq [rewriter1]
98
+ end
99
+
64
100
  it 'raises RewriterNotFound' do
65
- rewriter = Rewriter.new 'name', 'description' do
101
+ rewriter = Rewriter.new 'name' do
66
102
  add_snippet :not_exist
67
103
  end
68
104
  expect { rewriter.process }.to raise_error(RewriterNotFound)
69
105
  end
70
106
  end
71
107
 
72
- describe 'parses helper_method' do
73
- it 'adds helper method to new instance' do
74
- instance = double
75
- expect(Rewriter::Instance).to receive(:new).and_return(instance)
76
- expect(instance).to receive(:process)
77
- rewriter = Rewriter.new 'name', 'description' do
78
- helper_method 'dynamic_helper' do |arg1, arg2|
79
- 'dynamic result'
80
- end
81
- within_file 'spec/spec_helper.rb' do; end
108
+ it 'parses helper_method' do
109
+ instance = double
110
+ expect(Rewriter::Instance).to receive(:new).and_return(instance)
111
+ expect(instance).to receive(:process)
112
+ rewriter = Rewriter.new 'name' do
113
+ helper_method 'dynamic_helper' do |arg1, arg2|
114
+ 'dynamic result'
82
115
  end
83
- rewriter.process
84
- expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
116
+ within_file 'spec/spec_helper.rb' do; end
85
117
  end
118
+ rewriter.process
119
+ expect(instance.dynamic_helper('arg1', 'arg2')).to eq 'dynamic result'
86
120
  end
87
121
 
88
- describe 'parses todo' do
89
- it 'sets todo_list' do
90
- rewriter = Rewriter.new 'name', 'description' do
91
- todo "this rewriter doesn't do blah blah blah"
92
- end
93
- rewriter.process
94
- expect(rewriter.todo_list).to eq "this rewriter doesn't do blah blah blah"
122
+ it 'parses todo' do
123
+ rewriter = Rewriter.new 'name' do
124
+ todo "this rewriter doesn't do blah blah blah"
95
125
  end
126
+ rewriter.process
127
+ expect(rewriter.todo).to eq "this rewriter doesn't do blah blah blah"
96
128
  end
97
129
 
98
130
  describe 'class methods' do
@@ -100,15 +132,20 @@ module Synvert
100
132
  Rewriter.clear
101
133
  end
102
134
 
135
+ it 'registers and fetches' do
136
+ rewriter = Rewriter.new 'rewriter'
137
+ expect(Rewriter.fetch('rewriter')).to eq rewriter
138
+ end
139
+
103
140
  it 'registers and calls rewriter' do
104
- rewriter = Rewriter.new 'rewriter', 'description'
141
+ rewriter = Rewriter.new 'rewriter'
105
142
  expect(rewriter).to receive(:process)
106
143
  Rewriter.call 'rewriter'
107
144
  end
108
145
 
109
- it 'registers and list all available rewriters' do
110
- rewriter1 = Rewriter.new 'rewriter1', 'description1'
111
- rewriter2 = Rewriter.new 'rewriter2', 'description2'
146
+ it 'registers and lists all available rewriters' do
147
+ rewriter1 = Rewriter.new 'rewriter1'
148
+ rewriter2 = Rewriter.new 'rewriter2'
112
149
  expect(Rewriter.availables).to eq [rewriter1, rewriter2]
113
150
  end
114
151
  end
@@ -11,14 +11,12 @@ describe 'Upgrade rails from 3.0 to 3.1' do
11
11
  describe 'with fakefs', fakefs: true do
12
12
  let(:application_content) {"""
13
13
  Synvert::Application.configure do
14
- config.assets.prefix = '/assets'
15
14
  end
16
15
  """}
17
16
  let(:application_rewritten_content) {"""
18
17
  Synvert::Application.configure do
19
18
  config.assets.enabled = true
20
19
  config.assets.version = '1.0'
21
- config.assets.prefix = '/asset-files'
22
20
  end
23
21
  """}
24
22
  let(:development_content) {"""
@@ -54,10 +52,12 @@ Synvert::Application.configure do
54
52
  end
55
53
  '''}
56
54
  let(:wrap_parameters_rewritten_content) {"""
55
+ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
57
56
  ActiveSupport.on_load(:action_controller) do
58
57
  wrap_parameters format: [:json]
59
58
  end
60
59
 
60
+ # Disable root element in JSON by default.
61
61
  ActiveSupport.on_load(:active_record) do
62
62
  self.include_root_in_json = false
63
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-02 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -114,6 +114,7 @@ files:
114
114
  - lib/synvert.rb
115
115
  - lib/synvert/cli.rb
116
116
  - lib/synvert/configuration.rb
117
+ - lib/synvert/exceptions.rb
117
118
  - lib/synvert/node_ext.rb
118
119
  - lib/synvert/rewriter.rb
119
120
  - lib/synvert/rewriter/action.rb
@@ -121,7 +122,6 @@ files:
121
122
  - lib/synvert/rewriter/gem_spec.rb
122
123
  - lib/synvert/rewriter/instance.rb
123
124
  - lib/synvert/rewriter/scope.rb
124
- - lib/synvert/rewriter_not_found.rb
125
125
  - lib/synvert/snippets/factory_girl/syntax_methods.rb
126
126
  - lib/synvert/snippets/rails/convert_dynamic_finders.rb
127
127
  - lib/synvert/snippets/rails/strong_parameters.rb
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.2.0.rc.1
185
+ rubygems_version: 2.2.2
186
186
  signing_key:
187
187
  specification_version: 4
188
188
  summary: synvert = syntax + convert.
@@ -1,4 +0,0 @@
1
- module Synvert
2
- class RewriterNotFound < Exception
3
- end
4
- end