Permalink
Browse files

Mutate calls, yeah

  • Loading branch information...
1 parent 8793c9e commit 30fd1daca4bcb12428093476a58bbfdba633ebf5 @txus committed Feb 25, 2012
Showing with 332 additions and 0 deletions.
  1. +10 −0 lib/mutant/literal.rb
  2. +161 −0 spec/functional/instance_method/call_spec.rb
  3. +161 −0 spec/functional/singleton_method/call_spec.rb
View
@@ -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
@@ -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
@@ -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.