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
@@ -1,4 +1,54 @@
1
- Synvert::Rewriter.new "factory_girl_short_syntax", "FactoryGirl uses short syntax" do
1
+ Synvert::Rewriter.new "factory_girl_short_syntax" do
2
+ description <<-EOF
3
+ Uses FactoryGirl short syntax.
4
+
5
+ 1. it adds FactoryGirl::Syntax::methods module to RSpec, Test::Unit, Cucumber, Spainach, MiniTest, MiniTest::Spec, minitest-rails.
6
+
7
+ # rspec
8
+ RSpec.configure do |config|
9
+ config.include FactoryGirl::Syntax::Methods
10
+ end
11
+
12
+ # Test::Unit
13
+ class Test::Unit::TestCase
14
+ include FactoryGirl::Syntax::Methods
15
+ end
16
+
17
+ # Cucumber
18
+ World(FactoryGirl::Syntax::Methods)
19
+
20
+ # Spinach
21
+ class Spinach::FeatureSteps
22
+ include FactoryGirl::Syntax::Methods
23
+ end
24
+
25
+ # MiniTest
26
+ class MiniTest::Unit::TestCase
27
+ include FactoryGirl::Syntax::Methods
28
+ end
29
+
30
+ # MiniTest::Spec
31
+ class MiniTest::Spec
32
+ include FactoryGirl::Syntax::Methods
33
+ end
34
+
35
+ # minitest-rails
36
+ class MiniTest::Rails::ActiveSupport::TestCase
37
+ include FactoryGirl::Syntax::Methods
38
+ end
39
+
40
+ 2. it converts to short syntax.
41
+
42
+ FactoryGirl.create(...) => create(...)
43
+ FactoryGirl.build(...) => build(...)
44
+ FactoryGirl.attributes_for(...) => attributes_for(...)
45
+ FactoryGirl.build_stubbed(...) => build_stubbed(...)
46
+ FactoryGirl.create_list(...) => create_list(...)
47
+ FactoryGirl.build_list(...) => build_list(...)
48
+ FactoryGirl.create_pair(...) => create_pair(...)
49
+ FactoryGirl.build_pair(...) => build_pair(...)
50
+ EOF
51
+
2
52
  if_gem 'factory_girl', {gte: '2.0.0'}
3
53
 
4
54
  # insert include FactoryGirl::Syntax::Methods
@@ -1,4 +1,15 @@
1
- Synvert::Rewriter.new "convert_rails_dynamic_finders", "Convert rails dynamic finders" do
1
+ Synvert::Rewriter.new "convert_rails_dynamic_finders" do
2
+ description <<-EOF
3
+ It converts rails dynamic finders to arel syntax.
4
+
5
+ find_all_by_... => where(...)
6
+ find_by_... => where(...).first
7
+ find_last_by_... => where(...).last
8
+ scoped_by_... => where(...)
9
+ find_or_initialize_by_... => find_or_initialize_by(...)
10
+ find_or_create_by_... => find_or_create_by(...)
11
+ EOF
12
+
2
13
  helper_method 'dynamic_finder_to_hash' do |prefix|
3
14
  fields = node.message.to_s[prefix.length..-1].split("_and_")
4
15
  if fields.length == node.arguments.length && :hash != node.arguments.first.type
@@ -1,4 +1,25 @@
1
- Synvert::Rewriter.new "strong_parameters", "Use strong_parameters syntax" do
1
+ Synvert::Rewriter.new "strong_parameters" do
2
+ description <<-EOF
3
+ It uses string_parameters to replace attr_accessible.
4
+
5
+ 1. it removes active_record configurations.
6
+
7
+ config.active_record.whitelist_attributes = ...
8
+ config.active_record.mass_assignment_sanitizer = ...
9
+
10
+ 2. it removes attr_accessible code in models.
11
+
12
+ 3. it adds xxx_params in controllers
13
+
14
+ def xxx_params
15
+ params.require(:xxx).permit(...)
16
+ end
17
+
18
+ 4. it replaces params[:xxx] with xxx_params.
19
+
20
+ params[:xxx] => xxx_params
21
+ EOF
22
+
2
23
  within_files 'config/**/*.rb' do
