synvert 0.0.10 → 0.0.11

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: 614d00dc632a03aa4e33b46e9abd3632e3cd1192
4
- data.tar.gz: cda16861b6998679c265db36fa32c094ca391417
3
+ metadata.gz: 8950014c1ee881965625f25681c35b66b28234da
4
+ data.tar.gz: 5abd928e4478a5830a35488884cfcb6c85325d3d
5
5
  SHA512:
6
- metadata.gz: dc0094150dfdc672a9f4cbe95ba484cedf065d778a988b60790c2a417748b1e7b07c50e74df7fe3b44835f32313c4ac7708e0928b5cac4db41f5fd9ad59c8f24
7
- data.tar.gz: 2531c8a731dcfcf741634f23450abd0415b630197c64845958a3f81dd3f7d7b43b3d07ef706c31c1bf7d650beb04e9b4c7c768ad05fdb22694212f1fe90ed781
6
+ metadata.gz: 62e2fc5bb3639aea6a190feba903f7566ef30d5150ad13d7731aa4952e15de676bc83ff6ab9aa5119b4e12b2122019b6e941a4f03bdb1718994cd034e1e84aab
7
+ data.tar.gz: 89fa91f3f7c0275c85ba29942b5211ede25ba0576a0c89b0978930f372c464ad215f4e20a8ec4749abcc102c4d2fa9c35c9c2ce6596c1dd11481f6aac510bd39
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.11
4
+
5
+ * Rename gem_spec to if_gem dsl
6
+
3
7
  ## 0.0.10
4
8
 
5
9
  * Add not ast node operator
data/README.md CHANGED
@@ -56,7 +56,7 @@ convert_rspec_its_to_it | RSpec converts its to it
56
56
  convert_rspec_message_expectation | RSpec converts message expectation
57
57
  convert_rspec_method_stub | RSpec converts method stub
58
58
  convert_rspec_negative_error_expectation | RSpec converts negative error expectation
59
- rspec_new_syntax | Use RSpec new syntax
59
+ rspec_new_syntax | Use RSpec new syntax, it contains all convert_rspec_* snippets
60
60
  convert_rspec_one_liner_expectation | RSpec converts one liner expectation
61
61
  convert_rspec_should_to_expect | RSpec converts should to expect
62
62
  convert_rspec_stub_and_mock_to_double | RSpec converts stub and mock to double
@@ -2,9 +2,16 @@
2
2
 
3
3
  module Synvert
4
4
  class Rewriter::GemSpec
5
- def initialize(name, version)
5
+ OPERATORS = {eq: '==', lt: '<', gt: '>', lte: '<=', gte: '>=', ne: '!='}
6
+ def initialize(name, comparator)
6
7
  @name = name
7
- @version = Gem::Version.new version
8
+ if Hash === comparator
9
+ @operator = comparator.keys.first
10
+ @version = Gem::Version.new comparator.values.first
11
+ else
12
+ @operator = :eq
13
+ @version = Gem::Version.new comparator
14
+ end
8
15
  end
9
16
 
10
17
  def match?
@@ -12,7 +19,7 @@ module Synvert
12
19
  if File.exists? gemfile_lock_path
13
20
  parser = Bundler::LockfileParser.new(File.read(gemfile_lock_path))
14
21
  if spec = parser.specs.find { |spec| spec.name == @name }
15
- Gem::Version.new(spec.version) >= @version
22
+ Gem::Version.new(spec.version).send(OPERATORS[@operator], @version)
16
23
  else
17
24
  false
18
25
  end
@@ -56,8 +56,8 @@ module Synvert
56
56
  self.instance_eval &@block
57
57
  end
58
58
 
59
- def gem_spec(name, version)
60
- @gem_spec = Rewriter::GemSpec.new(name, version)
59
+ def if_gem(name, comparator)
60
+ @gem_spec = Rewriter::GemSpec.new(name, comparator)
61
61
  end
62
62
 
63
63
  def within_file(file_pattern, &block)
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "factory_girl_short_syntax", "FactoryGirl uses short syntax" do
2
- gem_spec 'factory_girl', '2.0.0'
2
+ if_gem 'factory_girl', {gte: '2.0.0'}
3
3
 
4
4
  # insert include FactoryGirl::Syntax::Methods
5
5
  within_file 'spec/spec_helper.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new 'upgrade_rails_3_0_to_3_1', 'Upgrade rails from 3.0 to 3.1' do
