Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add instance variable assignment

  • Loading branch information...
commit ee0c7c8302a6f086c11b5522cd8484a4e2cfc67e 1 parent 6d0cbc6
Josep M. Bach authored
13 lib/mutant/literal.rb
@@ -114,6 +114,19 @@ def literal_class
114 114 end
115 115 end
116 116
  117 + class InstanceVariableAssignment < BaseLiteral
  118 + def swap
  119 + @node.value = literal_class.new(@node.value.clone).swap
  120 + @node
  121 + end
  122 +
  123 + private
  124 +
  125 + def literal_class
  126 + Module.nesting[1].literal_class(@node.value)
  127 + end
  128 + end
  129 +
117 130 class If < BaseLiteral
118 131 def swap
119 132 @node.body, @node.else = @node.else, @node.body
62 spec/functional/instance_method/ivar_assign_spec.rb
... ... @@ -0,0 +1,62 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'Mutating instance variable assignments' do
  4 + context 'for an instance method' do
  5 + context 'that contains @a = 1' do
  6 + before do
  7 + write_file 'thing.rb', """
  8 + class Thing
  9 + attr_reader :a
  10 + def set_a
  11 + @a = 1
  12 + end
  13 + end
  14 + """
  15 + end
  16 +
  17 + context 'with an expectation that a will be set to 1' do
  18 + before do
  19 + write_file 'spec/thing_spec.rb', """
  20 + $: << '.'
  21 + require 'thing'
  22 +
  23 + describe 'Thing#set_a' do
  24 + specify do
  25 + thing = Thing.new
  26 + thing.set_a
  27 + thing.a.should eq(1)
  28 + end
  29 + end
  30 + """
  31 + mutate 'Thing#set_a spec/thing_spec.rb'
  32 + end
  33 +
  34 + specify 'the mutation passes' do
  35 + all_output.should include('passed')
  36 + end
  37 + end
  38 +
  39 + context 'with an expectation that a will bet set to some number' do
  40 + before do
  41 + write_file 'spec/thing_spec.rb', """
  42 + $: << '.'
  43 + require 'thing'
  44 +
  45 + describe 'Thing#set_a' do
  46 + specify do
  47 + thing = Thing.new
  48 + thing.set_a
  49 + thing.a.should be_kind_of(Fixnum)
  50 + end
  51 + end
  52 + """
  53 + mutate 'Thing#set_a spec/thing_spec.rb'
  54 + end
  55 +
  56 + specify 'the mutation fails' do
  57 + all_output.should include('failed')
  58 + end
  59 + end
  60 + end
  61 + end
  62 +end
60 spec/functional/singleton_method/ivar_assign_spec.rb
... ... @@ -0,0 +1,60 @@
  1 +require 'spec_helper'
  2 +
  3 +describe 'Mutating instance variable assignments' do
  4 + context 'for an instance method' do
  5 + context 'that contains @a = 1' do
  6 + before do
  7 + write_file 'thing.rb', """
  8 + class Thing
  9 + class << self; attr_reader :a; end
  10 + def self.set_a
  11 + @a = 1
  12 + end
  13 + end
  14 + """
  15 + end
  16 +
  17 + context 'with an expectation that a will be set to 1' do
  18 + before do
  19 + write_file 'spec/thing_spec.rb', """
  20 + $: << '.'
  21 + require 'thing'
  22 +
  23 + describe 'Thing.set_a' do
  24 + specify do
  25 + Thing.set_a
  26 + Thing.a.should eq(1)
  27 + end
  28 + end
  29 + """
  30 + mutate 'Thing.set_a spec/thing_spec.rb'
  31 + end
  32 +
  33 + specify 'the mutation passes' do
  34 + all_output.should include('passed')
  35 + end
  36 + end
  37 +
  38 + context 'with an expectation that a will bet set to some number' do
  39 + before do
  40 + write_file 'spec/thing_spec.rb', """
  41 + $: << '.'
  42 + require 'thing'
  43 +
  44 + describe 'Thing.set_a' do
  45 + specify do
  46 + Thing.set_a
  47 + Thing.a.should be_kind_of(Fixnum)
  48 + end
  49 + end
  50 + """
  51 + mutate 'Thing.set_a spec/thing_spec.rb'
  52 + end
  53 +
  54 + specify 'the mutation fails' do
  55 + all_output.should include('failed')
  56 + end
  57 + end
  58 + end
  59 + end
  60 +end

0 comments on commit ee0c7c8

Please sign in to comment.
Something went wrong with that request. Please try again.