3
24
  # remove config.active_record.whitelist_attributes = ...
4
25
  with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'active_record'}, message: 'whitelist_attributes=' do
@@ -1,4 +1,46 @@
1
- Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1', 'Upgrade rails from 3.0 to 3.1' do
1
+ Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1' do
2
+ description <<-EOF
3
+ It upgrade rails from 3.0 to 3.1.
4
+
5
+ 1. it enables asset pipeline.
6
+
7
+ config.assets.enabled = true
8
+ config.assets.version = '1.0'
9
+
10
+ 2. it removes config.action_view.debug_rjs in config/environments/development.rb
11
+
12
+ 3. it adds asset pipeline configs in config/environments/development.rb
13
+
14
+ # Do not compress assets
15
+ config.assets.compress = false
16
+
17
+ # Expands the lines which load the assets
18
+ config.assets.debug = true
19
+
20
+ 4. it adds asset pipeline configs in config/environments/production.rb
21
+
22
+ # Compress JavaScripts and CSS
23
+ config.assets.compress = true
24
+
25
+ # Don't fallback to assets pipeline if a precompiled asset is missed
26
+ config.assets.compile = false
27
+
28
+ # Generate digests for assets URLs
29
+ config.assets.digest = true
30
+
31
+ 5. it adds asset pipeline configs in config/environments/test.rb
32
+
33
+ # Configure static asset server for tests with Cache-Control for performance
34
+ config.serve_static_assets = true
35
+ config.static_cache_control = "public, max-age=3600"
36
+
37
+ 6. it creates config/environments/wrap_parameters.rb.
38
+
39
+ 7. it replaces session_store in config/initializers/session_store.rb
40
+
41
+ Application.session_store :cookie_store, key: '_xxx-session'
42
+ EOF
43
+
2
44
  if_gem 'rails', {gte: '3.0.0'}
3
45
 
4
46
  within_file 'config/application.rb' do
@@ -11,11 +53,6 @@ Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1', 'Upgrade rails from 3.0 to 3.1
11
53
  unless_exist_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'enabled=' do
12
54
  insert 'config.assets.enabled = true'
13
55
  end
14
-
15
- # config.assets.prefix = '/assets' => config.assets.prefix = '/asset-files'
16
- with_node type: 'send', receiver: {type: 'send', receiver: {type: 'send', message: 'config'}, message: 'assets'}, message: 'prefix=', arguments: ['/assets'] do
17
- replace_with "config.assets.prefix = '/asset-files'"
18
- end
19
56
  end
20
57
 
21
58
  within_file 'config/environments/development.rb' do
@@ -64,16 +101,20 @@ Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1', 'Upgrade rails from 3.0 to 3.1
64
101
  end
65
102
  end
66
103
 
67
- new_code = "ActiveSupport.on_load(:action_controller) do\n"
104
+ # add config/initializers/wrap_parameters.rb'
105
+ new_code = "# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.\n"
106
+ new_code << "ActiveSupport.on_load(:action_controller) do\n"
68
107
  new_code << " wrap_parameters format: [:json]\n"
69
108
  new_code << "end\n"
70
109
  new_code << "\n"
110
+ new_code << "# Disable root element in JSON by default.\n"
71
111
  new_code << "ActiveSupport.on_load(:active_record) do\n"
72
112
  new_code << " self.include_root_in_json = false\n"
73
113
  new_code << "end"
74
114
  add_file 'config/initializers/wrap_parameters.rb', new_code
75
115
 
76
116
  within_file 'config/initializers/session_store.rb' do
117
+ # add Application.session_store :cookie_store, key: '_xxx-session'
77
118
  with_node type: 'send', receiver: {type: 'send', message: 'config'}, message: 'session_store', arguments: {first: :cookie_store} do
78
119
  session_store_key = node.receiver.receiver.source(self).split(":").first.underscore
79
120
  replace_with "{{receiver}}.session_store :cookie_store, key: '_#{session_store_key}-session'"