2
- gem_spec 'rails', '3.0.0'
2
+ if_gem 'rails', {gte: '3.0.0'}
3
3
 
4
4
  within_file 'config/application.rb' do
5
5
  # insert config.assets.version = '1.0'
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.1 to 3.2' do
2
- gem_spec 'rails', '3.1.0'
2
+ if_gem 'rails', {gte: '3.1.0'}
3
3
 
4
4
  within_file 'config/environments/development.rb' do
5
5
  # insert config.active_record.auto_explain_threshold_in_seconds = 0.5
@@ -1,7 +1,7 @@
1
1
  require 'securerandom'
2
2
 
3
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
4
- gem_spec 'rails', '3.2.0'
4
+ if_gem 'rails', {gte: '3.2.0'}
5
5
 
6
6
  within_file 'config/application.rb' do
7
7
  # if defined?(Bundler)
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_be_close_to_be_within", "RSpec converts be_close to be_within" do
2
- gem_spec 'rspec', '2.1.0'
2
+ if_gem 'rspec', {gte: '2.1.0'}
3
3
 
4
4
  within_files 'spec/**/*.rb' do
5
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)
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_block_to_expect", "RSpec converts block to expect" do
2
- gem_spec 'rspec', '2.11.0'
2
+ if_gem 'rspec', {gte: '2.11.0'}
3
3
 
4
4
  {should: 'to', should_not: 'not_to'}.each do |old_message, new_message|
5
5
  within_files 'spec/**/*.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_boolean_matcher", "RSpec converts boolean matcher" do
2
- gem_spec 'rspec', '2.99.0'
2
+ if_gem 'rspec', {gte: '2.99.0'}
3
3
 
4
4
  {be_true: 'be_truthy', be_false: 'be_falsey'}.each do |old_matcher, new_matcher|
5
5
  within_files 'spec/**/*_spec.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_collection_matcher", "RSpec converts collection matcher" do
2
- gem_spec 'rspec', '2.99.0'
2
+ if_gem 'rspec', {gte: '2.11.0'}
3
3
 
4
4
  {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}.each do |old_matcher, new_matcher|
5
5
  within_files 'spec/**/*_spec.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_its_to_it", "RSpec converts its to it" do
2
- gem_spec 'rspec', '2.99.0'
2
+ if_gem 'rspec', {gte: '2.99.0'}
3
3
 
4
4
  [:should, :should_not].each do |message|
5
5
  within_files 'spec/**/*.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_message_expectation", "RSpec converts message expectation" do
2
- gem_spec 'rspec', '2.14.0'
2
+ if_gem 'rspec', {gte: '2.14.0'}
3
3
 
4
4
  within_files 'spec/**/*.rb' do
5
5
  # obj.should_receive(:message) => expect(obj).to receive(:message)
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_method_stub", "RSpec converts method stub" do
2
- gem_spec 'rspec', '2.14.0'
2
+ if_gem 'rspec', {gte: '2.14.0'}
3
3
 
4
4
  within_files 'spec/**/*.rb' do
5
5
  # obj.stub!(:message) => obj.stub(:message)
@@ -36,7 +36,7 @@ Synvert::Rewriter.new "convert_rspec_method_stub", "RSpec converts method stub"
36
36
  end
37
37
  end
38
38
 
39
- gem_spec 'rspec', '3.0.0'
39
+ if_gem 'rspec', {gte: '3.0.0'}
40
40
 
41
41
  within_files 'spec/**/*.rb' do
42
42
  # obj.stub_chain(:foo, :bar, :baz) => allow(obj).to receive_message_chain(:foo, :bar, :baz)
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_negative_error_expectation", "RSpec converts negative error expectation" do
2
- gem_spec 'rspec', '2.14.0'
2
+ if_gem 'rspec', {gte: '2.14.0'}
3
3
 
4
4
  within_files 'spec/**/*.rb' do
5
5
  # expect { do_something }.not_to raise_error(SomeErrorClass) => expect { do_something }.not_to raise_error
@@ -1,4 +1,4 @@
1
- Synvert::Rewriter.new "rspec_new_syntax", "Use RSpec new syntax" do
1
+ Synvert::Rewriter.new "rspec_new_syntax", "Use RSpec new syntax, it contains all convert_rspec_* snippets" do
2
2
  add_snippet "convert_rspec_should_to_expect"
3
3
  add_snippet "convert_rspec_block_to_expect"
