spec/synvert/rewriter/action_spec.rb in synvert-0.0.7 vs spec/synvert/rewriter/action_spec.rb in synvert-0.0.8
- old
+ new
@@ -8,43 +8,64 @@
instance = double(:current_node => send_node)
Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 7
+ expect(subject.begin_pos).to eq "post = ".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 39
+ expect(subject.end_pos).to eq "post = FactoryGirl.create_list :post, 2".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq 'create_list :post, 2'
end
end
describe Rewriter::AppendAction < Rewriter::Action do
describe 'class node' do
- subject {
+ subject do
source = "class User\n has_many :posts\nend"
class_node = Parser::CurrentRuby.parse(source)
instance = double(:current_node => class_node)
Rewriter::AppendAction.new(instance, "def as_json\n super\nend")
- }
+ end
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 28
+ expect(subject.begin_pos).to eq "calss User\n has_many :posts".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 28
+ expect(subject.end_pos).to eq "class User\n has_many :posts".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n\n def as_json\n super\n end"
end
end
+
+ describe 'begin node' do
+ subject do
+ source = "gem 'rails'\ngem 'mysql2'"
+ begin_node = Parser::CurrentRuby.parse(source)
+ instance = double(:current_node => begin_node)
+ Rewriter::AppendAction.new(instance, "gem 'twitter'")
+ end
+
+ it 'gets begin_pos' do
+ expect(subject.begin_pos).to eq "gem 'rails'\ngem 'mysql2'".length
+ end
+
+ it 'gets end_pos' do
+ expect(subject.end_pos).to eq "gem 'rails'\ngem 'mysql2'".length
+ end
+
+ it 'gets rewritten_code' do
+ expect(subject.rewritten_code).to eq "\ngem 'twitter'"
+ end
+ end
end
describe Rewriter::InsertAction do
describe 'block node without args' do
subject {
@@ -53,15 +74,15 @@
instance = double(:current_node => block_node)
Rewriter::InsertAction.new(instance, 'config.eager_load = true')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 33
+ expect(subject.begin_pos).to eq "Synvert::Application.configure do".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 33
+ expect(subject.end_pos).to eq "Synvert::Application.configure do".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n config.eager_load = true"
end
@@ -74,15 +95,15 @@
instance = double(:current_node => block_node)
Rewriter::InsertAction.new(instance, '{{arguments.first}}.include FactoryGirl::Syntax::Methods')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 27
+ expect(subject.begin_pos).to eq "RSpec.configure do |config|".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 27
+ expect(subject.end_pos).to eq "RSpec.configure do |config|".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n config.include FactoryGirl::Syntax::Methods"
end
@@ -95,15 +116,15 @@
instance = double(:current_node => class_node)
Rewriter::InsertAction.new(instance, 'include Deletable')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 10
+ expect(subject.begin_pos).to eq "class User".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 10
+ expect(subject.end_pos).to eq "class User".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n include Deletable"
end
@@ -116,15 +137,15 @@
instance = double(:current_node => class_node)
Rewriter::InsertAction.new(instance, 'include Deletable')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 31
+ expect(subject.begin_pos).to eq "class User < ActionRecord::Base".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 31
+ expect(subject.end_pos).to eq "class User < ActionRecord::Base".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n include Deletable"
end
@@ -138,15 +159,15 @@
instance = double(:current_node => node)
Rewriter::InsertAfterAction.new(instance, 'include Bar')
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 13
+ expect(subject.begin_pos).to eq " include Foo".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 13
+ expect(subject.end_pos).to eq " include Foo".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq "\n include Bar"
end
@@ -159,14 +180,14 @@
instance = double(:current_node => send_node)
Rewriter::RemoveAction.new(instance)
}
it 'gets begin_pos' do
- expect(subject.begin_pos).to eq 30
+ expect(subject.begin_pos).to eq "user = User.new params[:user]\n".length
end
it 'gets end_pos' do
- expect(subject.end_pos).to eq 39
+ expect(subject.end_pos).to eq "user = User.new params[:user]\nuser.save".length
end
it 'gets rewritten_code' do
expect(subject.rewritten_code).to eq ""
end