free_mutant/spec/unit/mutant/ast_spec.rb
Markus Schirp bfac03f29d Improve internals of method matcher
* Fix name clash with Kernel#method
* Match full paths of node enabling next changes to fix exclusion of evaled methods from direct matches
2014-09-16 18:39:34 +00:00

38 lines
969 B
Ruby

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