Sha256: d1dcab9a2d4b1b43a9af3bba61417129c922c364ecb173cd26cd9a559b6715b9

Contents?: true

Size: 969 Bytes

Versions: 15

Compression:

Stored size: 969 Bytes

Contents

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 one node matches' do
      let(:block) { ->(node) { node.equal?(child_a) } }

      it 'returns the full path' do
        expect(path).to eql([: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([:root, :parent, :child_b])
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
mutant-0.7.9 spec/unit/mutant/ast_spec.rb
mutant-0.7.8 spec/unit/mutant/ast_spec.rb
mutant-0.7.7 spec/unit/mutant/ast_spec.rb
mutant-0.7.6 spec/unit/mutant/ast_spec.rb
mutant-0.7.5 spec/unit/mutant/ast_spec.rb
mutant-0.7.4 spec/unit/mutant/ast_spec.rb
mutant-0.7.3 spec/unit/mutant/ast_spec.rb
mutant-0.7.2 spec/unit/mutant/ast_spec.rb
mutant-0.7.1 spec/unit/mutant/ast_spec.rb
mutant-0.6.7 spec/unit/mutant/ast_spec.rb
mutant-0.6.6 spec/unit/mutant/ast_spec.rb
mutant-0.6.5 spec/unit/mutant/ast_spec.rb
mutant-0.6.4 spec/unit/mutant/ast_spec.rb
mutant-0.6.3 spec/unit/mutant/ast_spec.rb
mutant-0.6.2 spec/unit/mutant/ast_spec.rb