Sha256: f98869caa25010f9e701b071aff91a45d297dd0debeff192373ca4ba993c4192

Contents?: true

Size: 1.36 KB

Versions: 65

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Synvert::Core
  describe Rewriter::AppendAction do
    describe 'class node' do
      subject do
        source = "class User\n  has_many :posts\nend"
        class_node = Parser::CurrentRuby.parse(source)
        instance = double(current_node: class_node)
        Rewriter::AppendAction.new(instance, "def as_json\n  super\nend")
      end

      it 'gets begin_pos' do
        expect(subject.begin_pos).to eq "class User\n  has_many :posts".length
      end

      it 'gets end_pos' do
        expect(subject.end_pos).to eq "class User\n  has_many :posts".length
      end

      it 'gets rewritten_code' do
        expect(subject.rewritten_code).to eq "\n\n  def as_json\n    super\n  end"
      end
    end

    describe 'begin node' do
      subject do
        source = "gem 'rails'\ngem 'mysql2'"
        begin_node = Parser::CurrentRuby.parse(source)
        instance = double(current_node: begin_node)
        Rewriter::AppendAction.new(instance, "gem 'twitter'")
      end

      it 'gets begin_pos' do
        expect(subject.begin_pos).to eq "gem 'rails'\ngem 'mysql2'".length
      end

      it 'gets end_pos' do
        expect(subject.end_pos).to eq "gem 'rails'\ngem 'mysql2'".length
      end

      it 'gets rewritten_code' do
        expect(subject.rewritten_code).to eq "\ngem 'twitter'"
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
synvert-core-0.56.1 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.56.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.55.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.54.3 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.54.2 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.54.1 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.54.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.53.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.52.1 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.52.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.51.1 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.51.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.50.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.49.1 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.49.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.48.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.47.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.46.0 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.45.2 spec/synvert/core/rewriter/action/append_action_spec.rb
synvert-core-0.45.1 spec/synvert/core/rewriter/action/append_action_spec.rb