@@ -1,4 +1,17 @@
1
- Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.1 to 3.2' do
1
+ Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2' do
2
+ description <<-EOF
3
+ It upgrades rails from 3.1 to 3.2.
4
+
5
+ 1. it insrts new configs in config/environments/development.rb.
6
+
7
+ config.active_record.mass_assignment_sanitizer = :strict
8
+ config.active_record.auto_explain_threshold_in_seconds = 0.5
9
+
10
+ 2. it insert new configs in config/environments/test.rb.
11
+
12
+ config.active_record.mass_assignment_sanitizer = :strict
13
+ EOF
14
+
2
15
  if_gem 'rails', {gte: '3.1.0'}
3
16
 
4
17
  within_file 'config/environments/development.rb' do
@@ -1,6 +1,76 @@
1
1
  require 'securerandom'
2
2
 
3
- Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0, it contains convert_dynamic_finder and strong_parameters snippets" do
3
+ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0" do
4
+ description <<-EOF
5
+ It upgrades rails from 3.2 to 4.0.
6
+
7
+ 1. it removes assets group in config/application.rb.
8
+
9
+ if defined?(Bundler)
10
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
11
+ end
12
+ => Bundler.require(:default, Rails.env)
13
+
14
+ 2. it removes config.active_record.identity_map = true from config files.
15
+
16
+ 3. it changes config.assets.compress = ... to config.assets.js_compressor = ...
17
+
18
+ 4. it removes include_root_in_json from config/initializers/secret_token.rb.
19
+
20
+ ActiveSupport.on_load(:active_record) do
21
+ self.include_root_in_json = false
22
+ end
23
+
24
+ 5. it inserts secret_key_base to config/initializers/session_store.rb.
25
+
26
+ Application.config.secret_key_base = '...'
27
+
28
+ 6. it removes config.action_dispatch.best_standards_support = ... from config files.
29
+
30
+ 7. it inserts config.eager_load = true in config/environments/production.rb.
31
+
32
+ 8. it inserts config.eager_load = false in config/environments/development.rb.
33
+
34
+ 9. it inserts config.eager_load = false in config/environments/test.rb.
35
+
36
+ 10. it removes any code using ActionDispatch::BestStandardsSupport in config files.
37
+
38
+ 11. it replaces ActionController::Base.page_cache_extension = ... with ActionController::Base.default_static_extension = ... in config files.
39
+
40
+ 12. it removes Rack::Utils.escape in config/routes.rb.
41
+
42
+ Rack::Utils.escape('こんにちは') => 'こんにちは'
43
+
44
+ 13. it replaces match in config/routes.rb.
45
+
46
+ match "/" => "root#index" => get "/" => "root#index"
47
+
48
+ 14. it removes rename_index in db migrations.
49
+
50
+ 15. it replaces instance method serialized_attributes with class method.
51
+
52
+ self.serialized_attributes => self.class.serialized_attributes
53
+
54
+ 16. it adds lambda for scope.
55
+
56
+ scope :active, where(active: true) => scope :active, -> { where(active: true) }
57
+
58
+ 17. it replaces ActiveRecord::Fixtures with ActiveRecord::FixtureSet.
59
+ replaces ActiveRecord::TestCase with ActiveSupport::TestCase.
60
+ replaces ActionController::Integration with ActionDispatch::Integration
61
+ replaces ActionController::IntegrationTest with ActionDispatch::IntegrationTest
62
+ replaces ActionController::PerformanceTest with ActionDispatch::PerformanceTest
63
+ replaces ActionController::AbstractRequest with ActionDispatch::Request
64
+ replaces ActionController::Request with ActionDispatch::Request
65
+ replaces ActionController::AbstractResponse with ActionDispatch::Response
66
+ replaces ActionController::Response with ActionDispatch::Response
67
+ replaces ActionController::Routing with ActionDispatch::Routing
68
+
69
+ 18. it calls another snippet convert_rails_dynamic_finder.
70
+
71
+ 19. it calls another snippet strong_parameters.
72
+ EOF
73
+
4
74
  if_gem 'rails', {gte: '3.2.0'}
5
75
 
6
76
  within_file 'config/application.rb' do
