Permalink
Browse files

Add mutation for Fixnums.

  • Loading branch information...
Josep M. Bach
Josep M. Bach committed Feb 11, 2012
1 parent ffe4656 commit c1406465b6217df128e0f05d419fb8d567abb26b
View
@@ -45,6 +45,13 @@ def swap
end
end
+ class FixnumLiteral < BaseLiteral
+ def swap
+ @node.value = Random.fixnum
+ @node
+ end
+ end
+
class Range < BaseLiteral
def swap
range = Random.range
@@ -67,4 +74,4 @@ def literal_class
end
end
end
-end
+end
View
@@ -13,6 +13,11 @@ def self.symbol
).to_sym
end
+ def self.fixnum
+ ENV['RANDOM_FIXNUM'] or
+ rand(100)
+ end
+
def self.range
if ENV['RANDOM_RANGE_MIN'] and ENV['RANDOM_RANGE_MAX']
min, max = ENV['RANDOM_RANGE_MIN'].to_i, ENV['RANDOM_RANGE_MAX'].to_i
@@ -24,4 +29,4 @@ def self.range
Range.new(min, max)
end
end
-end
+end
@@ -0,0 +1,51 @@
+require 'spec_helper'
+
+describe 'Mutating fixnums' do
+ context 'for an instance method' do
+ context 'that contains 42' do
+ before do
+ write_file 'life.rb', """
+ class Life
+ def answer
+ 42
+ end
+ end
+ """
+ end
+
+ context 'with an expectation that the return value 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 the return value is a Fixnum' do
+ before do
+ write_file 'spec/life_spec.rb', """
+ require 'life'
+
+ describe 'Life#answer' do
+ specify { Life.new.answer.should be_a(Fixnum) }
+ 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,51 @@
+require 'spec_helper'
+
+describe 'Mutating fixnums' do
+ context 'for a singleton method' do
+ context 'that contains 42' do
+ before do
+ write_file 'life.rb', """
+ class Life
+ def self.answer
+ 42
+ end
+ end
+ """
+ end
+
+ context 'with an expectation that the return value 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 the return value is a Fixnum' do
+ before do
+ write_file 'spec/life_spec.rb', """
+ require 'life'
+
+ describe 'Life#answer' do
+ specify { Life.answer.should be_a(Fixnum) }
+ 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
@@ -72,6 +72,17 @@
end
end
+ describe Mutant::Literal::FixnumLiteral do
+ describe '#swap' do
+ let(:node) { double('node') }
+
+ it "sets the node's value to a random fixnum" do
+ node.should_receive(:value=).with(instance_of(Fixnum))
+ Mutant::Literal::FixnumLiteral.new(node).swap.should eq(node)
+ end
+ end
+ end
+
describe Mutant::Literal::Range do
describe '#swap' do
let(:node) { double('node', :line => 1) }
@@ -104,4 +115,4 @@
end
end
end
-end
+end
@@ -13,9 +13,15 @@
end
end
+ describe '.fixnum' do
+ it 'returns a random fixnum' do
+ Mutant::Random.fixnum.should be_a(Fixnum)
+ end
+ end
+
describe '.range' do
it 'returns a random range' do
Mutant::Random.range.should be_a(Range)
end
end
-end
+end

0 comments on commit c140646

Please sign in to comment.