diff --git a/Changelog.md b/Changelog.md index 1b741e12..8e51eb32 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,7 @@ Changes: +* Fix crash without conditionals * Remove dependency to descendants tracker * Add mutation #== => #eql?, #equal? * Add mutation #eql? => #equal? diff --git a/lib/mutant/mutator/node/case.rb b/lib/mutant/mutator/node/case.rb index 873ffb68..56875c49 100644 --- a/lib/mutant/mutator/node/case.rb +++ b/lib/mutant/mutator/node/case.rb @@ -20,7 +20,7 @@ module Mutant # @api private # def dispatch - emit_condition_mutations + emit_condition_mutations if condition emit_when_mutations emit_else_mutations emit_nil diff --git a/spec/unit/mutant/mutator/node/case_spec.rb b/spec/unit/mutant/mutator/node/case_spec.rb index fbb62f60..f91369ed 100644 --- a/spec/unit/mutant/mutator/node/case_spec.rb +++ b/spec/unit/mutant/mutator/node/case_spec.rb @@ -9,6 +9,43 @@ describe Mutant::Mutator::Node::Case do Mutant::Random.stub(hex_string: random_string) end + context 'without condition' do + let(:source) do + <<-RUBY + case + when true + else + end + RUBY + end + + let(:mutations) do + mutations = [] + mutations << 'nil' + mutations << <<-RUBY + case + when true + raise + else + end + RUBY + mutations << <<-RUBY + case + when false + else + end + RUBY + mutations << <<-RUBY + case + when nil + else + end + RUBY + end + + it_should_behave_like 'a mutator' + end + context 'with multiple when branches' do let(:source) do <<-RUBY