Sha256: 4ccd4bf6bf743589676a71850f2898318f221b7531e7041f93c7290a02f7677a

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

module Synvert::Core
  describe Rewriter::Scope do
    let(:source) {
"""
describe Post do
  before :each do
    @user = FactoryGirl.create :user
  end

  it 'gets posts' do
    post1 = FactoryGirl.create :post
    post2 = FactoryGirl.create :post
  end
end
"""
    }
    let(:node) { Parser::CurrentRuby.parse(source) }
    let(:instance) { double(:current_node => node, :current_node= => node, :current_source => source) }
    before do
      allow(instance).to receive(:process_with_node).and_yield
      Rewriter::Instance.current = instance
    end

    describe '#process' do
      it 'not call block if no matching node' do
        run = false
        scope = Rewriter::Scope.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
        scope = Rewriter::Scope.new instance, type: 'send', receiver: 'FactoryGirl', message: 'create', arguments: [':post'] do
          run = true
        end
        scope.process
        expect(run).to be_truthy
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
synvert-core-0.5.0 spec/synvert/core/rewriter/scope_spec.rb
synvert-core-0.4.3 spec/synvert/core/rewriter/scope_spec.rb