From 05955f5e9dd060e70f0b24d17fcdb1b2133bca87 Mon Sep 17 00:00:00 2001 From: Markus Schirp Date: Mon, 10 Aug 2015 13:53:19 +0000 Subject: [PATCH] Improve `defined?` mutations * Correct changelog reference --- Changelog.md | 2 +- lib/mutant/mutator/node/defined.rb | 17 +++-------------- meta/defined.rb | 2 +- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Changelog.md b/Changelog.md index 496871fc..33935dbe 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,7 +2,7 @@ * Remove invalid mutation `foo or bar` to `!(foo or bar)` see #287 * Add mutation from `#to_h` to `#to_hash` #218 -* Add mutation from `#defined?` to `true` / `false` #399 +* Add mutation from `#defined?` to `true` / `false` #334 # v0.8.1 2015-07-24 diff --git a/lib/mutant/mutator/node/defined.rb b/lib/mutant/mutator/node/defined.rb index 8aaffa8d..cb01f494 100644 --- a/lib/mutant/mutator/node/defined.rb +++ b/lib/mutant/mutator/node/defined.rb @@ -16,21 +16,10 @@ module Mutant # # @api private def dispatch - emit_expression_mutations do |node| - !n_self?(node) - end - - emit_bools - end - - # Emit booleans - # - # @return [undefined] - # - # @api private - def emit_bools + emit_singletons emit(N_TRUE) - emit(N_FALSE) + + emit_expression_mutations { |node| !n_self?(node) } end end # Defined diff --git a/meta/defined.rb b/meta/defined.rb index e61d8af7..48214224 100644 --- a/meta/defined.rb +++ b/meta/defined.rb @@ -1,7 +1,7 @@ Mutant::Meta::Example.add do source 'defined?(foo)' + singleton_mutations mutation 'defined?(nil)' mutation 'true' - mutation 'false' end