mutant 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -1
- data/.travis.yml +6 -0
- data/Readme.md +13 -0
- data/exe/mutate +6 -0
- data/lib/mutant.rb +21 -0
- data/lib/mutant/extensions.rb +8 -0
- data/lib/mutant/formatter.rb +19 -0
- data/lib/mutant/implementation.rb +70 -0
- data/lib/mutant/literal.rb +134 -0
- data/lib/mutant/method.rb +31 -0
- data/lib/mutant/mutatee.rb +61 -0
- data/lib/mutant/mutation.rb +24 -0
- data/lib/mutant/mutator.rb +49 -0
- data/lib/mutant/node.rb +26 -0
- data/lib/mutant/random.rb +37 -0
- data/lib/mutant/reporter.rb +38 -0
- data/lib/mutant/runners/rspec.rb +26 -4
- data/lib/mutant/version.rb +1 -1
- data/mutant.gemspec +5 -3
- data/spec/functional/class_spec.rb +46 -0
- data/spec/functional/instance_method/array_spec.rb +53 -0
- data/spec/functional/instance_method/boolean_spec.rb +101 -0
- data/spec/functional/instance_method/call_spec.rb +161 -0
- data/spec/functional/instance_method/fixnum_spec.rb +53 -0
- data/spec/functional/instance_method/float_spec.rb +53 -0
- data/spec/functional/instance_method/hash_spec.rb +53 -0
- data/spec/functional/instance_method/if_spec.rb +57 -0
- data/spec/functional/instance_method/range_spec.rb +53 -0
- data/spec/functional/instance_method/regex_spec.rb +55 -0
- data/spec/functional/instance_method/string_spec.rb +53 -0
- data/spec/functional/instance_method/symbol_spec.rb +53 -0
- data/spec/functional/reporter/method_loaded_spec.rb +62 -0
- data/spec/functional/reporter/running_mutations_spec.rb +60 -0
- data/spec/functional/runners/rspec_spec.rb +26 -0
- data/spec/functional/singleton_method/array_spec.rb +53 -0
- data/spec/functional/singleton_method/boolean_spec.rb +101 -0
- data/spec/functional/singleton_method/call_spec.rb +161 -0
- data/spec/functional/singleton_method/fixnum_spec.rb +53 -0
- data/spec/functional/singleton_method/float_spec.rb +53 -0
- data/spec/functional/singleton_method/hash_spec.rb +53 -0
- data/spec/functional/singleton_method/if_spec.rb +57 -0
- data/spec/functional/singleton_method/range_spec.rb +53 -0
- data/spec/functional/singleton_method/regex_spec.rb +55 -0
- data/spec/functional/singleton_method/string_spec.rb +53 -0
- data/spec/functional/singleton_method/symbol_spec.rb +53 -0
- data/spec/mutant/extensions_spec.rb +13 -0
- data/spec/mutant/implementation_spec.rb +223 -0
- data/spec/mutant/literal_spec.rb +129 -0
- data/spec/mutant/mutatee_spec.rb +28 -0
- data/spec/mutant/node_spec.rb +41 -0
- data/spec/mutant/random_spec.rb +33 -0
- data/spec/mutant/reporter_spec.rb +17 -0
- data/spec/mutant_spec.rb +28 -0
- data/spec/spec_helper.rb +11 -3
- data/spec/support/example_group_helpers.rb +11 -0
- data/spec/support/example_helpers.rb +5 -0
- metadata +149 -81
- data/spec/functional/boolean_spec.rb +0 -49
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Reporter' do
|
4
|
+
describe 'running mutations' do
|
5
|
+
before do
|
6
|
+
write_file 'thing.rb', <<-CODE
|
7
|
+
class Thing
|
8
|
+
def alive?
|
9
|
+
a_string = 'foo'
|
10
|
+
a_symbol = :bar
|
11
|
+
a_range = 'a'..'c'
|
12
|
+
:symbol
|
13
|
+
true
|
14
|
+
end
|
15
|
+
end
|
16
|
+
CODE
|
17
|
+
write_file 'spec/thing_spec.rb', """
|
18
|
+
$: << '.'
|
19
|
+
require 'thing'
|
20
|
+
|
21
|
+
describe 'Thing#alive?' do
|
22
|
+
specify { Thing.new.should be_alive }
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
ENV['RANDOM_STRING'] = 'bar'
|
27
|
+
ENV['RANDOM_SYMBOL'] = 'foo'
|
28
|
+
ENV['RANDOM_RANGE_MIN'] = '1'
|
29
|
+
ENV['RANDOM_RANGE_MAX'] = '3'
|
30
|
+
|
31
|
+
mutate 'Thing#alive? spec/thing_spec.rb'
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
ENV['RANDOM_STRING'] = nil
|
36
|
+
ENV['RANDOM_SYMBOL'] = nil
|
37
|
+
ENV['RANDOM_RANGE_MIN'] = nil
|
38
|
+
ENV['RANDOM_RANGE_MAX'] = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'displays the details of each mutation as they are run' do
|
42
|
+
all_output.should include <<-STR
|
43
|
+
Mutating line 3
|
44
|
+
a_string = "foo" >>> a_string = "bar"
|
45
|
+
|
46
|
+
Mutating line 4
|
47
|
+
a_symbol = :bar >>> a_symbol = :foo
|
48
|
+
|
49
|
+
Mutating line 5
|
50
|
+
a_range = "a".."c" >>> a_range = 1..3
|
51
|
+
|
52
|
+
Mutating line 6
|
53
|
+
:symbol >>> :foo
|
54
|
+
|
55
|
+
Mutating line 7
|
56
|
+
true >>> false
|
57
|
+
STR
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Runners' do
|
4
|
+
describe 'RSpec' do
|
5
|
+
describe 'a spec that fails before mutations' do
|
6
|
+
before do
|
7
|
+
write_file 'spec/thing_spec.rb', """
|
8
|
+
class Thing
|
9
|
+
def alive?; true end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'Thing#alive?' do
|
13
|
+
specify { Thing.new.should_not be_alive }
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
mutate 'Thing#alive? spec/thing_spec.rb', false
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'causes the run to abort' do
|
20
|
+
all_output.should include(
|
21
|
+
'Initial run of specs failed... fix and run mutant again'
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mutating arrays' do
|
4
|
+
context 'for a singleton method' do
|
5
|
+
context 'that contains [1,2,3]' do
|
6
|
+
before do
|
7
|
+
write_file 'thing.rb', """
|
8
|
+
class Thing
|
9
|
+
def self.to_a
|
10
|
+
[1,2,3]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with an expectation that the array is [1,2,3]' do
|
17
|
+
before do
|
18
|
+
write_file 'spec/thing_spec.rb', """
|
19
|
+
$: << '.'
|
20
|
+
require 'thing'
|
21
|
+
|
22
|
+
describe 'Thing.to_a' do
|
23
|
+
specify { Thing.to_a.should eq([1,2,3]) }
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
mutate 'Thing.to_a 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 array responds to length' do
|
35
|
+
before do
|
36
|
+
write_file 'spec/thing_spec.rb', """
|
37
|
+
$: << '.'
|
38
|
+
require 'thing'
|
39
|
+
|
40
|
+
describe 'Thing.to_a' do
|
41
|
+
specify { Thing.to_a.should respond_to(:length) }
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
mutate 'Thing.to_a 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,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mutating booleans' do
|
4
|
+
context 'for a singleton method' do
|
5
|
+
context 'that contains `true`' do
|
6
|
+
before do
|
7
|
+
write_file 'thing.rb', """
|
8
|
+
class Thing
|
9
|
+
def self.alive?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'with an expectation that the return value is true' do
|
17
|
+
before do
|
18
|
+
write_file 'spec/thing_spec.rb', """
|
19
|
+
$: << '.'
|
20
|
+
require 'thing'
|
21
|
+
|
22
|
+
describe 'Thing.alive?' do
|
23
|
+
specify { Thing.should be_alive }
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
mutate 'Thing.alive? 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 true or false' do
|
35
|
+
before do
|
36
|
+
write_file 'spec/thing_spec.rb', """
|
37
|
+
$: << '.'
|
38
|
+
require 'thing'
|
39
|
+
|
40
|
+
describe 'Thing.alive?' do
|
41
|
+
specify { String(Thing.alive?).should =~ /true|false/ }
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
mutate 'Thing.alive? 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
|
+
|
53
|
+
context 'that contains `false`' do
|
54
|
+
before do
|
55
|
+
write_file 'thing.rb', """
|
56
|
+
class Thing
|
57
|
+
def self.alive?
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
"""
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'with an expectation that the return value is false' do
|
65
|
+
before do
|
66
|
+
write_file 'spec/thing_spec.rb', """
|
67
|
+
$: << '.'
|
68
|
+
require 'thing'
|
69
|
+
|
70
|
+
describe 'Thing.alive?' do
|
71
|
+
specify { Thing.should_not be_alive }
|
72
|
+
end
|
73
|
+
"""
|
74
|
+
mutate 'Thing.alive? spec/thing_spec.rb'
|
75
|
+
end
|
76
|
+
|
77
|
+
specify 'the mutation passes' do
|
78
|
+
all_output.should include('passed')
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context 'with an expectation that the return value is true or false' do
|
83
|
+
before do
|
84
|
+
write_file 'spec/thing_spec.rb', """
|
85
|
+
$: << '.'
|
86
|
+
require 'thing'
|
87
|
+
|
88
|
+
describe 'Thing.alive?' do
|
89
|
+
specify { String(Thing.alive?).should =~ /true|false/ }
|
90
|
+
end
|
91
|
+
"""
|
92
|
+
mutate 'Thing.alive? spec/thing_spec.rb'
|
93
|
+
end
|
94
|
+
|
95
|
+
specify 'the mutation fails' do
|
96
|
+
all_output.should include('failed')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mutating calls' do
|
4
|
+
context 'for an instance method' do
|
5
|
+
context 'that contains a method call without arguments' do
|
6
|
+
before do
|
7
|
+
write_file 'life.rb', """
|
8
|
+
class Life
|
9
|
+
def self.helper
|
10
|
+
42
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.answer
|
14
|
+
helper
|
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.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 life respond to :answer' do
|
39
|
+
before do
|
40
|
+
write_file 'spec/life_spec.rb', """
|
41
|
+
$: << '.'
|
42
|
+
require 'life'
|
43
|
+
|
44
|
+
describe 'Life.answer' do
|
45
|
+
specify { Life.should respond_to(:answer) }
|
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
|
+
|
57
|
+
context 'that contains a method call with arguments' do
|
58
|
+
before do
|
59
|
+
write_file 'life.rb', """
|
60
|
+
class Life
|
61
|
+
def self.helper(num)
|
62
|
+
num + 2
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.answer
|
66
|
+
helper(40)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
"""
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'with an expectation that the answer is 42' do
|
73
|
+
before do
|
74
|
+
write_file 'spec/life_spec.rb', """
|
75
|
+
$: << '.'
|
76
|
+
require 'life'
|
77
|
+
|
78
|
+
describe 'Life.answer' do
|
79
|
+
specify { Life.answer.should eq(42) }
|
80
|
+
end
|
81
|
+
"""
|
82
|
+
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
|
83
|
+
end
|
84
|
+
|
85
|
+
specify 'the mutation passes' do
|
86
|
+
all_output.should include('passed')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'with an expectation that life respond to :answer' do
|
91
|
+
before do
|
92
|
+
write_file 'spec/life_spec.rb', """
|
93
|
+
$: << '.'
|
94
|
+
require 'life'
|
95
|
+
|
96
|
+
describe 'Life.answer' do
|
97
|
+
specify { Life.should respond_to(:answer) }
|
98
|
+
end
|
99
|
+
"""
|
100
|
+
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
|
101
|
+
end
|
102
|
+
|
103
|
+
specify 'the mutation fails' do
|
104
|
+
all_output.should include('failed')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context 'that contains a method call with a block' do
|
110
|
+
before do
|
111
|
+
write_file 'life.rb', """
|
112
|
+
class Life
|
113
|
+
def self.helper
|
114
|
+
yield
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.answer
|
118
|
+
helper { 42 }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
"""
|
122
|
+
end
|
123
|
+
|
124
|
+
context 'with an expectation that the answer is 42' do
|
125
|
+
before do
|
126
|
+
write_file 'spec/life_spec.rb', """
|
127
|
+
$: << '.'
|
128
|
+
require 'life'
|
129
|
+
|
130
|
+
describe 'Life.answer' do
|
131
|
+
specify { Life.answer.should eq(42) }
|
132
|
+
end
|
133
|
+
"""
|
134
|
+
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
|
135
|
+
end
|
136
|
+
|
137
|
+
specify 'the mutation passes' do
|
138
|
+
all_output.should include('passed')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context 'with an expectation that life respond to :answer' do
|
143
|
+
before do
|
144
|
+
write_file 'spec/life_spec.rb', """
|
145
|
+
$: << '.'
|
146
|
+
require 'life'
|
147
|
+
|
148
|
+
describe 'Life.answer' do
|
149
|
+
specify { Life.should respond_to(:answer) }
|
150
|
+
end
|
151
|
+
"""
|
152
|
+
run_simple '../../bin/mutate Life.answer spec/life_spec.rb'
|
153
|
+
end
|
154
|
+
|
155
|
+
specify 'the mutation fails' do
|
156
|
+
all_output.should include('failed')
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Mutating fixnums' do
|
4
|
+
context 'for a singleton method' do
|
5
|
+
context 'that contains 42' do
|
6
|
+
before do
|
7
|
+
write_file 'life.rb', """
|
8
|
+
class Life
|
9
|
+
def self.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.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.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
|