Sha256: dcfc6be3f23a0ce31267fadea767a74fc3a309d9c98e52219ac495505905f087

Contents?: true

Size: 1.4 KB

Versions: 29

Compression:

Stored size: 1.4 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) {
      "
describe Post do
  it 'gets post' do
    FactoryGirl.create :post
  end
end
    "
    }
    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

29 entries across 29 versions & 1 rubygems

Version Path
synvert-core-0.35.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.34.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.33.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.33.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.32.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.31.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.30.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.29.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.28.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.28.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.27.4 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.27.3 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.27.2 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.27.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.27.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.26.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.26.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.25.1 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.25.0 spec/synvert/core/rewriter/scope/within_scope.rb
synvert-core-0.24.0 spec/synvert/core/rewriter/scope/within_scope.rb