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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/synvert/rewriter/gem_spec.rb +10 -3
- data/lib/synvert/rewriter.rb +2 -2
- data/lib/synvert/snippets/factory_girl/syntax_methods.rb +1 -1
- data/lib/synvert/snippets/rails/upgrade_3_0_to_3_1.rb +1 -1
- data/lib/synvert/snippets/rails/upgrade_3_1_to_3_2.rb +1 -1
- data/lib/synvert/snippets/rails/upgrade_3_2_to_4_0.rb +1 -1
- data/lib/synvert/snippets/rspec/be_close_to_be_within.rb +1 -1
- data/lib/synvert/snippets/rspec/block_to_expect.rb +1 -1
- data/lib/synvert/snippets/rspec/boolean_matcher.rb +1 -1
- data/lib/synvert/snippets/rspec/collection_matcher.rb +1 -1
- data/lib/synvert/snippets/rspec/its_to_it.rb +1 -1
- data/lib/synvert/snippets/rspec/message_expectation.rb +1 -1
- data/lib/synvert/snippets/rspec/method_stub.rb +2 -2
- data/lib/synvert/snippets/rspec/negative_error_expectation.rb +1 -1
- data/lib/synvert/snippets/rspec/new_syntax.rb +1 -1
- data/lib/synvert/snippets/rspec/one_liner_expectation.rb +1 -1
- data/lib/synvert/snippets/rspec/should_to_expect.rb +1 -1
- data/lib/synvert/snippets/rspec/stub_and_mock_to_double.rb +1 -1
- data/lib/synvert/version.rb +1 -1
- data/spec/synvert/rewriter/gem_spec_spec.rb +2 -2
- data/spec/synvert/rewriter_spec.rb +7 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8950014c1ee881965625f25681c35b66b28234da
|
4
|
+
data.tar.gz: 5abd928e4478a5830a35488884cfcb6c85325d3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62e2fc5bb3639aea6a190feba903f7566ef30d5150ad13d7731aa4952e15de676bc83ff6ab9aa5119b4e12b2122019b6e941a4f03bdb1718994cd034e1e84aab
|
7
|
+
data.tar.gz: 89fa91f3f7c0275c85ba29942b5211ede25ba0576a0c89b0978930f372c464ad215f4e20a8ec4749abcc102c4d2fa9c35c9c2ce6596c1dd11481f6aac510bd39
|
data/CHANGELOG.md
CHANGED
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
|
-
|
5
|
+
OPERATORS = {eq: '==', lt: '<', gt: '>', lte: '<=', gte: '>=', ne: '!='}
|
6
|
+
def initialize(name, comparator)
|
6
7
|
@name = name
|
7
|
-
|
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)
|
22
|
+
Gem::Version.new(spec.version).send(OPERATORS[@operator], @version)
|
16
23
|
else
|
17
24
|
false
|
18
25
|
end
|
data/lib/synvert/rewriter.rb
CHANGED
@@ -56,8 +56,8 @@ module Synvert
|
|
56
56
|
self.instance_eval &@block
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
@gem_spec = Rewriter::GemSpec.new(name,
|
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 'upgrade_rails_3_1_to_3_2', 'Upgrade rails from 3.1 to 3.2' do
|
2
|
-
|
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
|
-
|
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
|
-
|
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_boolean_matcher", "RSpec converts boolean matcher" do
|
2
|
-
|
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
|
-
|
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_method_stub", "RSpec converts method stub" do
|
2
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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 <='}
|
data/lib/synvert/version.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
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
|
-
|
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
|
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
|
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
|
-
|
36
|
+
if_gem 'synvert', '1.0.0'
|
37
37
|
within_file 'config/routes.rb' do; end
|
38
38
|
end
|
39
39
|
rewriter.process
|