@@ -85,7 +155,7 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
85
155
  end
86
156
 
87
157
  within_files 'config/**/*.rb' do
88
- # remove ActionController::Base.page_cache_extension = ... => ActionController::Base.default_static_extension = ...
158
+ # ActionController::Base.page_cache_extension = ... => ActionController::Base.default_static_extension = ...
89
159
  with_node type: 'send', message: 'page_cache_extension=' do
90
160
  replace_with 'ActionController::Base.default_static_extension = {{arguments}}'
91
161
  end
@@ -128,22 +198,17 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
128
198
  end
129
199
  end
130
200
 
131
- within_files 'test/unit/**/*.rb' do
132
- # ActiveRecord::TestCase => ActiveSupport::TestCase
133
- with_node source: 'ActiveRecord::TestCase' do
134
- replace_with 'ActiveSupport::TestCase'
135
- end
136
- end
137
-
138
- {'ActionController::Integration' => 'ActionDispatch::Integration',
139
- 'ActionController::IntegrationTest' => 'ActionDispatch::IntegrationTest',
140
- 'ActionController::PerformanceTest' => 'ActionDispatch::PerformanceTest',
141
- 'ActionController::AbstractRequest' => 'ActionDispatch::Request',
142
- 'ActionController::Request' => 'ActionDispatch::Request',
143
- 'ActionController::AbstractResponse' => 'ActionDispatch::Response',
144
- 'ActionController::Response' => 'ActionDispatch::Response',
145
- 'ActionController::Routing' => 'ActionDispatch::Routing'}.each do |deprecated, favor|
146
- within_files '**/*.rb' do
201
+ within_files '**/*.rb' do
202
+ {'ActiveRecord::Fixtures' => 'ActiveRecord::FixtureSet',
203
+ 'ActiveRecord::TestCase' => 'ActiveSupport::TestCase',
204
+ 'ActionController::Integration' => 'ActionDispatch::Integration',
205
+ 'ActionController::IntegrationTest' => 'ActionDispatch::IntegrationTest',
206
+ 'ActionController::PerformanceTest' => 'ActionDispatch::PerformanceTest',
207
+ 'ActionController::AbstractRequest' => 'ActionDispatch::Request',
208
+ 'ActionController::Request' => 'ActionDispatch::Request',
209
+ 'ActionController::AbstractResponse' => 'ActionDispatch::Response',
210
+ 'ActionController::Response' => 'ActionDispatch::Response',
211
+ 'ActionController::Routing' => 'ActionDispatch::Routing'}.each do |deprecated, favor|
147
212
  with_node source: deprecated do
148
213
  replace_with favor
149
214
  end
@@ -154,6 +219,12 @@ Synvert::Rewriter.new "upgrade_rails_3_2_to_4_0", "Upgrade rails from 3.2 to 4.0
154
219
  add_snippet 'strong_parameters'
155
220
 
156
221
  todo <<-EOF
157
- Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.
222
+ 1. Rails 4.0 no longer supports loading plugins from vendor/plugins. You must replace any plugins by extracting them to gems and adding them to your Gemfile. If you choose not to make them gems, you can move them into, say, lib/my_plugin/* and add an appropriate initializer in config/initializers/my_plugin.rb.
223
+
224
+ 2. Make the following changes to your Gemfile.
225
+
226
+ gem 'sass-rails', '~> 4.0.0'
227
+ gem 'coffee-rails', '~> 4.0.0'
228
+ gem 'uglifier', '>= 1.3.0'
158
229
  EOF
159
230
  end
@@ -1,4 +1,10 @@
1
- Synvert::Rewriter.new "convert_rspec_be_close_to_be_within", "RSpec converts be_close to be_within" do
1
+ Synvert::Rewriter.new "convert_rspec_be_close_to_be_within" do
2
+ description <<-EOF
3
+ It converts rspec be_close matcher to be_within matcher.
4
+
5
+ expect(1.0 / 3.0).to be_close(0.333, 0.001) => expect(1.0 / 3.0).to be_within(0.001).of(0.333)
6
+ EOF
7
+
2
8
  if_gem 'rspec', {gte: '2.1.0'}
3
9
 
4
10
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,12 @@
1
- Synvert::Rewriter.new "convert_rspec_block_to_expect", "RSpec converts block to expect" do
1
+ Synvert::Rewriter.new "convert_rspec_block_to_expect" do
2
+ description <<-EOF
3
+ It converts rspec block to expect.
4
+
5
+ lambda { do_something }.should raise_error => expect { do_something }.to raise_error
6
+ proc { do_something }.should raise_error => expect { do_something }.to raise_error
7
+ -> { do_something }.should raise_error => expect { do_something }.to raise_error
8
+ EOF
9
+
2
10
  if_gem 'rspec', {gte: '2.11.0'}
3
11
 
4
12
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,11 @@
1
- Synvert::Rewriter.new "convert_rspec_boolean_matcher", "RSpec converts boolean matcher" do
1
+ Synvert::Rewriter.new "convert_rspec_boolean_matcher" do
2
+ description <<-EOF
3
+ It converts rspec boolean matcher.
4
+
5
+ be_true => be_truthy
6
+ be_false => be_falsey
7
+ EOF
8
+
2
9
  if_gem 'rspec', {gte: '2.99.0'}
3
10
 
4
11
  within_files 'spec/**/*_spec.rb' do
@@ -1,4 +1,15 @@
1
- Synvert::Rewriter.new "convert_rspec_collection_matcher", "RSpec converts collection matcher" do
1
+ Synvert::Rewriter.new "convert_rspec_collection_matcher" do
2
+ description <<-EOF
3
+ It converts rspec collection matcher.
4
+
5
+ expect(collection).to have(3).items => expect(collection.size).to eq(3)
6
+ expect(collection).to have_exactly(3).items => expect(collection.size).to eq(3)
7
+ expect(collection).to have_at_least(3).items => expect(collection.size).to be >= 3
8
+ expect(collection).to have_at_most(3).items => expect(collection.size).to be <= 3
9
+
10
+ expect(team).to have(3).players => expect(team.players.size).to eq 3
11
+ EOF
12
+
2
13
  if_gem 'rspec', {gte: '2.11.0'}
3
14
 
4
15
  within_files 'spec/**/*_spec.rb' do
@@ -1,4 +1,37 @@
1
- Synvert::Rewriter.new "convert_rspec_its_to_it", "RSpec converts its to it" do
1
+ Synvert::Rewriter.new "convert_rspec_its_to_it" do
2
+ description <<-EOF
3
+ It converts rspec its to it.
4
+
5
+ describe 'example' do
6
+ subject { { foo: 1, bar: 2 } }
7
+ its(:size) { should == 2 }
8
+ its([:foo]) { should == 1 }
9
+ its('keys.first') { should == :foo }
10
+ end
11
+ =>
12
+ describe 'example' do
13
+ subject { { foo: 1, bar: 2 } }
14
+
15
+ describe '#size' do
16
+ subject { super().size }
17
+ it { should == 2 }
18
+ end
19
+
20
+ describe '[:foo]' do
21
+ subject { super()[:foo] }
22
+ it { should == 1 }
23
+ end
24
+
25
+ describe '#keys' do
26
+ subject { super().keys }
27
+ describe '#first' do
28
+ subject { super().first }
29
+ it { should == :foo }
30
+ end
31
+ end
32
+ end
33
+ EOF
34
+
2
35
  if_gem 'rspec', {gte: '2.99.0'}
3
36
 
4
37
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,17 @@
1
- Synvert::Rewriter.new "convert_rspec_message_expectation", "RSpec converts message expectation" do
1
+ Synvert::Rewriter.new "convert_rspec_message_expectation" do
2
+ description <<-EOF
3
+ It convert rspec message expectation.
4
+
5
+ obj.should_receive(:message) => expect(obj).to receive(:message)
6
+ Klass.any_instance.should_receive(:message) => expect_any_instance_of(Klass).to receive(:message)
7
+
8
+ expect(obj).to receive(:message).and_return { 1 } => expect(obj).to receive(:message) { 1 }
9
+
10
+ expect(obj).to receive(:message).and_return { 1 } => expect(obj).to receive(:message) { 1 }
11
+
12
+ expect(obj).to receive(:message).and_return => expect(obj).to receive(:message)
13
+ EOF
14
+
2
15
  if_gem 'rspec', {gte: '2.14.0'}
