mutant 0.5.17 → 0.5.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/Changelog.md +6 -0
  3. data/Rakefile +13 -0
  4. data/config/flay.yml +1 -1
  5. data/config/reek.yml +8 -1
  6. data/lib/mutant.rb +18 -3
  7. data/lib/mutant/cli.rb +6 -3
  8. data/lib/mutant/constants.rb +3 -0
  9. data/lib/mutant/expression.rb +110 -0
  10. data/lib/mutant/expression/method.rb +92 -0
  11. data/lib/mutant/expression/namespace.rb +90 -0
  12. data/lib/mutant/matcher/namespace.rb +3 -4
  13. data/lib/mutant/meta.rb +31 -0
  14. data/lib/mutant/meta/example.rb +152 -0
  15. data/lib/mutant/meta/example/dsl.rb +105 -0
  16. data/lib/mutant/mutator/node.rb +6 -6
  17. data/lib/mutant/mutator/node/arguments.rb +1 -1
  18. data/lib/mutant/mutator/node/begin.rb +1 -1
  19. data/lib/mutant/mutator/node/const.rb +1 -1
  20. data/lib/mutant/mutator/node/if.rb +6 -6
  21. data/lib/mutant/mutator/node/literal/array.rb +2 -2
  22. data/lib/mutant/mutator/node/literal/hash.rb +2 -2
  23. data/lib/mutant/mutator/node/literal/range.rb +3 -3
  24. data/lib/mutant/mutator/node/literal/regex.rb +2 -2
  25. data/lib/mutant/mutator/node/literal/symbol.rb +1 -1
  26. data/lib/mutant/mutator/node/op_asgn.rb +1 -3
  27. data/lib/mutant/mutator/node/or_asgn.rb +31 -0
  28. data/lib/mutant/mutator/node/send.rb +1 -1
  29. data/lib/mutant/mutator/node/send/attribute_assignment.rb +1 -1
  30. data/lib/mutant/reporter/cli/report/mutation.rb +11 -1
  31. data/lib/mutant/strategy.rb +1 -1
  32. data/lib/mutant/version.rb +1 -1
  33. data/meta/and.rb +12 -0
  34. data/meta/and_asgn.rb +12 -0
  35. data/meta/array.rb +30 -0
  36. data/meta/begin.rb +15 -0
  37. data/meta/binary.rb +12 -0
  38. data/meta/block.rb +55 -0
  39. data/meta/block_pass.rb +8 -0
  40. data/meta/blockarg.rb +10 -0
  41. data/meta/boolean.rb +15 -0
  42. data/meta/break.rb +11 -0
  43. data/meta/case.rb +303 -0
  44. data/meta/casgn.rb +9 -0
  45. data/meta/cbase.rb +8 -0
  46. data/meta/const.rb +9 -0
  47. data/meta/cvar.rb +7 -0
  48. data/meta/cvasgn.rb +10 -0
  49. data/meta/define.rb +118 -0
  50. data/meta/defined.rb +7 -0
  51. data/meta/dstr.rb +10 -0
  52. data/meta/dsym.rb +11 -0
  53. data/meta/ensure.rb +9 -0
  54. data/meta/fixnum.rb +19 -0
  55. data/meta/float.rb +38 -0
  56. data/meta/gvar.rb +7 -0
  57. data/meta/gvasgn.rb +10 -0
  58. data/meta/hash.rb +25 -0
  59. data/meta/if.rb +57 -0
  60. data/meta/ivasgn.rb +10 -0
  61. data/meta/kwbegin.rb +9 -0
  62. data/meta/lvar.rb +14 -0
  63. data/meta/lvasgn.rb +10 -0
  64. data/meta/masgn.rb +7 -0
  65. data/meta/match_current_line.rb +14 -0
  66. data/meta/next.rb +11 -0
  67. data/meta/nil.rb +5 -0
  68. data/meta/nthref.rb +14 -0
  69. data/meta/op_assgn.rb +15 -0
  70. data/meta/or_asgn.rb +22 -0
  71. data/meta/range.rb +41 -0
  72. data/meta/redo.rb +5 -0
  73. data/meta/regex.rb +20 -0
  74. data/meta/rescue.rb +38 -0
  75. data/meta/restarg.rb +11 -0
  76. data/meta/return.rb +15 -0
  77. data/meta/self.rb +7 -0
  78. data/meta/send.rb +240 -0
  79. data/meta/string.rb +7 -0
  80. data/meta/super.rb +26 -0
  81. data/meta/symbol.rb +8 -0
  82. data/meta/unless.rb +15 -0
  83. data/meta/while.rb +24 -0
  84. data/meta/yield.rb +10 -0
  85. data/mutant.gemspec +1 -0
  86. data/spec/integration/mutant/corpus_spec.rb +29 -25
  87. data/spec/spec_helper.rb +2 -0
  88. data/spec/support/mutation_verifier.rb +1 -0
  89. data/spec/unit/mutant/cli_new_spec.rb +6 -6
  90. data/spec/unit/mutant/expression/method_spec.rb +50 -0
  91. data/spec/unit/mutant/expression/namespace/flat_spec.rb +32 -0
  92. data/spec/unit/mutant/expression/namespace/recursive_spec.rb +37 -0
  93. data/spec/unit/mutant/matcher/namespace_spec.rb +2 -2
  94. data/spec/unit/mutant/mutation_spec.rb +1 -1
  95. data/spec/unit/mutant/mutator/node_spec.rb +14 -0
  96. metadata +123 -139
  97. data/lib/mutant/cli/classifier.rb +0 -139
  98. data/lib/mutant/cli/classifier/method.rb +0 -105
  99. data/lib/mutant/cli/classifier/namespace.rb +0 -49
  100. data/spec/unit/mutant/cli/classifier/method_spec.rb +0 -77
  101. data/spec/unit/mutant/cli/classifier/namespace/flat_spec.rb +0 -58
  102. data/spec/unit/mutant/cli/classifier/namespace/recursive_spec.rb +0 -58
  103. data/spec/unit/mutant/cli/classifier_spec.rb +0 -59
  104. data/spec/unit/mutant/mutator/node/and_asgn_spec.rb +0 -19
  105. data/spec/unit/mutant/mutator/node/begin_spec.rb +0 -32
  106. data/spec/unit/mutant/mutator/node/binary_spec.rb +0 -41
  107. data/spec/unit/mutant/mutator/node/block_pass_spec.rb +0 -15
  108. data/spec/unit/mutant/mutator/node/block_spec.rb +0 -83
  109. data/spec/unit/mutant/mutator/node/blockarg_spec.rb +0 -17
  110. data/spec/unit/mutant/mutator/node/case_spec.rb +0 -329
  111. data/spec/unit/mutant/mutator/node/cbase_spec.rb +0 -15
  112. data/spec/unit/mutant/mutator/node/conditional_loop_spec.rb +0 -58
  113. data/spec/unit/mutant/mutator/node/const_spec.rb +0 -16
  114. data/spec/unit/mutant/mutator/node/define_spec.rb +0 -171
  115. data/spec/unit/mutant/mutator/node/defined_spec.rb +0 -14
  116. data/spec/unit/mutant/mutator/node/dstr_spec.rb +0 -17
  117. data/spec/unit/mutant/mutator/node/dsym_spec.rb +0 -18
  118. data/spec/unit/mutant/mutator/node/ensure_spec.rb +0 -16
  119. data/spec/unit/mutant/mutator/node/if_spec.rb +0 -77
  120. data/spec/unit/mutant/mutator/node/kwbegin_spec.rb +0 -16
  121. data/spec/unit/mutant/mutator/node/literal/array_spec.rb +0 -47
  122. data/spec/unit/mutant/mutator/node/literal/boolean_spec.rb +0 -25
  123. data/spec/unit/mutant/mutator/node/literal/fixnum_spec.rb +0 -13
  124. data/spec/unit/mutant/mutator/node/literal/float_spec.rb +0 -53
  125. data/spec/unit/mutant/mutator/node/literal/hash_spec.rb +0 -33
  126. data/spec/unit/mutant/mutator/node/literal/nil_spec.rb +0 -10
  127. data/spec/unit/mutant/mutator/node/literal/range_spec.rb +0 -56
  128. data/spec/unit/mutant/mutator/node/literal/regex_spec.rb +0 -36
  129. data/spec/unit/mutant/mutator/node/literal/string_spec.rb +0 -15
  130. data/spec/unit/mutant/mutator/node/literal/symbol_spec.rb +0 -15
  131. data/spec/unit/mutant/mutator/node/loop_ctrl_spec.rb +0 -37
  132. data/spec/unit/mutant/mutator/node/masgn_spec.rb +0 -14
  133. data/spec/unit/mutant/mutator/node/match_current_line_spec.rb +0 -21
  134. data/spec/unit/mutant/mutator/node/named_value/access_spec.rb +0 -78
  135. data/spec/unit/mutant/mutator/node/named_value/constant_assignment_spec.rb +0 -16
  136. data/spec/unit/mutant/mutator/node/named_value/variable_assignment_spec.rb +0 -61
  137. data/spec/unit/mutant/mutator/node/nthref_spec.rb +0 -19
  138. data/spec/unit/mutant/mutator/node/op_assgn_spec.rb +0 -22
  139. data/spec/unit/mutant/mutator/node/or_asgn_spec.rb +0 -19
  140. data/spec/unit/mutant/mutator/node/redo_spec.rb +0 -10
  141. data/spec/unit/mutant/mutator/node/rescue_spec.rb +0 -63
  142. data/spec/unit/mutant/mutator/node/restarg_spec.rb +0 -18
  143. data/spec/unit/mutant/mutator/node/return_spec.rb +0 -31
  144. data/spec/unit/mutant/mutator/node/send_spec.rb +0 -382
  145. data/spec/unit/mutant/mutator/node/super_spec.rb +0 -46
  146. data/spec/unit/mutant/mutator/node/yield_spec.rb +0 -17
