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-1.31.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.31.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.30.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.30.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.30.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.30.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.29.4 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.29.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.29.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.29.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.29.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.5 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.4 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.2 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.28.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.27.1 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.27.0 spec/synvert/core/rewriter/scope/goto_scope_spec.rb
synvert-core-1.26.3 spec/synvert/core/rewriter/scope/goto_scope_spec.rb