spec/synvert/rewriter/action_spec.rb in synvert-0.0.9 vs spec/synvert/rewriter/action_spec.rb in synvert-0.0.10
- old
+ new
@@ -1,25 +1,54 @@
require 'spec_helper'
module Synvert
describe Rewriter::ReplaceWithAction do
- subject {
- source = "post = FactoryGirl.create_list :post, 2"
- send_node = Parser::CurrentRuby.parse(source).children[1]
- instance = double(:current_node => send_node)
- Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}')
- }
+ context "replace with single line" do
+ subject {
+ source = "post = FactoryGirl.create_list :post, 2"
+ send_node = Parser::CurrentRuby.parse(source).children[1]
+ instance = double(:current_node => send_node)
+ Rewriter::ReplaceWithAction.new(instance, 'create_list {{arguments}}')
+ }
- it 'gets begin_pos' do
- expect(subject.begin_pos).to eq "post = ".length
- end
+ it 'gets begin_pos' do
+ expect(subject.begin_pos).to eq "post = ".length
+ end
- it 'gets end_pos' do
- expect(subject.end_pos).to eq "post = FactoryGirl.create_list :post, 2".length
+ it 'gets end_pos' do
+ 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
- it 'gets rewritten_code' do
- expect(subject.rewritten_code).to eq 'create_list :post, 2'
+ context "#replace with multiple line" do
+ subject {
+ source = " its(:size) { should == 1 }"
+ send_node = Parser::CurrentRuby.parse(source)
+ instance = double(:current_node => send_node)
+ Rewriter::ReplaceWithAction.new(instance, """describe '#size' do
+ subject { super().size }
+ it { {{body}} }
+end""")
+ }
+
+ it 'gets begin_pos' do
+ expect(subject.begin_pos).to eq 2
+ end
+
+ it 'gets end_pos' do
+ expect(subject.end_pos).to eq " its(:size) { should == 1 }".length
+ end
+
+ it 'gets rewritten_code' do
+ expect(subject.rewritten_code).to eq """\n\n describe '#size' do
+ subject { super().size }
+ it { should == 1 }
+ end"""
+ end
end
end
describe Rewriter::AppendAction < Rewriter::Action do
describe 'class node' do