synvert-core 0.15.2 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/Gemfile +2 -0
- data/Guardfile +2 -0
- data/Rakefile +2 -0
- data/lib/synvert/core.rb +2 -3
- data/lib/synvert/core/configuration.rb +10 -17
- data/lib/synvert/core/engine.rb +1 -1
- data/lib/synvert/core/engine/erb.rb +31 -23
- data/lib/synvert/core/exceptions.rb +5 -3
- data/lib/synvert/core/node_ext.rb +107 -101
- data/lib/synvert/core/rewriter.rb +22 -16
- data/lib/synvert/core/rewriter/action.rb +4 -6
- data/lib/synvert/core/rewriter/action/append_action.rb +3 -3
- data/lib/synvert/core/rewriter/action/insert_action.rb +9 -5
- data/lib/synvert/core/rewriter/action/insert_after_action.rb +2 -2
- data/lib/synvert/core/rewriter/action/remove_action.rb +2 -2
- data/lib/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action.rb +5 -4
- data/lib/synvert/core/rewriter/action/replace_with_action.rb +7 -5
- data/lib/synvert/core/rewriter/condition.rb +1 -1
- data/lib/synvert/core/rewriter/condition/if_exist_condition.rb +2 -2
- data/lib/synvert/core/rewriter/condition/if_only_exist_condition.rb +2 -3
- data/lib/synvert/core/rewriter/condition/unless_exist_condition.rb +2 -2
- data/lib/synvert/core/rewriter/gem_spec.rb +11 -11
- data/lib/synvert/core/rewriter/helper.rb +4 -6
- data/lib/synvert/core/rewriter/instance.rb +37 -23
- data/lib/synvert/core/rewriter/ruby_version.rb +1 -1
- data/lib/synvert/core/rewriter/scope.rb +1 -1
- data/lib/synvert/core/rewriter/scope/goto_scope.rb +2 -1
- data/lib/synvert/core/rewriter/scope/within_scope.rb +23 -7
- data/lib/synvert/core/rewriter/warning.rb +1 -1
- data/lib/synvert/core/version.rb +2 -2
- data/spec/spec_helper.rb +3 -6
- data/spec/support/parser_helper.rb +2 -0
- data/spec/synvert/core/engine/erb_spec.rb +32 -30
- data/spec/synvert/core/node_ext_spec.rb +57 -54
- data/spec/synvert/core/rewriter/action/append_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/insert_action_spec.rb +10 -8
- data/spec/synvert/core/rewriter/action/insert_after_action_spec.rb +5 -3
- data/spec/synvert/core/rewriter/action/remove_action_spec.rb +3 -1
- data/spec/synvert/core/rewriter/action/replace_erb_stmt_with_expr_action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/action/replace_with_action_spec.rb +17 -11
- data/spec/synvert/core/rewriter/action_spec.rb +2 -0
- data/spec/synvert/core/rewriter/condition/if_exist_condition_spec.rb +19 -9
- data/spec/synvert/core/rewriter/condition/if_only_exist_condition_spec.rb +23 -12
- data/spec/synvert/core/rewriter/condition/unless_exist_condition_spec.rb +19 -9
- data/spec/synvert/core/rewriter/condition_spec.rb +2 -0
- data/spec/synvert/core/rewriter/gem_spec_spec.rb +13 -10
- data/spec/synvert/core/rewriter/helper_spec.rb +36 -31
- data/spec/synvert/core/rewriter/instance_spec.rb +118 -66
- data/spec/synvert/core/rewriter/scope/goto_scope_spec.rb +10 -6
- data/spec/synvert/core/rewriter/scope/within_scope.rb +18 -9
- data/spec/synvert/core/rewriter/scope_spec.rb +2 -0
- data/spec/synvert/core/rewriter/warning_spec.rb +2 -0
- data/spec/synvert/core/rewriter_spec.rb +106 -73
- metadata +2 -4
- data/spec/synvert/core/configuration_spec.rb +0 -10
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
@@ -11,11 +13,11 @@ module Synvert::Core
|
|
11
13
|
}
|
12
14
|
|
13
15
|
it 'gets begin_pos' do
|
14
|
-
expect(subject.begin_pos).to eq
|
16
|
+
expect(subject.begin_pos).to eq 'Synvert::Application.configure do'.length
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'gets end_pos' do
|
18
|
-
expect(subject.end_pos).to eq
|
20
|
+
expect(subject.end_pos).to eq 'Synvert::Application.configure do'.length
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'gets rewritten_code' do
|
@@ -32,11 +34,11 @@ module Synvert::Core
|
|
32
34
|
}
|
33
35
|
|
34
36
|
it 'gets begin_pos' do
|
35
|
-
expect(subject.begin_pos).to eq
|
37
|
+
expect(subject.begin_pos).to eq 'RSpec.configure do |config|'.length
|
36
38
|
end
|
37
39
|
|
38
40
|
it 'gets end_pos' do
|
39
|
-
expect(subject.end_pos).to eq
|
41
|
+
expect(subject.end_pos).to eq 'RSpec.configure do |config|'.length
|
40
42
|
end
|
41
43
|
|
42
44
|
it 'gets rewritten_code' do
|
@@ -53,11 +55,11 @@ module Synvert::Core
|
|
53
55
|
}
|
54
56
|
|
55
57
|
it 'gets begin_pos' do
|
56
|
-
expect(subject.begin_pos).to eq
|
58
|
+
expect(subject.begin_pos).to eq 'class User'.length
|
57
59
|
end
|
58
60
|
|
59
61
|
it 'gets end_pos' do
|
60
|
-
expect(subject.end_pos).to eq
|
62
|
+
expect(subject.end_pos).to eq 'class User'.length
|
61
63
|
end
|
62
64
|
|
63
65
|
it 'gets rewritten_code' do
|
@@ -74,11 +76,11 @@ module Synvert::Core
|
|
74
76
|
}
|
75
77
|
|
76
78
|
it 'gets begin_pos' do
|
77
|
-
expect(subject.begin_pos).to eq
|
79
|
+
expect(subject.begin_pos).to eq 'class User < ActionRecord::Base'.length
|
78
80
|
end
|
79
81
|
|
80
82
|
it 'gets end_pos' do
|
81
|
-
expect(subject.end_pos).to eq
|
83
|
+
expect(subject.end_pos).to eq 'class User < ActionRecord::Base'.length
|
82
84
|
end
|
83
85
|
|
84
86
|
it 'gets rewritten_code' do
|
@@ -1,20 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::InsertAfterAction do
|
5
7
|
subject {
|
6
|
-
source =
|
8
|
+
source = ' include Foo'
|
7
9
|
node = Parser::CurrentRuby.parse(source)
|
8
10
|
instance = double(current_node: node)
|
9
11
|
Rewriter::InsertAfterAction.new(instance, 'include Bar')
|
10
12
|
}
|
11
13
|
|
12
14
|
it 'gets begin_pos' do
|
13
|
-
expect(subject.begin_pos).to eq
|
15
|
+
expect(subject.begin_pos).to eq ' include Foo'.length
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'gets end_pos' do
|
17
|
-
expect(subject.end_pos).to eq
|
19
|
+
expect(subject.end_pos).to eq ' include Foo'.length
|
18
20
|
end
|
19
21
|
|
20
22
|
it 'gets rewritten_code' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
@@ -18,7 +20,7 @@ module Synvert::Core
|
|
18
20
|
end
|
19
21
|
|
20
22
|
it 'gets rewritten_code' do
|
21
|
-
expect(subject.rewritten_code).to eq
|
23
|
+
expect(subject.rewritten_code).to eq ''
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
@@ -1,21 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::ReplaceWithAction do
|
5
|
-
context
|
7
|
+
context 'replace with single line' do
|
6
8
|
subject {
|
7
|
-
source =
|
9
|
+
source = 'post = FactoryGirl.create_list :post, 2'
|
8
10
|
send_node = Parser::CurrentRuby.parse(source).children[1]
|
9
11
|
instance = double(current_node: send_node)
|
10
12
|
Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}')
|
11
13
|
}
|
12
14
|
|
13
15
|
it 'gets begin_pos' do
|
14
|
-
expect(subject.begin_pos).to eq
|
16
|
+
expect(subject.begin_pos).to eq 'post = '.length
|
15
17
|
end
|
16
18
|
|
17
19
|
it 'gets end_pos' do
|
18
|
-
expect(subject.end_pos).to eq
|
20
|
+
expect(subject.end_pos).to eq 'post = FactoryGirl.create_list :post, 2'.length
|
19
21
|
end
|
20
22
|
|
21
23
|
it 'gets rewritten_code' do
|
@@ -23,15 +25,19 @@ module Synvert::Core
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
context
|
28
|
+
context '#replace with multiple line' do
|
27
29
|
subject {
|
28
|
-
source =
|
30
|
+
source = ' its(:size) { should == 1 }'
|
29
31
|
send_node = Parser::CurrentRuby.parse(source)
|
30
32
|
instance = double(current_node: send_node)
|
31
|
-
Rewriter::ReplaceWithAction.new(
|
33
|
+
Rewriter::ReplaceWithAction.new(
|
34
|
+
instance,
|
35
|
+
"describe '#size' do
|
32
36
|
subject { super().size }
|
33
37
|
it { {{body}} }
|
34
|
-
end"
|
38
|
+
end",
|
39
|
+
autoindent: false
|
40
|
+
)
|
35
41
|
}
|
36
42
|
|
37
43
|
it 'gets begin_pos' do
|
@@ -39,14 +45,14 @@ end""", autoindent: false)
|
|
39
45
|
end
|
40
46
|
|
41
47
|
it 'gets end_pos' do
|
42
|
-
expect(subject.end_pos).to eq
|
48
|
+
expect(subject.end_pos).to eq ' its(:size) { should == 1 }'.length
|
43
49
|
end
|
44
50
|
|
45
51
|
it 'gets rewritten_code' do
|
46
|
-
expect(subject.rewritten_code).to eq "
|
52
|
+
expect(subject.rewritten_code).to eq "describe '#size' do
|
47
53
|
subject { super().size }
|
48
54
|
it { should == 1 }
|
49
|
-
end"
|
55
|
+
end"
|
50
56
|
end
|
51
57
|
end
|
52
58
|
end
|
@@ -1,33 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::IfExistCondition do
|
5
7
|
let(:source) {
|
6
|
-
|
8
|
+
'
|
7
9
|
RSpec.configure do |config|
|
8
10
|
config.include EmailSpec::Helpers
|
9
11
|
config.include EmailSpec::Methods
|
10
12
|
end
|
11
|
-
|
13
|
+
'
|
12
14
|
}
|
13
15
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
14
|
-
let(:instance) { double(:
|
16
|
+
let(:instance) { double(current_node: node) }
|
15
17
|
|
16
18
|
describe '#process' do
|
17
19
|
it 'call block if match anything' do
|
18
20
|
run = false
|
19
|
-
condition =
|
20
|
-
|
21
|
-
|
21
|
+
condition =
|
22
|
+
Rewriter::IfExistCondition.new instance,
|
23
|
+
type: 'send',
|
24
|
+
message: 'include',
|
25
|
+
arguments: ['EmailSpec::Helpers'] do
|
26
|
+
run = true
|
27
|
+
end
|
22
28
|
condition.process
|
23
29
|
expect(run).to be_truthy
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'not call block if not match anything' do
|
27
33
|
run = false
|
28
|
-
condition =
|
29
|
-
|
30
|
-
|
34
|
+
condition =
|
35
|
+
Rewriter::IfExistCondition.new instance,
|
36
|
+
type: 'send',
|
37
|
+
message: 'include',
|
38
|
+
arguments: ['FactoryGirl::SyntaxMethods'] do
|
39
|
+
run = true
|
40
|
+
end
|
31
41
|
condition.process
|
32
42
|
expect(run).to be_falsey
|
33
43
|
end
|
@@ -1,40 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::IfOnlyExistCondition do
|
5
7
|
let(:source) {
|
6
|
-
|
8
|
+
'
|
7
9
|
RSpec.configure do |config|
|
8
10
|
config.include EmailSpec::Helpers
|
9
11
|
config.include EmailSpec::Methods
|
10
12
|
end
|
11
|
-
|
13
|
+
'
|
12
14
|
}
|
13
15
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
14
|
-
let(:instance) { double(:
|
16
|
+
let(:instance) { double(current_node: node) }
|
15
17
|
|
16
18
|
describe '#process' do
|
17
19
|
it 'gets matching nodes' do
|
18
|
-
source =
|
20
|
+
source =
|
21
|
+
'
|
19
22
|
RSpec.configure do |config|
|
20
23
|
config.include EmailSpec::Helpers
|
21
24
|
end
|
22
|
-
|
25
|
+
'
|
23
26
|
node = Parser::CurrentRuby.parse(source)
|
24
|
-
instance = double(:
|
27
|
+
instance = double(current_node: node)
|
25
28
|
run = false
|
26
|
-
condition =
|
27
|
-
|
28
|
-
|
29
|
+
condition =
|
30
|
+
Rewriter::IfOnlyExistCondition.new instance,
|
31
|
+
type: 'send',
|
32
|
+
message: 'include',
|
33
|
+
arguments: ['EmailSpec::Helpers'] do
|
34
|
+
run = true
|
35
|
+
end
|
29
36
|
condition.process
|
30
37
|
expect(run).to be_truthy
|
31
38
|
end
|
32
39
|
|
33
40
|
it 'not call block if does not match' do
|
34
41
|
run = false
|
35
|
-
condition =
|
36
|
-
|
37
|
-
|
42
|
+
condition =
|
43
|
+
Rewriter::IfOnlyExistCondition.new instance,
|
44
|
+
type: 'send',
|
45
|
+
message: 'include',
|
46
|
+
arguments: ['EmailSpec::Helpers'] do
|
47
|
+
run = true
|
48
|
+
end
|
38
49
|
condition.process
|
39
50
|
expect(run).to be_falsey
|
40
51
|
end
|
@@ -1,33 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::UnlessExistCondition do
|
5
7
|
let(:source) {
|
6
|
-
|
8
|
+
'
|
7
9
|
RSpec.configure do |config|
|
8
10
|
config.include EmailSpec::Helpers
|
9
11
|
config.include EmailSpec::Methods
|
10
12
|
end
|
11
|
-
|
13
|
+
'
|
12
14
|
}
|
13
15
|
let(:node) { Parser::CurrentRuby.parse(source) }
|
14
|
-
let(:instance) { double(:
|
16
|
+
let(:instance) { double(current_node: node) }
|
15
17
|
|
16
18
|
describe '#process' do
|
17
19
|
it 'call block if match anything' do
|
18
20
|
run = false
|
19
|
-
condition =
|
20
|
-
|
21
|
-
|
21
|
+
condition =
|
22
|
+
Rewriter::UnlessExistCondition.new instance,
|
23
|
+
type: 'send',
|
24
|
+
message: 'include',
|
25
|
+
arguments: ['FactoryGirl::Syntax::Methods'] do
|
26
|
+
run = true
|
27
|
+
end
|
22
28
|
condition.process
|
23
29
|
expect(run).to be_truthy
|
24
30
|
end
|
25
31
|
|
26
32
|
it 'not call block if not match anything' do
|
27
33
|
run = false
|
28
|
-
condition =
|
29
|
-
|
30
|
-
|
34
|
+
condition =
|
35
|
+
Rewriter::UnlessExistCondition.new instance,
|
36
|
+
type: 'send',
|
37
|
+
message: 'include',
|
38
|
+
arguments: ['EmailSpec::Helpers'] do
|
39
|
+
run = true
|
40
|
+
end
|
31
41
|
condition.process
|
32
42
|
expect(run).to be_falsey
|
33
43
|
end
|
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
4
6
|
describe Rewriter::GemSpec do
|
5
|
-
let(:gemfile_lock_content) {
|
7
|
+
let(:gemfile_lock_content) {
|
8
|
+
'
|
6
9
|
GEM
|
7
10
|
remote: https://rubygems.org/
|
8
11
|
specs:
|
@@ -12,41 +15,41 @@ GEM
|
|
12
15
|
slop (~> 3.4, >= 3.4.5)
|
13
16
|
rake (10.1.1)
|
14
17
|
slop (3.4.7)
|
15
|
-
|
18
|
+
'
|
16
19
|
}
|
17
20
|
|
18
21
|
it 'returns true if version in Gemfile.lock is greater than definition' do
|
19
|
-
expect(File).to receive(:
|
22
|
+
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(true)
|
20
23
|
expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
|
21
|
-
gem_spec = Rewriter::GemSpec.new('ast', {gte: '1.0.0'})
|
24
|
+
gem_spec = Rewriter::GemSpec.new('ast', { gte: '1.0.0' })
|
22
25
|
expect(gem_spec).to be_match
|
23
26
|
end
|
24
27
|
|
25
28
|
it 'returns true if version in Gemfile.lock is equal to definition' do
|
26
|
-
expect(File).to receive(:
|
29
|
+
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(true)
|
27
30
|
expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
|
28
31
|
gem_spec = Rewriter::GemSpec.new('ast', '1.1.0')
|
29
32
|
expect(gem_spec).to be_match
|
30
33
|
end
|
31
34
|
|
32
35
|
it 'returns false if version in Gemfile.lock is less than definition' do
|
33
|
-
expect(File).to receive(:
|
36
|
+
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(true)
|
34
37
|
expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
|
35
|
-
gem_spec = Rewriter::GemSpec.new('ast', {gt: '1.2.0'})
|
38
|
+
gem_spec = Rewriter::GemSpec.new('ast', { gt: '1.2.0' })
|
36
39
|
expect(gem_spec).not_to be_match
|
37
40
|
end
|
38
41
|
|
39
42
|
it 'returns false if gem does not exist in Gemfile.lock' do
|
40
|
-
expect(File).to receive(:
|
43
|
+
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(true)
|
41
44
|
expect(File).to receive(:read).with('./Gemfile.lock').and_return(gemfile_lock_content)
|
42
45
|
gem_spec = Rewriter::GemSpec.new('synvert', '1.0.0')
|
43
46
|
expect(gem_spec).not_to be_match
|
44
47
|
end
|
45
48
|
|
46
49
|
it 'raise Synvert::Core::GemfileLockNotFound if Gemfile.lock does not exist' do
|
47
|
-
expect(File).to receive(:
|
50
|
+
expect(File).to receive(:exist?).with('./Gemfile.lock').and_return(false)
|
48
51
|
gem_spec = Rewriter::GemSpec.new('ast', '1.1.0')
|
49
|
-
expect
|
52
|
+
expect(gem_spec).to be_match
|
50
53
|
end
|
51
54
|
end
|
52
55
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module Synvert::Core
|
@@ -5,74 +7,77 @@ module Synvert::Core
|
|
5
7
|
let(:dummy_instance) { Class.new { include Rewriter::Helper }.new }
|
6
8
|
let(:instance) do
|
7
9
|
rewriter = Rewriter.new('foo', 'bar')
|
8
|
-
Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
|
10
|
+
Rewriter::Instance.new rewriter, 'spec/**/*_spec.rb' do
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
|
-
describe
|
12
|
-
context
|
13
|
-
let(:node) { parse(
|
14
|
+
describe 'add_receiver_if_necessary' do
|
15
|
+
context 'with receiver' do
|
16
|
+
let(:node) { parse('User.save(false)') }
|
14
17
|
|
15
|
-
it
|
18
|
+
it 'adds reciever' do
|
16
19
|
allow(dummy_instance).to receive(:node).and_return(node)
|
17
|
-
expect(
|
20
|
+
expect(
|
21
|
+
dummy_instance.add_receiver_if_necessary('save(validate: false)')
|
22
|
+
).to eq '{{receiver}}.save(validate: false)'
|
18
23
|
end
|
19
24
|
end
|
20
25
|
|
21
|
-
context
|
22
|
-
let(:node) { parse(
|
26
|
+
context 'without receiver' do
|
27
|
+
let(:node) { parse('save(false)') }
|
23
28
|
|
24
29
|
it "doesn't add reciever" do
|
25
30
|
allow(dummy_instance).to receive(:node).and_return(node)
|
26
|
-
expect(dummy_instance.add_receiver_if_necessary(
|
31
|
+
expect(dummy_instance.add_receiver_if_necessary('save(validate: false)')).to eq 'save(validate: false)'
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
describe
|
32
|
-
context
|
33
|
-
let(:node) { parse(
|
36
|
+
describe 'add_arguments_with_parenthesis_if_necessary' do
|
37
|
+
context 'with arguments' do
|
38
|
+
let(:node) { parse('user.save(false)') }
|
34
39
|
|
35
|
-
it
|
40
|
+
it 'gets arguments with parenthesis' do
|
36
41
|
allow(dummy_instance).to receive(:node).and_return(node)
|
37
|
-
expect(dummy_instance.add_arguments_with_parenthesis_if_necessary).to eq
|
42
|
+
expect(dummy_instance.add_arguments_with_parenthesis_if_necessary).to eq '({{arguments}})'
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
41
|
-
context
|
42
|
-
let(:node) { parse(
|
46
|
+
context 'without argument' do
|
47
|
+
let(:node) { parse('user.save') }
|
43
48
|
|
44
|
-
it
|
49
|
+
it 'gets nothing' do
|
45
50
|
allow(dummy_instance).to receive(:node).and_return(node)
|
46
|
-
expect(dummy_instance.add_arguments_with_parenthesis_if_necessary).to eq
|
51
|
+
expect(dummy_instance.add_arguments_with_parenthesis_if_necessary).to eq ''
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
|
-
describe
|
52
|
-
it
|
53
|
-
expect(dummy_instance.add_curly_brackets_if_necessary(
|
56
|
+
describe 'add_curly_brackets_if_necessary' do
|
57
|
+
it 'add {} if code does not have' do
|
58
|
+
expect(dummy_instance.add_curly_brackets_if_necessary('foo: bar')).to eq '{ foo: bar }'
|
54
59
|
end
|
55
60
|
|
56
61
|
it "doesn't add {} if code already has" do
|
57
|
-
expect(dummy_instance.add_curly_brackets_if_necessary(
|
62
|
+
expect(dummy_instance.add_curly_brackets_if_necessary('{foo: bar}')).to eq '{foo: bar}'
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
|
-
describe
|
62
|
-
it
|
63
|
-
expect(dummy_instance.strip_brackets(
|
66
|
+
describe 'strip_brackets' do
|
67
|
+
it 'strip ()' do
|
68
|
+
expect(dummy_instance.strip_brackets('(123)')).to eq '123'
|
64
69
|
end
|
65
70
|
|
66
|
-
it
|
67
|
-
expect(dummy_instance.strip_brackets(
|
71
|
+
it 'strip {}' do
|
72
|
+
expect(dummy_instance.strip_brackets('{123}')).to eq '123'
|
68
73
|
end
|
69
74
|
|
70
|
-
it
|
71
|
-
expect(dummy_instance.strip_brackets(
|
75
|
+
it 'strip []' do
|
76
|
+
expect(dummy_instance.strip_brackets('[123]')).to eq '123'
|
72
77
|
end
|
73
78
|
|
74
|
-
it
|
75
|
-
expect(dummy_instance.strip_brackets(
|
79
|
+
it 'not strip unmatched (]' do
|
80
|
+
expect(dummy_instance.strip_brackets('(123]')).to eq '(123]'
|
76
81
|
end
|
77
82
|
end
|
78
83
|
end
|