Sha256: 65ecf6989e16a5726bb0baabd53f98bb647b065712bec16ad02a9ee3fb31f1c8

Contents?: true

Size: 1.4 KB

Versions: 20

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

RSpec.describe Mutant::AST do
  let(:object) { described_class }

  describe '.find_last_path' do
    subject { object.find_last_path(root, &block) }

    let(:root)    { s(:root, parent)             }
    let(:child_a) { s(:child_a)                  }
    let(:child_b) { s(:child_b)                  }
    let(:parent)  { s(:parent, child_a, child_b) }

    def path
      subject.map(&:type)
    end

    context 'when no node matches' do
      let(:block) { ->(_) { false } }

      it { should eql([]) }
    end

    context 'when called without block' do
      let(:block) { nil }

      it 'raises error' do
        expect { subject }.to raise_error(ArgumentError, 'block expected')
      end
    end

    context 'on non Parser::AST::Node child' do
      let(:block)   { ->(node) { fail if node.equal?(child_a) } }
      let(:child_a) { AST::Node.new(:foo) }

      it 'does not yield that node' do
        expect(path).to eql([])
      end
    end

    context 'when one node matches' do
      let(:block) { ->(node) { node.equal?(child_a) } }

      it 'returns the full path' do
        expect(path).to eql(%i[root parent child_a])
      end
    end

    context 'when two nodes match' do
      let(:block) { ->(node) { node.equal?(child_a) || node.equal?(child_b) } }

      it 'returns the last full path' do
        expect(path).to eql(%i[root parent child_b])
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mutant-0.9.11 spec/unit/mutant/ast_spec.rb
mutant-0.9.10 spec/unit/mutant/ast_spec.rb
mutant-0.9.9 spec/unit/mutant/ast_spec.rb
mutant-0.9.8 spec/unit/mutant/ast_spec.rb
mutant-0.9.7 spec/unit/mutant/ast_spec.rb
mutant-0.9.6 spec/unit/mutant/ast_spec.rb
mutant-0.9.5 spec/unit/mutant/ast_spec.rb
mutant-0.9.4 spec/unit/mutant/ast_spec.rb
mutant-0.9.3 spec/unit/mutant/ast_spec.rb
mutant-0.9.2 spec/unit/mutant/ast_spec.rb
mutant-0.9.1 spec/unit/mutant/ast_spec.rb
mutant-0.9.0 spec/unit/mutant/ast_spec.rb
mutant-0.8.24 spec/unit/mutant/ast_spec.rb
mutant-0.8.23 spec/unit/mutant/ast_spec.rb
mutant-0.8.22 spec/unit/mutant/ast_spec.rb
mutant-0.8.21 spec/unit/mutant/ast_spec.rb
mutant-0.8.20 spec/unit/mutant/ast_spec.rb
mutant-0.8.19 spec/unit/mutant/ast_spec.rb
mutant-0.8.18 spec/unit/mutant/ast_spec.rb
mutant-0.8.17 spec/unit/mutant/ast_spec.rb