Skip to content

Commit

Permalink
Mutate calls, yeah
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach committed Feb 25, 2012
1 parent 8793c9e commit 30fd1da
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/mutant/literal.rb
Expand Up @@ -120,5 +120,15 @@ def swap
@node
end
end

class Send < BaseLiteral
def swap
line = @node.line
@node = Rubinius::AST::NilLiteral.new(line)
@node
end
end

SendWithArguments = Send
end
end
161 changes: 161 additions & 0 deletions spec/functional/instance_method/call_spec.rb
@@ -0,0 +1,161 @@
require 'spec_helper'

describe 'Mutating calls' do
context 'for an instance method' do
context 'that contains a method call without arguments' do
before do
write_file 'life.rb', """
class Life
def helper
42
end
def answer
helper
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end

context 'that contains a method call with arguments' do
before do
write_file 'life.rb', """
class Life
def helper(num)
num + 2
end
def answer
helper(40)
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end

context 'that contains a method call with a block' do
before do
write_file 'life.rb', """
class Life
def helper
yield
end
def answer
helper { 42 }
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life#answer' do
specify { Life.new.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end
end
end
161 changes: 161 additions & 0 deletions spec/functional/singleton_method/call_spec.rb
@@ -0,0 +1,161 @@
require 'spec_helper'

describe 'Mutating calls' do
context 'for an instance method' do
context 'that contains a method call without arguments' do
before do
write_file 'life.rb', """
class Life
def self.helper
42
end
def self.answer
helper
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end

context 'that contains a method call with arguments' do
before do
write_file 'life.rb', """
class Life
def self.helper(num)
num + 2
end
def self.answer
helper(40)
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end

context 'that contains a method call with a block' do
before do
write_file 'life.rb', """
class Life
def self.helper
yield
end
def self.answer
helper { 42 }
end
end
"""
end

context 'with an expectation that the answer is 42' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.answer.should eq(42) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation passes' do
all_output.should include('passed')
end
end

context 'with an expectation that life respond to :answer' do
before do
write_file 'spec/life_spec.rb', """
$: << '.'
require 'life'
describe 'Life.answer' do
specify { Life.should respond_to(:answer) }
end
"""
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
end

specify 'the mutation fails' do
all_output.should include('failed')
end
end
end
end
end

0 comments on commit 30fd1da

Please sign in to comment.