Sha256: fcd477faedb099795d19ba557eed7fa00b85bd45f1125b791a34106ded127d07

Contents?: true

Size: 1.82 KB

Versions: 16

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Synvert::Core
  describe Rewriter::InsertAction do
    context 'at end' do
      subject {
        source = "  User.where(username: 'Richard')"
        node = Parser::CurrentRuby.parse(source)
        instance = double(current_node: node)
        Rewriter::InsertAction.new(instance, '.first', at: 'end').process
      }

      it 'gets begin_pos' do
        expect(subject.begin_pos).to eq "  User.where(username: 'Richard')".length
      end

      it 'gets end_pos' do
        expect(subject.end_pos).to eq "  User.where(username: 'Richard')".length
      end

      it 'gets rewritten_code' do
        expect(subject.rewritten_code).to eq '.first'
      end
    end

    context 'at beginning' do
      subject {
        source = "  open('http://test.com')"
        node = Parser::CurrentRuby.parse(source)
        instance = double(current_node: node)
        Rewriter::InsertAction.new(instance, 'URI.', at: 'beginning').process
      }

      it 'gets begin_pos' do
        expect(subject.begin_pos).to eq 2
      end

      it 'gets end_pos' do
        expect(subject.end_pos).to eq 2
      end

      it 'gets rewritten_code' do
        expect(subject.rewritten_code).to eq 'URI.'
      end
    end

    context 'to receiver' do
      subject {
        source = "User.where(username: 'Richard')"
        node = Parser::CurrentRuby.parse(source)
        instance = double(current_node: node)
        Rewriter::InsertAction.new(instance, '.active', to: 'receiver', at: 'end').process
      }

      it 'gets begin_pos' do
        expect(subject.begin_pos).to eq "User".length
      end

      it 'gets end_pos' do
        expect(subject.end_pos).to eq "User".length
      end

      it 'gets rewritten_code' do
        expect(subject.rewritten_code).to eq '.active'
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
synvert-core-1.4.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.3.1 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.3.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.2.1 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.2.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.1.1 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.1.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.0.5 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.0.4 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.0.3 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.0.2 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-1.0.1 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-0.64.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-0.63.1 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-0.63.0 spec/synvert/core/rewriter/action/insert_action_spec.rb
synvert-core-0.62.1 spec/synvert/core/rewriter/action/insert_action_spec.rb