Sha256: d7f963f046b05f8bd0819967796f40e3fd620874bf3a4f9b37cdfe950f2aa95c

Contents?: true

Size: 1.53 KB

Versions: 34

Compression:

Stored size: 1.53 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,
          "describe '#size' do
  subject { super().size }
  it { {{body}} }
end",
          autoindent: false
        )
      }

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

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
synvert-core-0.40.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.39.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.38.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.36.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.35.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.35.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.34.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.33.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.33.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.32.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.31.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.30.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.29.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.28.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.28.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.27.4 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.27.3 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.27.2 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.27.1 spec/synvert/core/rewriter/action/replace_with_action_spec.rb
synvert-core-0.27.0 spec/synvert/core/rewriter/action/replace_with_action_spec.rb