3
16
 
4
17
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,25 @@
1
- Synvert::Rewriter.new "convert_rspec_method_stub", "RSpec converts method stub" do
1
+ Synvert::Rewriter.new "convert_rspec_method_stub" do
2
+ description <<-EOF
3
+ It converts rspec method stub.
4
+
5
+ obj.stub!(:message) => obj.stub(:message)
6
+ obj.unstub!(:message) => obj.unstub(:message)
7
+
8
+ obj.stub(:message).any_number_of_times => allow(obj).to receive(:message)
9
+ obj.stub(:message).at_least(0) => allow(obj).to receive(:message)
10
+
11
+ obj.stub(:message) => allow(obj).to receive(:message)
12
+ Klass.any_instance.stub(:message) => allow_any_instance_of(Klass).to receive(:message)
13
+
14
+ obj.stub_chain(:foo, :bar, :baz) => allow(obj).to receive_message_chain(:foo, :bar, :baz)
15
+
16
+ obj.stub(:foo => 1, :bar => 2) => allow(obj).to receive_messages(:foo => 1, :bar => 2)
17
+
18
+ allow(obj).to receive(:message).and_return { 1 } => allow(obj).to receive(:message) { 1 }
19
+
20
+ allow(obj).to receive(:message).and_return => allow(obj).to receive(:message)
21
+ EOF
22
+
2
23
  if_gem 'rspec', {gte: '2.14.0'}
3
24
 
4
25
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,11 @@
1
- Synvert::Rewriter.new "convert_rspec_negative_error_expectation", "RSpec converts negative error expectation" do
1
+ Synvert::Rewriter.new "convert_rspec_negative_error_expectation" do
2
+ description <<-EOF
3
+ It converts rspec negative error expectation.
4
+
5
+ expect { do_something }.not_to raise_error(SomeErrorClass) => expect { do_something }.not_to raise_error
6
+ expect { do_something }.not_to raise_error('message') => expect { do_something }.not_to raise_error
7
+ expect { do_something }.not_to raise_error(SomeErrorClass, 'message') => expect { do_something }.not_to raise_error
8
+ EOF
2
9
  if_gem 'rspec', {gte: '2.14.0'}
3
10
 
4
11
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,8 @@
1
- Synvert::Rewriter.new "rspec_new_syntax", "Use RSpec new syntax, it contains all convert_rspec_* snippets" do
1
+ Synvert::Rewriter.new "rspec_new_syntax" do
2
+ description <<-EOF
3
+ It converts rspec code to new syntax, it calls all convert_rspec_* snippets.
4
+ EOF
5
+
2
6
  add_snippet "convert_rspec_should_to_expect"
3
7
  add_snippet "convert_rspec_block_to_expect"
4
8
  add_snippet "convert_rspec_one_liner_expectation"
@@ -1,4 +1,23 @@
1
- Synvert::Rewriter.new "convert_rspec_one_liner_expectation", "RSpec converts one liner expectation" do
1
+ Synvert::Rewriter.new "convert_rspec_one_liner_expectation" do
2
+ description <<-EOF
3
+ It convers rspec one liner expectation.
4
+
5
+ it { should matcher } => it { is_expected.to matcher }
6
+ it { should_not matcher } => it { is_expected.not_to matcher }
7
+
8
+ it { should have(3).items }
9
+ =>
10
+ it 'has 3 items' do
11
+ expect(subject.size).to eq(3)
12
+ end
13
+
14
+ it { should have_at_least(3).players }
15
+ =>
16
+ it 'has at least 3 players' do
17
+ expect(subject.players.size).to be >= 3
18
+ end
19
+ EOF
20
+
2
21
  if_gem 'rspec', {gte: '2.99.0'}
3
22
 
