Mutate method call receivers
This commit is contained in:
parent
a3a5db7e0b
commit
3dc23c5238
4 changed files with 55 additions and 21 deletions
|
@ -1,3 +1,9 @@
|
|||
# v0.2.8 2012-12-29
|
||||
|
||||
* [feature] Mutate method call receivers "foo.bar" => "foo"
|
||||
|
||||
[Compare v0.2.7..v0.2.8](https://github.com/mbj/mutant/compare/v0.2.7...v0.2.8)
|
||||
|
||||
# v0.2.7 2012-12-21
|
||||
|
||||
* [fixed] Use latest adamantium and ice_nine
|
||||
|
|
|
@ -15,11 +15,49 @@ module Mutant
|
|||
# @api private
|
||||
#
|
||||
def dispatch
|
||||
emit_receiver
|
||||
emit_implicit_self_receiver
|
||||
emit_attribute_mutations(:block) if node.block
|
||||
emit_receiver_mutations
|
||||
emit_block_mutations
|
||||
emit_block_absence_mutation
|
||||
end
|
||||
|
||||
# Emit receiver
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api pirvate
|
||||
#
|
||||
def emit_receiver
|
||||
unless self?
|
||||
emit(receiver)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit block mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_block_mutations
|
||||
if node.block
|
||||
emit_attribute_mutations(:block)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit receiver mutations
|
||||
#
|
||||
# @return [undefined]
|
||||
#
|
||||
# @api private
|
||||
#
|
||||
def emit_receiver_mutations
|
||||
unless self?
|
||||
emit_attribute_mutations(:receiver)
|
||||
end
|
||||
end
|
||||
|
||||
# Emit block absence mutation
|
||||
#
|
||||
# @return [undefined]
|
||||
|
|
|
@ -45,13 +45,14 @@ shared_examples_for 'a mutator' do
|
|||
end
|
||||
|
||||
it 'generates the expected mutations' do
|
||||
generated = self.subject.map { |mutation| ToSource.to_source(mutation) }.to_set
|
||||
generated = self.subject.map { |mutation| ToSource.to_source(mutation) }.to_set
|
||||
|
||||
missing = (expected_mutations - generated).to_a
|
||||
unexpected = (generated - expected_mutations).to_a
|
||||
|
||||
unless generated == expected_mutations
|
||||
fail "Missing mutations:\n%s\nUnexpected mutations:\n%s" % [missing.join("\n----\n"), unexpected.join("\n----\n")]
|
||||
message ="Missing mutations:\n%s\nUnexpected mutations:\n%s" % [missing.join("\n----\n"), unexpected.join("\n----\n")]
|
||||
fail message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,23 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe Mutant::Mutator, 'send' do
|
||||
context 'send without arguments' do
|
||||
# This could not be reproduced in a test case but happens in the mutant source code?
|
||||
context 'block_given?' do
|
||||
context 'implicit self' do
|
||||
let(:source) { 'block_given?' }
|
||||
|
||||
it_should_behave_like 'a noop mutator'
|
||||
end
|
||||
|
||||
context 'explicit self' do
|
||||
let(:source) { 'self.block_given?' }
|
||||
|
||||
it_should_behave_like 'a noop mutator'
|
||||
end
|
||||
end
|
||||
|
||||
context 'with self as receiver' do
|
||||
|
||||
context 'implicit' do
|
||||
let(:source) { 'foo' }
|
||||
|
||||
|
@ -39,9 +23,14 @@ describe Mutant::Mutator, 'send' do
|
|||
end
|
||||
|
||||
context 'to some object' do
|
||||
let(:source) { '1.foo' }
|
||||
let(:source) { 'foo.bar' }
|
||||
|
||||
it_should_behave_like 'a noop mutator'
|
||||
let(:mutations) do
|
||||
mutations = []
|
||||
mutations << 'foo'
|
||||
end
|
||||
|
||||
it_should_behave_like 'a mutator'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue