mutant 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.gitignore +5 -0
  2. data/.rvmrc +1 -1
  3. data/.travis.yml +6 -0
  4. data/Readme.md +13 -0
  5. data/exe/mutate +6 -0
  6. data/lib/mutant.rb +21 -0
  7. data/lib/mutant/extensions.rb +8 -0
  8. data/lib/mutant/formatter.rb +19 -0
  9. data/lib/mutant/implementation.rb +70 -0
  10. data/lib/mutant/literal.rb +134 -0
  11. data/lib/mutant/method.rb +31 -0
  12. data/lib/mutant/mutatee.rb +61 -0
  13. data/lib/mutant/mutation.rb +24 -0
  14. data/lib/mutant/mutator.rb +49 -0
  15. data/lib/mutant/node.rb +26 -0
  16. data/lib/mutant/random.rb +37 -0
  17. data/lib/mutant/reporter.rb +38 -0
  18. data/lib/mutant/runners/rspec.rb +26 -4
  19. data/lib/mutant/version.rb +1 -1
  20. data/mutant.gemspec +5 -3
  21. data/spec/functional/class_spec.rb +46 -0
  22. data/spec/functional/instance_method/array_spec.rb +53 -0
  23. data/spec/functional/instance_method/boolean_spec.rb +101 -0
  24. data/spec/functional/instance_method/call_spec.rb +161 -0
  25. data/spec/functional/instance_method/fixnum_spec.rb +53 -0
  26. data/spec/functional/instance_method/float_spec.rb +53 -0
  27. data/spec/functional/instance_method/hash_spec.rb +53 -0
  28. data/spec/functional/instance_method/if_spec.rb +57 -0
  29. data/spec/functional/instance_method/range_spec.rb +53 -0
  30. data/spec/functional/instance_method/regex_spec.rb +55 -0
  31. data/spec/functional/instance_method/string_spec.rb +53 -0
  32. data/spec/functional/instance_method/symbol_spec.rb +53 -0
  33. data/spec/functional/reporter/method_loaded_spec.rb +62 -0
  34. data/spec/functional/reporter/running_mutations_spec.rb +60 -0
  35. data/spec/functional/runners/rspec_spec.rb +26 -0
  36. data/spec/functional/singleton_method/array_spec.rb +53 -0
  37. data/spec/functional/singleton_method/boolean_spec.rb +101 -0
  38. data/spec/functional/singleton_method/call_spec.rb +161 -0
  39. data/spec/functional/singleton_method/fixnum_spec.rb +53 -0
  40. data/spec/functional/singleton_method/float_spec.rb +53 -0
  41. data/spec/functional/singleton_method/hash_spec.rb +53 -0
  42. data/spec/functional/singleton_method/if_spec.rb +57 -0
  43. data/spec/functional/singleton_method/range_spec.rb +53 -0
  44. data/spec/functional/singleton_method/regex_spec.rb +55 -0
  45. data/spec/functional/singleton_method/string_spec.rb +53 -0
  46. data/spec/functional/singleton_method/symbol_spec.rb +53 -0
  47. data/spec/mutant/extensions_spec.rb +13 -0
  48. data/spec/mutant/implementation_spec.rb +223 -0
  49. data/spec/mutant/literal_spec.rb +129 -0
  50. data/spec/mutant/mutatee_spec.rb +28 -0
  51. data/spec/mutant/node_spec.rb +41 -0
  52. data/spec/mutant/random_spec.rb +33 -0
  53. data/spec/mutant/reporter_spec.rb +17 -0
  54. data/spec/mutant_spec.rb +28 -0
  55. data/spec/spec_helper.rb +11 -3
  56. data/spec/support/example_group_helpers.rb +11 -0
  57. data/spec/support/example_helpers.rb +5 -0
  58. metadata +149 -81
  59. data/spec/functional/boolean_spec.rb +0 -49
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating fixnums' do
4
+ context 'for an instance method' do
5
+ context 'that contains 42' do
6
+ before do
7
+ write_file 'life.rb', """
8
+ class Life
9
+ def answer
10
+ 42
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that the return value is 42' do
17
+ before do
18
+ write_file 'spec/life_spec.rb', """
19
+ $: << '.'
20
+ require 'life'
21
+
22
+ describe 'Life#answer' do
23
+ specify { Life.new.answer.should eq(42) }
24
+ end
25
+ """
26
+ mutate 'Life#answer spec/life_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context 'with an expectation that the return value is a Fixnum' do
35
+ before do
36
+ write_file 'spec/life_spec.rb', """
37
+ $: << '.'
38
+ require 'life'
39
+
40
+ describe 'Life#answer' do
41
+ specify { Life.new.answer.should be_a(Fixnum) }
42
+ end
43
+ """
44
+ mutate 'Life#answer spec/life_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating floats' do
4
+ context 'for an instance method' do
5
+ context 'that contains 42.5' do
6
+ before do
7
+ write_file 'life.rb', """
8
+ class Life
9
+ def answer
10
+ 42.5
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that the return value is 42.5' do
17
+ before do
18
+ write_file 'spec/life_spec.rb', """
19
+ $: << '.'
20
+ require 'life'
21
+
22
+ describe 'Life#answer' do
23
+ specify { Life.new.answer.should eq(42.5) }
24
+ end
25
+ """
26
+ mutate 'Life#answer spec/life_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context 'with an expectation that the return value is a Float' do
35
+ before do
36
+ write_file 'spec/life_spec.rb', """
37
+ $: << '.'
38
+ require 'life'
39
+
40
+ describe 'Life#answer' do
41
+ specify { Life.new.answer.should be_a(Float) }
42
+ end
43
+ """
44
+ mutate 'Life#answer spec/life_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating hashes' do
4
+ context 'for an instance method' do
5
+ context 'that contains {:foo => {:bar => 3}}' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def to_hash
10
+ {:foo => {:bar => 3}}
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that hash[:foo][:bar] is 3' do
17
+ before do
18
+ write_file 'spec/thing_spec.rb', """
19
+ $: << '.'
20
+ require 'thing'
21
+
22
+ describe 'Thing#to_hash' do
23
+ specify { Thing.new.to_hash[:foo][:bar].should eq(3) }
24
+ end
25
+ """
26
+ mutate 'Thing#to_hash spec/thing_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context 'with an expectation that hash[:foo][:bar] is a Fixnum' do
35
+ before do
36
+ write_file 'spec/thing_spec.rb', """
37
+ $: << '.'
38
+ require 'thing'
39
+
40
+ describe 'Thing#to_hash' do
41
+ specify { Thing.new.to_hash[:foo][:bar].should be_kind_of(Fixnum) }
42
+ end
43
+ """
44
+ mutate 'Thing#to_hash spec/thing_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating If clauses' do
4
+ context 'for an instance method' do
5
+ context 'that contains an if-else that returns 42' do
6
+ before do
7
+ write_file 'life.rb', """
8
+ class Life
9
+ def answer
10
+ if true
11
+ 42
12
+ else
13
+ 24
14
+ end
15
+ end
16
+ end
17
+ """
18
+ end
19
+
20
+ context 'with an expectation that the answer is 42' do
21
+ before do
22
+ write_file 'spec/life_spec.rb', """
23
+ $: << '.'
24
+ require 'life'
25
+
26
+ describe 'Life#answer' do
27
+ specify { Life.new.answer.should eq(42) }
28
+ end
29
+ """
30
+ run_simple '../../bin/mutate Life#answer spec/life_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 the answer is a Fixnum' do
39
+ before do
40
+ write_file 'spec/life_spec.rb', """
41
+ $: << '.'
42
+ require 'life'
43
+
44
+ describe 'Life#answer' do
45
+ specify { Life.new.answer.should be_kind_of(Fixnum) }
46
+ end
47
+ """
48
+ run_simple '../../bin/mutate Life#answer spec/life_spec.rb'
49
+ end
50
+
51
+ specify 'the mutation fails' do
52
+ all_output.should include('failed')
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating ranges' do
4
+ context 'for an instance method' do
5
+ context 'that contains a..z' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def a_range
10
+ 'a'..'z'
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context "with an expectation that the return value is `'a'..'z'`" do
17
+ before do
18
+ write_file 'spec/thing_spec.rb', """
19
+ $: << '.'
20
+ require 'thing'
21
+
22
+ describe 'Thing#a_range' do
23
+ specify { Thing.new.a_range.should eq('a'..'z') }
24
+ end
25
+ """
26
+ mutate 'Thing#a_range spec/thing_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context "with an expectation that the return value is a range" do
35
+ before do
36
+ write_file 'spec/thing_spec.rb', """
37
+ $: << '.'
38
+ require 'thing'
39
+
40
+ describe 'Thing#a_range' do
41
+ specify { Thing.new.a_range.should be_a(Range) }
42
+ end
43
+ """
44
+ mutate 'Thing#a_range spec/thing_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating regexen' do
4
+ context 'for an instance method' do
5
+ context 'that contains `.*`' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def regex
10
+ /.*/
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that a string matches the regex' do
17
+ before do
18
+ write_file 'spec/thing_spec.rb', """
19
+ $: << '.'
20
+ require 'thing'
21
+
22
+ describe 'Thing#regex' do
23
+ specify do
24
+ 'hello'.should match(Thing.new.regex)
25
+ end
26
+ end
27
+ """
28
+ mutate 'Thing#regex spec/thing_spec.rb'
29
+ end
30
+
31
+ specify 'the mutation passes' do
32
+ all_output.should include('passed')
33
+ end
34
+ end
35
+
36
+ context 'with an expectation that the regex is a Regex' do
37
+ before do
38
+ write_file 'spec/thing_spec.rb', """
39
+ $: << '.'
40
+ require 'thing'
41
+
42
+ describe 'Thing#regex' do
43
+ specify { Thing.new.regex.should be_kind_of(Regexp) }
44
+ end
45
+ """
46
+ mutate 'Thing#regex spec/thing_spec.rb'
47
+ end
48
+
49
+ specify 'the mutation fails' do
50
+ all_output.should include('failed')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating strings' do
4
+ context 'for an instance method' do
5
+ context 'that contains "foo"' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def a_string
10
+ 'foo'
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that the return value is "foo"' do
17
+ before do
18
+ write_file 'spec/thing_spec.rb', """
19
+ $: << '.'
20
+ require 'thing'
21
+
22
+ describe 'Thing#a_string' do
23
+ specify { Thing.new.a_string.should eq('foo') }
24
+ end
25
+ """
26
+ mutate 'Thing#a_string spec/thing_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context 'with an expectation that the return value is a string' do
35
+ before do
36
+ write_file 'spec/thing_spec.rb', """
37
+ $: << '.'
38
+ require 'thing'
39
+
40
+ describe 'Thing#a_string' do
41
+ specify { Thing.new.a_string.should be_a(String) }
42
+ end
43
+ """
44
+ mutate 'Thing#a_string spec/thing_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Mutating symbols' do
4
+ context 'for an instance method' do
5
+ context 'that contains :foo' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def a_symbol
10
+ :foo
11
+ end
12
+ end
13
+ """
14
+ end
15
+
16
+ context 'with an expectation that the return value is :foo' do
17
+ before do
18
+ write_file 'spec/thing_spec.rb', """
19
+ $: << '.'
20
+ require 'thing'
21
+
22
+ describe 'Thing#a_symbol' do
23
+ specify { Thing.new.a_symbol.should eq(:foo) }
24
+ end
25
+ """
26
+ mutate 'Thing#a_symbol spec/thing_spec.rb'
27
+ end
28
+
29
+ specify 'the mutation passes' do
30
+ all_output.should include('passed')
31
+ end
32
+ end
33
+
34
+ context 'with an expectation that the return value is a symbol' do
35
+ before do
36
+ write_file 'spec/thing_spec.rb', """
37
+ $: << '.'
38
+ require 'thing'
39
+
40
+ describe 'Thing#a_symbol' do
41
+ specify { Thing.new.a_symbol.should be_a(Symbol) }
42
+ end
43
+ """
44
+ mutate 'Thing#a_symbol spec/thing_spec.rb'
45
+ end
46
+
47
+ specify 'the mutation fails' do
48
+ all_output.should include('failed')
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Reporter' do
4
+ describe 'method loaded' do
5
+ context 'that has mutations' do
6
+ before do
7
+ write_file 'thing.rb', """
8
+ class Thing
9
+ def alive?
10
+ true
11
+ end
12
+ end
13
+ """
14
+ write_file 'spec/thing_spec.rb', """
15
+ $: << '.'
16
+ require 'thing'
17
+
18
+ describe 'Thing#alive?' do
19
+ specify { Thing.new.should be_alive }
20
+ end
21
+ """
22
+ mutate 'Thing#alive? spec/thing_spec.rb'
23
+ end
24
+
25
+ it 'displays the number of possible mutations' do
26
+ all_output.should include <<-STR
27
+ **********************************************************************
28
+ *** Thing#alive? loaded with 1 possible mutation
29
+ **********************************************************************
30
+ STR
31
+ end
32
+ end
33
+
34
+ context 'that has no mutations' do
35
+ before do
36
+ write_file 'thing.rb', """
37
+ class Thing
38
+ def alive?
39
+ end
40
+ end
41
+ """
42
+ write_file 'spec/thing_spec.rb', """
43
+ $: << '.'
44
+ require 'thing'
45
+
46
+ describe 'Thing#alive?' do
47
+ specify { Thing.new.alive?.should be_nil }
48
+ end
49
+ """
50
+ mutate 'Thing#alive? spec/thing_spec.rb'
51
+ end
52
+
53
+ it 'displays a warning that there are no possible mutations' do
54
+ all_output.should include <<-STR
55
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
56
+ !!! Thing#alive? has no possible mutations
57
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
58
+ STR
59
+ end
60
+ end
61
+ end
62
+ end