spec/synvert/rewriter/action_spec.rb in synvert-0.0.2 vs spec/synvert/rewriter/action_spec.rb in synvert-0.0.3

- old
+ new

@@ -2,11 +2,11 @@ module Synvert describe Rewriter::ReplaceWithAction do describe '#rewrite' do it 'replaces code' do - action = Rewriter::ReplaceWithAction.new('create_list {{node.arguments}}') + action = Rewriter::ReplaceWithAction.new('create_list {{self.arguments}}') source = "post = FactoryGirl.create_list :post, 2" send_node = Parser::CurrentRuby.parse(source).children[1] output = action.rewrite(source, send_node) expect(output).to eq "post = create_list :post, 2" end @@ -14,11 +14,11 @@ end describe Rewriter::InsertAction do describe '#rewrite' do it 'insert code to block node' do - action = Rewriter::InsertAction.new('{{node.arguments.first}}.include FactoryGirl::Syntax::Methods') + action = Rewriter::InsertAction.new('{{self.arguments.first}}.include FactoryGirl::Syntax::Methods') source = "RSpec.configure do |config|\nend" block_node = Parser::CurrentRuby.parse(source) output = action.rewrite(source, block_node) expect(output).to eq "RSpec.configure do |config|\n config.include FactoryGirl::Syntax::Methods\nend" end @@ -43,9 +43,33 @@ action = Rewriter::InsertAction.new('World(FactoryGirl::Syntax::Methods)') source = "require 'cucumber/rails'" block_node = Parser::CurrentRuby.parse(source) output = action.rewrite(source, block_node) expect(output).to eq "require 'cucumber/rails'\nWorld(FactoryGirl::Syntax::Methods)" + end + end + end + + describe Rewriter::InsertAfterAction do + describe '#rewrite' do + it 'insert_after code' do + action = Rewriter::InsertAfterAction.new('include Bar') + source = " include Foo" + node = Parser::CurrentRuby.parse(source) + output = action.rewrite(source, node) + expect(output).to eq " include Foo\n include Bar" + end + end + end + + describe Rewriter::RemoveAction do + describe '#rewrite' do + it 'remove code' do + action = Rewriter::RemoveAction.new + source = "user = User.new params[:user]\nuser.save\nrender\n" + send_node = Parser::CurrentRuby.parse(source).children[1] + output = action.rewrite(source, send_node) + expect(output).to eq "user = User.new params[:user]\nrender\n" end end end end