4
4
  add_snippet "convert_rspec_one_liner_expectation"
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_one_liner_expectation", "RSpec converts one liner expectation" do
2
- gem_spec 'rspec', '2.99.0'
2
+ if_gem 'rspec', {gte: '2.99.0'}
3
3
 
4
4
  {should: 'to', should_not: 'not_to'}.each do |old_message, new_message|
5
5
  matcher_converters = {have: 'eq', have_exactly: 'eq', have_at_least: 'be >=', have_at_most: 'be <='}
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_should_to_expect", "RSpec converts should to expect" do
2
- gem_spec 'rspec', '2.11.0'
2
+ if_gem 'rspec', {gte: '2.11.0'}
3
3
 
4
4
  {should: 'to', should_not: 'not_to'}.each do |old_message, new_message|
5
5
  within_files 'spec/**/*.rb' do
@@ -1,5 +1,5 @@
1
1
  Synvert::Rewriter.new "convert_rspec_stub_and_mock_to_double", "RSpec converts stub and mock to double" do
2
- gem_spec 'rspec', '2.14.0'
2
+ if_gem 'rspec', {gte: '2.14.0'}
3
3
 
4
4
  within_files 'spec/**/*.rb' do
5
5
  # stub('something') => double('something')
@@ -1,5 +1,5 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Synvert
4
- VERSION = "0.0.10"
4
+ VERSION = "0.0.11"
5
5
  end
@@ -18,7 +18,7 @@ GEM
18
18
  it 'returns true if version in Gemfile.lock is greater than definition' do
19
19
  expect(File).to receive(:exists?).with('./Gemfile.lock').and_return(true)
20
20
  expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
21
- gem_spec = Rewriter::GemSpec.new('ast', '1.0.0')
21
+ gem_spec = Rewriter::GemSpec.new('ast', {gte: '1.0.0'})
22
22
  expect(gem_spec).to be_match
23
23
  end
24
24
 
@@ -32,7 +32,7 @@ GEM
32
32
  it 'returns false if version in Gemfile.lock is less than definition' do
33
33
  expect(File).to receive(:exists?).with('./Gemfile.lock').and_return(true)
34
34
  expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
35
- gem_spec = Rewriter::GemSpec.new('ast', '1.2.0')
35
+ gem_spec = Rewriter::GemSpec.new('ast', {lt: '1.2.0'})
36
36
  expect(gem_spec).not_to be_match
37
37
  end
38
38
 
@@ -2,26 +2,26 @@ require 'spec_helper'
2
2
 
3
3
  module Synvert
4
4
  describe Rewriter do
5
- it 'parses gem_spec' do
5
+ it 'parses if_gem' do
6
6
  expect(Rewriter::GemSpec).to receive(:new).with('synvert', '1.0.0')
7
7
  rewriter = Rewriter.new 'name', 'description' do
8
- gem_spec 'synvert', '1.0.0'
8
+ if_gem 'synvert', '1.0.0'
9
9
  end
10
10
  rewriter.process
11
11
  end
12
12
 
13
13
  describe 'parses within_file' do
14
- it 'does nothing if gem_spec not match' do
14
+ it 'does nothing if if_gem not match' do
15
15
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(false)
16
16
  expect_any_instance_of(Rewriter::Instance).not_to receive(:process)
17
17
  rewriter = Rewriter.new 'name', 'description' do
18
- gem_spec 'synvert', '1.0.0'
18
+ if_gem 'synvert', '1.0.0'
19
19
  within_file 'config/routes.rb' do; end
20
20
  end
21
21
  rewriter.process
22
22
  end
23
23
 
24
- it 'delegates process to instances if gem_spec not exist' do
24
+ it 'delegates process to instances if if_gem not exist' do
25
25
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
26
26
  rewriter = Rewriter.new 'name', 'description' do
27
27
  within_file 'config/routes.rb' do; end
@@ -29,11 +29,11 @@ module Synvert
29
29
  rewriter.process
30
30
  end
31
31
 
32
- it 'delegates process to instances if gem_spec matches' do
32
+ it 'delegates process to instances if if_gem matches' do
33
33
  expect_any_instance_of(Rewriter::GemSpec).to receive(:match?).and_return(true)
34
34
  expect_any_instance_of(Rewriter::Instance).to receive(:process)
35
35
  rewriter = Rewriter.new 'name', 'description' do
36
- gem_spec 'synvert', '1.0.0'
36
+ if_gem 'synvert', '1.0.0'
37
37
  within_file 'config/routes.rb' do; end
38
38
  end
39
39
  rewriter.process
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synvert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Huang