4
23
  matcher_converters = {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}
@@ -1,4 +1,18 @@
1
- Synvert::Rewriter.new "convert_rspec_should_to_expect", "RSpec converts should to expect" do
1
+ Synvert::Rewriter.new "convert_rspec_should_to_expect" do
2
+ description <<-EOF
3
+ It converts rspec should to expect.
4
+
5
+ obj.should matcher => expect(obj).to matcher
6
+ obj.should_not matcher => expect(obj).not_to matcher
7
+
8
+ 1.should == 1 => expect(1).to eq 1
9
+ 1.should < 1 => expect(1).to be < 2
10
+ Integer.should === 1 => expect(Integer).to be === 1
11
+
12
+ 'string'.should =~ /^str/ => expect('string').to match /^str/
13
+ [1, 2, 3].should =~ [2, 1, 3] => expect([1, 2, 3]).to match_array [2, 1, 3]
14
+ EOF
15
+
2
16
  if_gem 'rspec', {gte: '2.11.0'}
3
17
 
4
18
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,11 @@
1
- Synvert::Rewriter.new "convert_rspec_stub_and_mock_to_double", "RSpec converts stub and mock to double" do
1
+ Synvert::Rewriter.new "convert_rspec_stub_and_mock_to_double" do
2
+ description <<-EOF
3
+ It converts stub and mock to double.
4
+
5
+ stub('something') => double('something')
6
+ mock('something') => double('something')
7
+ EOF
8
+
2
9
  if_gem 'rspec', {gte: '2.14.0'}
3
10
 
4
11
  within_files 'spec/**/*.rb' do
@@ -1,4 +1,10 @@
1
- Synvert::Rewriter.new "ruby_new_hash_syntax", "Ruby uses new hash syntax" do
1
+ Synvert::Rewriter.new "ruby_new_hash_syntax" do
2
+ description <<-EOF
3
+ Use ruby new hash syntax.
4
+
5
+ {:foo => 'bar'} => {foo: 'bar'}
6
+ EOF
7
+
2
8
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
3
9
  within_files '**/*.rb' do
4
10
  # {:foo => 'bar'} => {foo: 'bar'}
@@ -1,4 +1,10 @@
1
- Synvert::Rewriter.new "ruby_new_lambda_syntax", "Ruby uses new lambda syntax" do
1
+ Synvert::Rewriter.new "ruby_new_lambda_syntax" do
2
+ description <<-EOF
3
+ Use ruby new lambda syntax
4
+
5
+ lambda { # do some thing } => -> { # do some thing }
6
+ EOF
7
+
2
8
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("1.9.0")
3
9
  within_files '**/*.rb' do
4
10
  # lambda { |a, b, c| a + b + c } => ->(a, b, c) { a + b + c }
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.0.13"
4
+ VERSION = "0.0.14"
5
5
  end
data/lib/synvert.rb CHANGED
@@ -11,5 +11,6 @@ module Synvert
11
11
  autoload :CheckingVisitor, 'synvert/checking_visitor'
12
12
  autoload :Configuration, 'synvert/configuration'
13
13
  autoload :Rewriter, 'synvert/rewriter'
14
- autoload :RewriterNotFound, 'synvert/rewriter_not_found'
14
+ autoload :RewriterNotFound, 'synvert/exceptions'
15
+ autoload :GemfileLockNotFound, 'synvert/exceptions'
15
16
  end
@@ -43,10 +43,10 @@ GEM
43
43
  expect(gem_spec).not_to be_match
44
44
  end
45
45
 
46
- it 'raise LoadError if Gemfile.lock does not exist' do
46
+ it 'raise Synvert::GemfileLockNotFound if Gemfile.lock does not exist' do
47
47
  expect(File).to receive(:exists?).with('./Gemfile.lock').and_return(false)
48
48
  gem_spec = Rewriter::GemSpec.new('ast', '1.1.0')
49
- expect { gem_spec.match? }.to raise_error(LoadError)
49
+ expect { gem_spec.match? }.to raise_error(Synvert::GemfileLockNotFound)
50
50
  end
51
51
  end
52
52
  end