@@ -1,61 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::NamedValue::VariableAssignment, 'mutations' do
6
- context 'global variable' do
7
- let(:source) { '$a = true' }
8
-
9
- let(:mutations) do
10
- mutations = []
11
- mutations << '$a__mutant__ = true'
12
- mutations << '$a = false'
13
- mutations << '$a = nil'
14
- mutations << 'nil'
15
- end
16
-
17
- it_should_behave_like 'a mutator'
18
- end
19
-
20
- context 'class variable' do
21
- let(:source) { '@@a = true' }
22
-
23
- let(:mutations) do
24
- mutations = []
25
- mutations << '@@a__mutant__ = true'
26
- mutations << '@@a = false'
27
- mutations << '@@a = nil'
28
- mutations << 'nil'
29
- end
30
-
31
- it_should_behave_like 'a mutator'
32
- end
33
-
34
- context 'instance variable' do
35
- let(:source) { '@a = true' }
36
-
37
- let(:mutations) do
38
- mutations = []
39
- mutations << '@a__mutant__ = true'
40
- mutations << '@a = false'
41
- mutations << '@a = nil'
42
- mutations << 'nil'
43
- end
44
-
45
- it_should_behave_like 'a mutator'
46
- end
47
-
48
- context 'local variable' do
49
- let(:source) { 'a = true' }
50
-
51
- let(:mutations) do
52
- mutations = []
53
- mutations << 'a__mutant__ = true'
54
- mutations << 'a = false'
55
- mutations << 'a = nil'
56
- mutations << 'nil'
57
- end
58
-
59
- it_should_behave_like 'a mutator'
60
- end
61
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator, 'nthref' do
6
- context '$1' do
7
- let(:source) { '$1' }
8
- let(:mutations) { ['$2'] }
9
-
10
- it_should_behave_like 'a mutator'
11
- end
12
-
13
- context '$2' do
14
- let(:source) { '$2' }
15
- let(:mutations) { ['$3', '$1'] }
16
-
17
- it_should_behave_like 'a mutator'
18
- end
19
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::Generic, 'op_asgn' do
6
- let(:source) { '@a.b += 1' }
7
-
8
- let(:mutations) do
9
- mutations = []
10
- mutations << '@a.b += -1'
11
- mutations << '@a.b += 2'
12
- mutations << '@a.b += 0'
13
- mutations << '@a.b += nil'
14
- mutations << 'nil.b += 1'
15
- mutations << 'nil'
16
- # TODO: fix invalid AST
17
- # This should not get emitted as invalid AST with valid unparsed source
18
- mutations << s(:op_asgn, s(:ivar, :@a), :+, s(:int, 1))
19
- end
20
-
21
- it_should_behave_like 'a mutator'
22
- end
@@ -1,19 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::OpAsgn, 'or_asgn' do
6
- let(:source) { 'a ||= 1' }
7
-
8
- let(:mutations) do
9
- mutations = []
10
- mutations << 'a__mutant__ ||= 1'
11
- mutations << 'a ||= nil'
12
- mutations << 'a ||= 0'
13
- mutations << 'a ||= -1'
14
- mutations << 'a ||= 2'
15
- mutations << 'nil'
16
- end
17
-
18
- it_should_behave_like 'a mutator'
19
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::Generic, 'redo' do
6
- let(:source) { 'redo' }
7
- let(:mutations) { [] }
8
-
9
- it_should_behave_like 'a mutator'
10
- end
@@ -1,63 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::Generic, 'rescue' do
6
-
7
- context 'multiple exception selectors and assignment' do
8
- let(:source) { 'begin; rescue ExceptionA, ExceptionB => error; true; end' }
9
-
10
- let(:mutations) do
11
- mutations = []
12
- mutations << 'nil'
13
- mutations << 'begin; rescue ExceptionA, ExceptionB; true; end'
14
- mutations << 'begin; rescue ExceptionA, ExceptionB => error; false; end'
15
- mutations << 'begin; rescue ExceptionA, ExceptionB => error; nil; end'
16
- mutations << 'begin; rescue ExceptionA => error; true; end'
17
- mutations << 'begin; rescue ExceptionB => error; true; end'
18
- end
19
-
20
- it_should_behave_like 'a mutator'
21
- end
22
-
23
- context 'single exception selector and assignment' do
24
- let(:source) { 'begin; rescue SomeException => error; true; end' }
25
-
26
- let(:mutations) do
27
- mutations = []
28
- mutations << 'nil'
29
- mutations << 'begin; rescue SomeException; true; end'
30
- mutations << 'begin; rescue SomeException => error; false; end'
31
- mutations << 'begin; rescue SomeException => error; nil; end'
32
- end
33
-
34
- it_should_behave_like 'a mutator'
35
- end
36
-
37
- context 'no exection selector and assignment' do
38
- let(:source) { 'begin; rescue => error; true end' }
39
-
40
- let(:mutations) do
41
- mutations = []
42
- mutations << 'nil'
43
- mutations << 'begin; rescue => error; false; end'
44
- mutations << 'begin; rescue => error; nil; end'
45
- mutations << 'begin; rescue; true; end'
46
- end
47
-
48
- it_should_behave_like 'a mutator'
49
- end
50
-
51
- context 'no exection selector and no assignment' do
52
- let(:source) { 'begin; rescue; true end' }
53
-
54
- let(:mutations) do
55
- mutations = []
56
- mutations << 'nil'
57
- mutations << 'begin; rescue; false; end'
58
- mutations << 'begin; rescue; nil; end'
59
- end
60
-
61
- it_should_behave_like 'a mutator'
62
- end
63
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator::Node::Restarg, 'restarg' do
6
- let(:source) { 'foo(*bar)' }
7
-
8
- let(:mutations) do
9
- mutants = []
10
- mutants << 'foo'
11
- mutants << 'foo(nil)'
12
- mutants << 'foo(bar)'
13
- mutants << 'foo(*nil)'
14
- mutants << 'nil'
15
- end
16
-
17
- it_should_behave_like 'a mutator'
18
- end
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Mutant::Mutator, 'return' do
6
-
7
- context 'return without value' do
8
- let(:source) { 'return' }
9
-
10
- let(:mutations) do
11
- mutations = []
12
- mutations << 'nil'
13
- end
14
-
15
- it_should_behave_like 'a mutator'
16
- end
17
-
18
- context 'return with value' do
19
- let(:source) { 'return foo' }
20
-
21
- let(:mutations) do
22
- mutations = []
23
- mutations << 'foo'
24
- mutations << 'return nil'
25
- mutations << 'nil'
26
- end
27
-
28
- it_should_behave_like 'a mutator'
29
- end
30
-
31
- end
@@ -1,382 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- # FIXME: This spec needs to be structured better!
6
- describe Mutant::Mutator, 'send' do
7
-
8
- context 'when using #reverse_each' do
9
- let(:source) { 'reverse_each' }
10
-
11
- let(:mutations) do
12
- mutations = []
13
- mutations << 'nil'
14
- mutations << 'each'
15
- end
16
-
17
- it_should_behave_like 'a mutator'
18
- end
19
-
20
- context 'when using #reverse_map' do
21
- let(:source) { 'reverse_map' }
22
-
23
- let(:mutations) do
24
- mutations = []
25
- mutations << 'nil'
26
- mutations << 'map'
27
- mutations << 'each'
28
- end
29
-
30
- it_should_behave_like 'a mutator'
31
- end
32
-
33
- context 'when using #map' do
34
- let(:source) { 'map' }
35
-
36
- let(:mutations) do
37
- mutations = []
38
- mutations << 'nil'
39
- mutations << 'each'
40
- end
41
-
42
- it_should_behave_like 'a mutator'
43
- end
44
-
45
- context 'when using #==' do
46
- let(:source) { 'foo == bar' }
47
-
48
- let(:mutations) do
49
- mutations = []
50
- mutations << 'foo'
51
- mutations << 'bar'
52
- mutations << 'nil == bar'
53
- mutations << 'foo == nil'
54
- mutations << 'nil'
55
- mutations << 'foo.eql?(bar)'
56
- mutations << 'foo.equal?(bar)'
57
- end
58
-
59
- it_should_behave_like 'a mutator'
60
- end
61
-
62
- context 'when using #gsub' do
63
- let(:source) { 'foo.gsub(a, b)' }
64
-
65
- let(:mutations) do
66
- mutations = []
67
- mutations << 'foo'
68
- mutations << 'foo.gsub(a)'
69
- mutations << 'foo.gsub(b)'
70
- mutations << 'foo.gsub'
71
- mutations << 'foo.sub(a, b)'
72
- mutations << 'foo.gsub(a, nil)'
73
- mutations << 'foo.gsub(nil, b)'
74
- mutations << 'nil.gsub(a, b)'
75
- mutations << 'nil'
76
- end
77
-
78
- it_should_behave_like 'a mutator'
79
- end
80
-
81
- context 'when using Kernel#send' do
82
- let(:source) { 'foo.send(bar)' }
83
-
84
- let(:mutations) do
85
- mutations = []
86
- mutations << 'foo.send'
87
- mutations << 'foo.public_send(bar)'
88
- mutations << 'bar'
89
- mutations << 'foo'
90
- mutations << 'foo.send(nil)'
91
- mutations << 'nil.send(bar)'
92
- mutations << 'nil'
93
- end
94
-
95
- it_should_behave_like 'a mutator'
96
- end
97
-
98
- context 'inside op assign' do
99
- let(:source) { 'self.foo ||= expression' }
100
-
101
- let(:mutations) do
102
- mutations = []
103
- mutations << 'self.foo ||= nil'
104
- mutations << 'nil.foo ||= expression'
105
- mutations << 'nil'
106
- end
107
-
108
- it_should_behave_like 'a mutator'
109
- end
110
-
111
- context 'attribute assign' do
112
-
113
- context 'to self' do
114
- let(:source) { 'self.bar=baz' }
115
-
116
- let(:mutations) do
117
- mutations = []
118
- mutations << 'nil'
119
- mutations << 'self.bar=nil'
120
- mutations << 'self'
121
- mutations << 'self.bar'
122
- mutations << 'baz'
123
- # This one could probably be removed
124
- mutations << 'nil.bar=baz'
125
- end
126
-
127
- it_should_behave_like 'a mutator'
128
- end
129
-
130
- context 'to other object' do
131
- let(:source) { 'foo.bar=baz' }
132
-
133
- let(:mutations) do
134
- mutations = []
135
- mutations << 'foo'
136
- mutations << 'nil'
137
- mutations << 'foo.bar=nil'
138
- mutations << 'foo.bar'
139
- mutations << 'baz'
140
- # This one could probably be removed
141
- mutations << 'nil.bar=baz'
142
- end
143
-
144
- it_should_behave_like 'a mutator'
145
- end
146
- end
147
-
148
- context 'index assign' do
149
- let(:source) { 'foo[bar]=baz' }
150
-
151
- let(:mutations) do
152
- mutations = []
153
- mutations << 'foo'
154
- mutations << 'nil'
155
- end
156
-
157
- it_should_behave_like 'a mutator'
158
- end
159
-
160
- context 'with only a splat arg' do
161
- let(:source) { 'foo(*bar)' }
162
-
163
- let(:mutations) do
164
- mutations = []
165
- mutations << 'foo'
166
- mutations << 'foo(nil)'
167
- mutations << 'foo(bar)'
168
- mutations << 'foo(*nil)'
169
- mutations << 'nil'
170
- end
171
-
172
- it_should_behave_like 'a mutator'
173
- end
174
-
175
- context 'with only a block arg' do
176
- let(:source) { 'foo(&bar)' }
177
-
178
- let(:mutations) do
179
- mutations = []
180
- mutations << 'foo'
181
- mutations << 'nil'
182
- end
183
-
184
- it_should_behave_like 'a mutator'
185
- end
186
-
187
- context 'single splat arg splat' do
188
- let(:source) { 'foo[*bar]' }
189
-
190
- let(:mutations) do
191
- mutations = []
192
- mutations << 'foo'
193
- mutations << 'nil'
194
- end
195
-
196
- it_should_behave_like 'a mutator'
197
- end
198
-
199
- context 'with self as' do
200
- context 'implicit' do
201
- let(:source) { 'foo' }
202
-
203
- let(:mutations) do
204
- mutations = []
205
- mutations << 'nil'
206
- end
207
-
208
- it_should_behave_like 'a mutator'
209
- end
210
-
211
- context 'explict receiver' do
212
- let(:source) { 'self.foo' }
213
-
214
- let(:mutations) do
215
- mutations = []
216
- mutations << 'foo'
217
- mutations << 'self'
218
- mutations << 'nil.foo'
219
- mutations << 'nil'
220
- end
221
-
222
- it_should_behave_like 'a mutator'
223
- end
224
-
225
- context 'explicit receiver with keyword message name' do
226
- Unparser::Constants::KEYWORDS.each do |keyword|
227
- context "with keyword: #{keyword}" do
228
- let(:source) { "self.#{keyword}" }
229
- let(:mutations) do
230
- ['self']
231
- end
232
- end
233
- end
234
- end
235
- end
236
-
237
- context 'without arguments' do
238
-
239
- context 'to some object' do
240
- let(:source) { 'foo.bar' }
241
-
242
- let(:mutations) do
243
- mutations = []
244
- mutations << 'foo'
245
- mutations << 'nil.bar'
246
- mutations << 'nil'
247
- end
248
-
249
- it_should_behave_like 'a mutator'
250
- end
251
-
252
- context 'to self.class.foo' do
253
- let(:source) { 'self.class.foo' }
254
-
255
- let(:mutations) do
256
- mutations = []
257
- mutations << 'self.class'
258
- mutations << 'self.foo'
259
- mutations << 'nil.class.foo'
260
- mutations << 'nil.foo'
261
- mutations << 'nil'
262
- end
263
-
264
- it_should_behave_like 'a mutator'
265
- end
266
- end
267
-
268
- context 'with arguments' do
269
-
270
- context 'one argument' do
271
- let(:source) { 'foo(nil)' }
272
-
273
- let(:mutations) do
274
- mutations = []
275
- mutations << 'foo'
276
- mutations << 'nil'
277
- end
278
-
279
- it_should_behave_like 'a mutator'
280
- end
281
-
282
- context 'with explicit self as receiver' do
283
- let(:source) { 'self.foo(nil)' }
284
-
285
- let(:mutations) do
286
- mutations = []
287
- mutations << 'self'
288
- mutations << 'self.foo'
289
- mutations << 'foo(nil)'
290
- mutations << 'nil'
291
- mutations << 'nil.foo(nil)'
292
- end
293
-
294
- it_should_behave_like 'a mutator'
295
- end
296
-
297
- context 'to some object with keyword in method name' do
298
- Unparser::Constants::KEYWORDS.each do |keyword|
299
- context "with keyword #{keyword}" do
300
- let(:source) { "foo.#{keyword}(nil)" }
301
-
302
- let(:mutations) do
303
- mutations = []
304
- mutations << "foo.#{keyword}"
305
- mutations << 'foo'
306
- mutations << "nil.#{keyword}(nil)"
307
- mutations << 'nil'
308
- end
309
-
310
- it_should_behave_like 'a mutator'
311
- end
312
- end
313
- end
314
-
315
- context 'two arguments' do
316
- let(:source) { 'foo(nil, nil)' }
317
-
318
- let(:mutations) do
319
- mutations = []
320
- mutations << 'foo()'
321
- mutations << 'foo(nil)'
322
- mutations << 'nil'
323
- end
324
-
325
- it_should_behave_like 'a mutator'
326
- end
327
-
328
- context 'binary operator methods' do
329
- context 'nested' do
330
- let(:source) { '(left - right) / foo' }
331
-
332
- let(:mutations) do
333
- mutations = []
334
- mutations << 'foo'
335
- mutations << '(left - right)'
336
- mutations << 'left / foo'
337
- mutations << 'right / foo'
338
- mutations << '(left - right) / nil'
339
- mutations << '(left - nil) / foo'
340
- mutations << '(nil - right) / foo'
341
- mutations << 'nil / foo'
342
- mutations << 'nil'
343
- end
344
-
345
- it_should_behave_like 'a mutator'
346
- end
347
-
348
- (Mutant::BINARY_METHOD_OPERATORS - [:==, :eql?]).each do |operator|
349
- context 'on literal scalar arguments' do
350
- let(:source) { "true #{operator} false" }
351
-
352
- let(:mutations) do
353
- mutations = []
354
- mutations << "false #{operator} false"
355
- mutations << "nil #{operator} false"
356
- mutations << "true #{operator} true"
357
- mutations << "true #{operator} nil"
358
- mutations << 'true'
359
- mutations << 'false'
360
- mutations << 'nil'
361
- end
362
-
363
- it_should_behave_like 'a mutator'
364
- end
365
-
366
- context 'on non literal scalar arguments' do
367
- let(:source) { "left #{operator} right" }
368
- let(:mutations) do
369
- mutations = []
370
- mutations << 'left'
371
- mutations << 'right'
372
- mutations << "left #{operator} nil"
373
- mutations << "nil #{operator} right"
374
- mutations << 'nil'
375
- end
376
-
377
- it_should_behave_like 'a mutator'
378
- end
379
- end
380
- end
381
- end
382
- end