Sha256: e24668397889f5e306f91b33f9810fc7850ab308008bbda98538f5746259deb6

Contents?: true

Size: 1.61 KB

Versions: 46

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Synvert::Core
  describe Rewriter::GotoScope do
    let(:instance) {
      rewriter = Rewriter.new('foo', 'bar')
      Rewriter::Instance.new(rewriter, 'file pattern')
    }
    let(:source) { <<~EOS }
      Factory.define :user do |user|
        user.first_name 'First'
        user.last_name 'Last'
      end
    EOS

    let(:node) { Parser::CurrentRuby.parse(source) }
    before { instance.current_node = node }

    describe '#process' do
      it 'calls block with child node' do
        run = false
        type_in_scope = nil
        scope =
          Rewriter::GotoScope.new instance, 'caller.receiver' do
            run = true
            type_in_scope = node.type
          end
        scope.process
        expect(run).to be_truthy
        expect(type_in_scope).to eq :const
        expect(instance.current_node.type).to eq :block
      end

      it 'call block with child node in array' do
        run = false
        type_in_scope = nil
        scope =
          Rewriter::GotoScope.new instance, 'body.1' do
            run = true
            type_in_scope = node.type
          end
        scope.process
        expect(run).to be_truthy
        expect(type_in_scope).to eq :send
        expect(instance.current_node.type).to eq :block
      end

      it 'calls block multiple times with block body' do
        count = 0
        scope =
          Rewriter::GotoScope.new instance, 'body' do
            count += 1
          end
        scope.process
        expect(count).to eq 2
        expect(instance.current_node.type).to eq :block
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
synvert-core-2.2.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.1.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.1.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.1.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.0.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.0.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.0.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-2.0.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.35.4 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.35.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.35.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.35.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.35.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.34.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.33.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.33.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.33.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.33.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.32.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.32.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb