Sha256: 28f661479120ef9fba9e5cd81bb32e15309296888b7b2f3f1979d43fed94f1ed

Contents?: true

Size: 1.59 KB

Versions: 28

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Synvert::Core
  describe Rewriter::ReplaceWithAction do
    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 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

    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, <<~EOS)
          describe '#size' do
            subject { super().size }
            it { {{body}} }
          end
        EOS
      }

      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 <<~EOS.strip
          describe '#size' do
              subject { super().size }
              it { should == 1 }
            end
        EOS
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
synvert-core-0.56.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.56.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.55.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.54.3 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.54.2 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.54.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.54.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.53.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.52.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.52.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.51.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.51.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.50.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.49.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.49.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.48.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.47.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.46.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.45.2 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.45.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb