Do not create empty blocks on mutations
This commit is contained in:
parent
d140ef2435
commit
6f8d4e1cfa
3 changed files with 37 additions and 14 deletions
|
@ -3,7 +3,7 @@ module Mutant
|
|||
# Mutator on AST blocks
|
||||
class Block < self
|
||||
|
||||
handle Rubinius::AST::Block
|
||||
handle(Rubinius::AST::Block)
|
||||
|
||||
private
|
||||
|
||||
|
@ -16,7 +16,11 @@ module Mutant
|
|||
def dispatch
|
||||
array = node.array
|
||||
emit_elements(array)
|
||||
if array.length > 1
|
||||
emit_element_presence(array)
|
||||
else
|
||||
emit_self([new_nil])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,10 @@ shared_examples_for 'a mutator' do
|
|||
|
||||
let(:yields) { [] }
|
||||
let(:object) { described_class }
|
||||
|
||||
unless instance_methods.map(&:to_s).include?('node')
|
||||
let(:node) { source.to_ast }
|
||||
end
|
||||
|
||||
it_should_behave_like 'a command method'
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Mutant::Mutator, 'block' do
|
||||
# Two send operations
|
||||
|
||||
context 'with more than one statement' do
|
||||
let(:source) { "self.foo\nself.bar" }
|
||||
|
||||
let(:mutations) do
|
||||
|
@ -18,3 +19,18 @@ describe Mutant::Mutator, 'block' do
|
|||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
|
||||
|
||||
context 'with one statement' do
|
||||
let(:node) { Rubinius::AST::Block.new(1, ['self.foo'.to_ast]) }
|
||||
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << [:block, 'foo'.to_sexp]
|
||||
# Empty blocks result in stack verification error
|
||||
mutations << [:block, 'nil'.to_sexp]
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue