Sha256: e33f65928b33757e4b1ec47e474a04e816db9caaac9006a00b9c77bc572c3999

Contents?: true

Size: 1.43 KB

Versions: 34

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Synvert::Core
  describe Rewriter::WithinScope do
    let(:instance) {
      rewriter = Rewriter.new('foo', 'bar')
      Rewriter::Instance.new(rewriter, 'file pattern')
    }
    let(:source) { <<~EOS }
      describe Post do
        it 'gets post' do
          FactoryGirl.create :post
        end
      end
    EOS

    let(:node) { Parser::CurrentRuby.parse(source) }

    before do
      Rewriter::Instance.reset
      instance.current_node = node
    end

    describe '#process' do
      it 'not call block if no matching node' do
        run = false
        scope =
          Rewriter::WithinScope.new instance, type: 'send', message: 'missing' do
            run = true
          end
        scope.process
        expect(run).to be_falsey
      end

      it 'call block if there is matching node' do
        run = false
        type_in_scope = nil
        scope =
          Rewriter::WithinScope.new instance,
                                    type: 'send',
                                    receiver: 'FactoryGirl',
                                    message: 'create',
                                    arguments: [':post'] 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
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
synvert-core-0.57.1 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.57.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.56.1 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.56.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.55.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.54.3 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.54.2 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.54.1 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.54.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.53.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.52.1 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.52.0 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.51.1 spec/synvert/core/rewriter/scope/within_scope_spec.rb
synvert-core-0.51.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.50.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.49.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.49.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.48.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.47.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.46.0 spec/synvert/core/rewriter/scope/within_scope.rb