mutant 0.8.24 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (218) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +3 -3
  3. data/Changelog.md +14 -654
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +59 -64
  6. data/LICENSE +271 -20
  7. data/README.md +73 -140
  8. data/Rakefile +0 -21
  9. data/bin/mutant +7 -2
  10. data/config/reek.yml +2 -1
  11. data/config/rubocop.yml +5 -9
  12. data/docs/incremental.md +76 -0
  13. data/docs/known-problems.md +0 -14
  14. data/docs/mutant-minitest.md +1 -1
  15. data/docs/mutant-rspec.md +2 -24
  16. data/lib/mutant.rb +45 -53
  17. data/lib/mutant/ast/nodes.rb +0 -2
  18. data/lib/mutant/ast/types.rb +1 -117
  19. data/lib/mutant/base.rb +192 -0
  20. data/lib/mutant/bootstrap.rb +145 -0
  21. data/lib/mutant/cli.rb +68 -54
  22. data/lib/mutant/config.rb +119 -6
  23. data/lib/mutant/env.rb +94 -8
  24. data/lib/mutant/expression.rb +6 -1
  25. data/lib/mutant/expression/parser.rb +9 -31
  26. data/lib/mutant/integration.rb +64 -36
  27. data/lib/mutant/isolation.rb +16 -1
  28. data/lib/mutant/isolation/fork.rb +105 -40
  29. data/lib/mutant/license.rb +34 -0
  30. data/lib/mutant/license/subscription.rb +47 -0
  31. data/lib/mutant/license/subscription/commercial.rb +57 -0
  32. data/lib/mutant/license/subscription/opensource.rb +77 -0
  33. data/lib/mutant/loader.rb +27 -4
  34. data/lib/mutant/matcher.rb +48 -1
  35. data/lib/mutant/matcher/chain.rb +1 -1
  36. data/lib/mutant/matcher/config.rb +0 -2
  37. data/lib/mutant/matcher/filter.rb +1 -1
  38. data/lib/mutant/matcher/method.rb +11 -7
  39. data/lib/mutant/matcher/methods.rb +1 -1
  40. data/lib/mutant/matcher/namespace.rb +1 -1
  41. data/lib/mutant/matcher/null.rb +1 -1
  42. data/lib/mutant/matcher/scope.rb +1 -1
  43. data/lib/mutant/meta/example/dsl.rb +0 -8
  44. data/lib/mutant/mutation.rb +1 -2
  45. data/lib/mutant/mutator/node.rb +2 -9
  46. data/lib/mutant/mutator/node/arguments.rb +1 -1
  47. data/lib/mutant/mutator/node/class.rb +0 -8
  48. data/lib/mutant/mutator/node/define.rb +0 -12
  49. data/lib/mutant/mutator/node/generic.rb +30 -44
  50. data/lib/mutant/mutator/node/index.rb +4 -4
  51. data/lib/mutant/mutator/node/literal/regex.rb +0 -39
  52. data/lib/mutant/mutator/node/send.rb +13 -12
  53. data/lib/mutant/parallel.rb +61 -40
  54. data/lib/mutant/parallel/driver.rb +59 -0
  55. data/lib/mutant/parallel/source.rb +6 -2
  56. data/lib/mutant/parallel/worker.rb +63 -45
  57. data/lib/mutant/range.rb +15 -0
  58. data/lib/mutant/reporter/cli.rb +5 -11
  59. data/lib/mutant/reporter/cli/format.rb +3 -46
  60. data/lib/mutant/reporter/cli/printer/config.rb +5 -6
  61. data/lib/mutant/reporter/cli/printer/env.rb +40 -0
  62. data/lib/mutant/reporter/cli/printer/env_progress.rb +13 -17
  63. data/lib/mutant/reporter/cli/printer/isolation_result.rb +17 -3
  64. data/lib/mutant/reporter/cli/printer/mutation_result.rb +2 -3
  65. data/lib/mutant/reporter/cli/printer/status_progressive.rb +19 -10
  66. data/lib/mutant/repository.rb +0 -65
  67. data/lib/mutant/repository/diff.rb +104 -0
  68. data/lib/mutant/repository/diff/ranges.rb +52 -0
  69. data/lib/mutant/result.rb +16 -7
  70. data/lib/mutant/runner.rb +38 -47
  71. data/lib/mutant/runner/sink.rb +1 -1
  72. data/lib/mutant/selector/null.rb +19 -0
  73. data/lib/mutant/subject.rb +3 -1
  74. data/lib/mutant/subject/method/instance.rb +3 -1
  75. data/lib/mutant/transform.rb +511 -0
  76. data/lib/mutant/variable.rb +282 -0
  77. data/lib/mutant/version.rb +1 -1
  78. data/lib/mutant/warnings.rb +113 -0
  79. data/meta/case.rb +1 -0
  80. data/meta/class.rb +0 -9
  81. data/meta/def.rb +1 -26
  82. data/meta/regexp.rb +10 -20
  83. data/meta/send.rb +14 -46
  84. data/mutant-minitest.gemspec +1 -1
  85. data/mutant-rspec.gemspec +2 -2
  86. data/mutant.gemspec +15 -16
  87. data/mutant.yml +6 -0
  88. data/spec/integration/mutant/isolation/fork_spec.rb +22 -5
  89. data/spec/integration/mutant/minitest_spec.rb +3 -2
  90. data/spec/integration/mutant/rspec_spec.rb +4 -3
  91. data/spec/integrations.yml +16 -13
  92. data/spec/shared/base_behavior.rb +45 -0
  93. data/spec/shared/framework_integration_behavior.rb +43 -14
  94. data/spec/spec_helper.rb +21 -17
  95. data/spec/support/corpus.rb +56 -95
  96. data/spec/support/shared_context.rb +37 -14
  97. data/spec/support/xspec.rb +7 -3
  98. data/spec/unit/mutant/bootstrap_spec.rb +216 -0
  99. data/spec/unit/mutant/cli_spec.rb +173 -117
  100. data/spec/unit/mutant/config_spec.rb +126 -0
  101. data/spec/unit/mutant/either_spec.rb +247 -0
  102. data/spec/unit/mutant/env_spec.rb +162 -40
  103. data/spec/unit/mutant/expression/method_spec.rb +16 -0
  104. data/spec/unit/mutant/expression/parser_spec.rb +29 -33
  105. data/spec/unit/mutant/expression_spec.rb +5 -7
  106. data/spec/unit/mutant/integration_spec.rb +100 -9
  107. data/spec/unit/mutant/isolation/fork_spec.rb +125 -67
  108. data/spec/unit/mutant/isolation/result_spec.rb +33 -1
  109. data/spec/unit/mutant/license_spec.rb +257 -0
  110. data/spec/unit/mutant/loader_spec.rb +50 -11
  111. data/spec/unit/mutant/matcher/compiler_spec.rb +0 -78
  112. data/spec/unit/mutant/matcher/method/instance_spec.rb +55 -11
  113. data/spec/unit/mutant/matcher/method/singleton_spec.rb +12 -2
  114. data/spec/unit/mutant/matcher_spec.rb +102 -0
  115. data/spec/unit/mutant/maybe_spec.rb +60 -0
  116. data/spec/unit/mutant/meta/example/dsl_spec.rb +1 -17
  117. data/spec/unit/mutant/mutation_spec.rb +13 -6
  118. data/spec/unit/mutant/parallel/driver_spec.rb +112 -14
  119. data/spec/unit/mutant/parallel/source/array_spec.rb +25 -17
  120. data/spec/unit/mutant/parallel/worker_spec.rb +182 -44
  121. data/spec/unit/mutant/parallel_spec.rb +105 -8
  122. data/spec/unit/mutant/range_spec.rb +141 -0
  123. data/spec/unit/mutant/reporter/cli/printer/config_spec.rb +7 -21
  124. data/spec/unit/mutant/reporter/cli/printer/env_progress_spec.rb +15 -6
  125. data/spec/unit/mutant/reporter/cli/printer/env_result_spec.rb +10 -2
  126. data/spec/unit/mutant/reporter/cli/printer/isolation_result_spec.rb +12 -4
  127. data/spec/unit/mutant/reporter/cli/printer/mutation_result_spec.rb +31 -2
  128. data/spec/unit/mutant/reporter/cli/printer/status_progressive_spec.rb +4 -4
  129. data/spec/unit/mutant/reporter/cli/printer/subject_result_spec.rb +5 -0
  130. data/spec/unit/mutant/reporter/cli_spec.rb +46 -123
  131. data/spec/unit/mutant/repository/diff/ranges_spec.rb +180 -0
  132. data/spec/unit/mutant/repository/diff_spec.rb +84 -71
  133. data/spec/unit/mutant/require_highjack_spec.rb +1 -1
  134. data/spec/unit/mutant/result/env_spec.rb +39 -9
  135. data/spec/unit/mutant/result/test_spec.rb +14 -0
  136. data/spec/unit/mutant/runner_spec.rb +88 -41
  137. data/spec/unit/mutant/selector/expression_spec.rb +11 -10
  138. data/spec/unit/mutant/selector/null_spec.rb +17 -0
  139. data/spec/unit/mutant/subject/method/instance_spec.rb +44 -5
  140. data/spec/unit/mutant/subject/method/singleton_spec.rb +9 -2
  141. data/spec/unit/mutant/subject_spec.rb +9 -1
  142. data/spec/unit/mutant/transform/array_spec.rb +92 -0
  143. data/spec/unit/mutant/transform/bool_spec.rb +63 -0
  144. data/spec/unit/mutant/transform/error_spec.rb +132 -0
  145. data/spec/unit/mutant/transform/exception_spec.rb +44 -0
  146. data/spec/unit/mutant/transform/hash_spec.rb +236 -0
  147. data/spec/unit/mutant/transform/index_spec.rb +92 -0
  148. data/spec/unit/mutant/transform/named_spec.rb +49 -0
  149. data/spec/unit/mutant/transform/primitive_spec.rb +56 -0
  150. data/spec/unit/mutant/transform/sequence_spec.rb +98 -0
  151. data/spec/unit/mutant/variable_spec.rb +618 -0
  152. data/spec/unit/mutant/warnings_spec.rb +89 -0
  153. data/spec/unit/mutant/world_spec.rb +63 -0
  154. data/test_app/Gemfile.minitest +0 -2
  155. metadata +79 -113
  156. data/.gitattributes +0 -1
  157. data/.ruby-gemset +0 -1
  158. data/config/triage.yml +0 -2
  159. data/lib/mutant/actor.rb +0 -57
  160. data/lib/mutant/actor/env.rb +0 -31
  161. data/lib/mutant/actor/mailbox.rb +0 -34
  162. data/lib/mutant/actor/receiver.rb +0 -42
  163. data/lib/mutant/actor/sender.rb +0 -26
  164. data/lib/mutant/ast/meta/restarg.rb +0 -19
  165. data/lib/mutant/ast/regexp.rb +0 -42
  166. data/lib/mutant/ast/regexp/transformer.rb +0 -187
  167. data/lib/mutant/ast/regexp/transformer/direct.rb +0 -123
  168. data/lib/mutant/ast/regexp/transformer/named_group.rb +0 -59
  169. data/lib/mutant/ast/regexp/transformer/options_group.rb +0 -83
  170. data/lib/mutant/ast/regexp/transformer/quantifier.rb +0 -114
  171. data/lib/mutant/ast/regexp/transformer/recursive.rb +0 -58
  172. data/lib/mutant/ast/regexp/transformer/root.rb +0 -31
  173. data/lib/mutant/ast/regexp/transformer/text.rb +0 -60
  174. data/lib/mutant/env/bootstrap.rb +0 -160
  175. data/lib/mutant/matcher/compiler.rb +0 -60
  176. data/lib/mutant/mutator/node/regexp.rb +0 -35
  177. data/lib/mutant/mutator/node/regexp/alternation_meta.rb +0 -23
  178. data/lib/mutant/mutator/node/regexp/capture_group.rb +0 -28
  179. data/lib/mutant/mutator/node/regexp/character_type.rb +0 -32
  180. data/lib/mutant/mutator/node/regexp/end_of_line_anchor.rb +0 -23
  181. data/lib/mutant/mutator/node/regexp/end_of_string_or_before_end_of_line_anchor.rb +0 -23
  182. data/lib/mutant/mutator/node/regexp/greedy_zero_or_more.rb +0 -27
  183. data/lib/mutant/parallel/master.rb +0 -181
  184. data/lib/mutant/reporter/cli/printer/status.rb +0 -53
  185. data/lib/mutant/reporter/cli/tput.rb +0 -46
  186. data/lib/mutant/warning_filter.rb +0 -61
  187. data/meta/regexp/character_types.rb +0 -23
  188. data/meta/regexp/regexp_alternation_meta.rb +0 -13
  189. data/meta/regexp/regexp_bol_anchor.rb +0 -10
  190. data/meta/regexp/regexp_bos_anchor.rb +0 -18
  191. data/meta/regexp/regexp_capture_group.rb +0 -19
  192. data/meta/regexp/regexp_eol_anchor.rb +0 -10
  193. data/meta/regexp/regexp_eos_anchor.rb +0 -8
  194. data/meta/regexp/regexp_eos_ob_eol_anchor.rb +0 -10
  195. data/meta/regexp/regexp_greedy_zero_or_more.rb +0 -12
  196. data/meta/regexp/regexp_root_expression.rb +0 -10
  197. data/meta/restarg.rb +0 -10
  198. data/spec/support/fake_actor.rb +0 -111
  199. data/spec/support/warning.rb +0 -66
  200. data/spec/unit/mutant/actor/binding_spec.rb +0 -34
  201. data/spec/unit/mutant/actor/env_spec.rb +0 -31
  202. data/spec/unit/mutant/actor/mailbox_spec.rb +0 -28
  203. data/spec/unit/mutant/actor/message_spec.rb +0 -25
  204. data/spec/unit/mutant/actor/receiver_spec.rb +0 -58
  205. data/spec/unit/mutant/actor/sender_spec.rb +0 -24
  206. data/spec/unit/mutant/ast/regexp/parse_spec.rb +0 -19
  207. data/spec/unit/mutant/ast/regexp/transformer/lookup_table/table_spec.rb +0 -21
  208. data/spec/unit/mutant/ast/regexp/transformer/lookup_table_spec.rb +0 -35
  209. data/spec/unit/mutant/ast/regexp/transformer_spec.rb +0 -21
  210. data/spec/unit/mutant/ast/regexp_spec.rb +0 -704
  211. data/spec/unit/mutant/env/bootstrap_spec.rb +0 -188
  212. data/spec/unit/mutant/matcher/compiler/subject_prefix_spec.rb +0 -26
  213. data/spec/unit/mutant/parallel/master_spec.rb +0 -338
  214. data/spec/unit/mutant/reporter/cli/printer/status_spec.rb +0 -121
  215. data/spec/unit/mutant/reporter/cli/tput_spec.rb +0 -50
  216. data/spec/unit/mutant/warning_filter_spec.rb +0 -106
  217. data/spec/unit/mutant_spec.rb +0 -17
  218. data/test_app/Gemfile.rspec3.7 +0 -7
@@ -25,7 +25,7 @@ RSpec.describe Mutant::Isolation::Result do
25
25
  end
26
26
  end
27
27
 
28
- describe 'add_error' do
28
+ describe '#add_error' do
29
29
  let(:other) { described_class::Success.new(object) }
30
30
  let(:value) { double('Object') }
31
31
  let(:object) { described_class::Success.new(value) }
@@ -38,4 +38,36 @@ RSpec.describe Mutant::Isolation::Result do
38
38
  expect(apply).to eql(described_class::ErrorChain.new(other, object))
39
39
  end
40
40
  end
41
+
42
+ describe '#log' do
43
+ let(:value) { double('Object') }
44
+
45
+ def apply
46
+ object.log
47
+ end
48
+
49
+ context 'on exception result' do
50
+ let(:object) { described_class::Exception.new(value) }
51
+
52
+ it 'returns the empty string' do
53
+ expect(apply).to eql('')
54
+ end
55
+ end
56
+
57
+ context 'on sucess result' do
58
+ let(:object) { described_class::Success.new(value) }
59
+
60
+ it 'returns the empty string' do
61
+ expect(apply).to eql('')
62
+ end
63
+ end
64
+
65
+ context 'on argument' do
66
+ let(:object) { described_class::Success.new(value, 'foo') }
67
+
68
+ it 'returns the empty string' do
69
+ expect(apply).to eql('foo')
70
+ end
71
+ end
72
+ end
41
73
  end
@@ -0,0 +1,257 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Mutant::License do
4
+ def apply
5
+ described_class.apply(world)
6
+ end
7
+
8
+ let(:gem) { class_double(Gem, loaded_specs: loaded_specs) }
9
+ let(:gem_path) { '/path/to/mutant-license' }
10
+ let(:gem_pathname) { instance_double(Pathname) }
11
+ let(:json) { class_double(JSON) }
12
+ let(:kernel) { class_double(Kernel) }
13
+ let(:license_pathname) { instance_double(Pathname) }
14
+ let(:loaded_specs) { { 'mutant-license' => spec } }
15
+ let(:path) { instance_double(Pathname) }
16
+ let(:pathname) { class_double(Pathname) }
17
+ let(:stderr) { instance_double(IO) }
18
+
19
+ let(:spec) do
20
+ instance_double(
21
+ Gem::Specification,
22
+ full_gem_path: gem_path
23
+ )
24
+ end
25
+
26
+ let(:world) do
27
+ instance_double(
28
+ Mutant::World,
29
+ gem: gem,
30
+ json: json,
31
+ kernel: kernel,
32
+ pathname: pathname,
33
+ stderr: stderr
34
+ )
35
+ end
36
+
37
+ before do
38
+ allow(gem_pathname).to receive_messages(join: license_pathname)
39
+ allow(json).to receive_messages(load: license_json)
40
+ allow(kernel).to receive_messages(sleep: undefined)
41
+ allow(pathname).to receive_messages(new: gem_pathname)
42
+ allow(world).to receive(:capture_stdout, &commands.method(:fetch))
43
+ end
44
+
45
+ def self.it_fails(expected)
46
+ it 'failse with exception' do
47
+ expect { apply }.to raise_error(expected)
48
+ end
49
+ end
50
+
51
+ def self.it_is_successful
52
+ include_examples 'license.json lookup'
53
+
54
+ it 'allows usage' do
55
+ expect(apply).to eql(Mutant::Either::Right.new(true))
56
+ end
57
+ end
58
+
59
+ # rubocop:disable Metrics/AbcSize
60
+ # rubocop:disable Metrics/MethodLength
61
+ def self.it_fails_with_message(expected)
62
+ before do
63
+ allow(stderr).to receive(:puts)
64
+ end
65
+
66
+ it 'performs IO in expected sequence' do
67
+ expect(apply).to eql(Mutant::Either::Right.new(true))
68
+
69
+ expect(stderr)
70
+ .to have_received(:puts)
71
+ .with(expected)
72
+ .ordered
73
+
74
+ expect(stderr)
75
+ .to have_received(:puts)
76
+ .with('Soft fail, continuing in 10 seconds')
77
+ .ordered
78
+
79
+ expect(kernel)
80
+ .to have_received(:sleep)
81
+ .with(10)
82
+ .ordered
83
+ end
84
+ end
85
+
86
+ shared_examples 'license.json lookup' do
87
+ it 'builds correct license.json path' do
88
+ apply
89
+
90
+ expect(pathname).to have_received(:new).with(gem_path)
91
+ expect(gem_pathname).to have_received(:join).with('license.json')
92
+ end
93
+ end
94
+
95
+ describe 'on opensource license' do
96
+ let(:repository) { 'github.com/mbj/mutant' }
97
+
98
+ let(:git_remote) do
99
+ <<~REMOTE
100
+ origin\tgit@github.com:mbj/mutant (fetch)
101
+ origin\tgit@github.com:mbj/mutant (push)
102
+ REMOTE
103
+ end
104
+
105
+ let(:license_json) do
106
+ {
107
+ 'type' => 'oss',
108
+ 'contents' => {
109
+ 'repositories' => [repository]
110
+ }
111
+ }
112
+ end
113
+
114
+ let(:git_remote_result) { Mutant::Either::Right.new(git_remote) }
115
+
116
+ let(:commands) do
117
+ {
118
+ %w[git remote --verbose] => git_remote_result
119
+ }
120
+ end
121
+
122
+ context 'when repository is whitelisted' do
123
+ context 'on ssh url without protocol and without suffx' do
124
+ it_is_successful
125
+ end
126
+
127
+ context 'on ssh url with protocol and without suffx' do
128
+ let(:git_remote) do
129
+ <<~REMOTE
130
+ origin\tssh://git@github.com/mbj/mutant (fetch)
131
+ origin\tssh://git@github.com/mbj/mutant (push)
132
+ REMOTE
133
+ end
134
+
135
+ it_is_successful
136
+ end
137
+
138
+ context 'on ssh url with protocol and suffx' do
139
+ let(:git_remote) do
140
+ <<~REMOTE
141
+ origin\tssh://git@github.com/mbj/mutant.git (fetch)
142
+ origin\tssh://git@github.com/mbj/mutant.git (push)
143
+ REMOTE
144
+ end
145
+
146
+ it_is_successful
147
+ end
148
+
149
+ context 'on https url without suffix' do
150
+ let(:git_remote) do
151
+ <<~REMOTE
152
+ origin\thttps://github.com/mbj/mutant (fetch)
153
+ origin\thttps://github.com/mbj/mutant (push)
154
+ REMOTE
155
+ end
156
+
157
+ it_is_successful
158
+ end
159
+
160
+ context 'on https url with .git suffix' do
161
+ let(:git_remote) do
162
+ <<~REMOTE
163
+ origin\thttps://github.com/mbj/mutant.git (fetch)
164
+ origin\thttps://github.com/mbj/mutant.git (push)
165
+ REMOTE
166
+ end
167
+
168
+ it_is_successful
169
+ end
170
+ end
171
+
172
+ context 'when repository is not whitelisted' do
173
+ let(:repository) { 'github.com/mbj/unparser' }
174
+
175
+ it_fails_with_message(<<~'MESSAGE')
176
+ Can not validate opensource license.
177
+ Licensed:
178
+ github.com/mbj/unparser
179
+ Present:
180
+ github.com/mbj/mutant
181
+ MESSAGE
182
+ end
183
+
184
+ context 'when git remote line cannot be parsed' do
185
+ let(:git_remote) { "some-bad-remote-line\n" }
186
+
187
+ it_fails 'Unmatched remote line: "some-bad-remote-line\n"'
188
+ end
189
+
190
+ context 'when git remote url cannot be parsed' do
191
+ let(:git_remote) { "some-unknown\thttp://github.com/mbj/mutant (fetch)\n" }
192
+
193
+ it_fails 'Unmatched git remote URL: "http://github.com/mbj/mutant"'
194
+ end
195
+ end
196
+
197
+ describe 'on commercial license' do
198
+ let(:licensed_authors) do
199
+ %w[
200
+ customer-a@example.com
201
+ customer-b@example.com
202
+ ]
203
+ end
204
+
205
+ let(:license_json) do
206
+ {
207
+ 'type' => 'com',
208
+ 'contents' => {
209
+ 'authors' => licensed_authors
210
+ }
211
+ }
212
+ end
213
+
214
+ let(:git_config_author) { "customer-a@example.com\n" }
215
+ let(:git_config_result) { Mutant::Either::Right.new(git_config_author) }
216
+ let(:git_show_author) { "customer-b@example.com\n" }
217
+ let(:git_show_result) { Mutant::Either::Right.new(git_show_author) }
218
+
219
+ let(:commands) do
220
+ {
221
+ %w[git config --get user.email] => git_config_result,
222
+ %w[git show --quiet --pretty=format:%ae] => git_show_result
223
+ }
224
+ end
225
+
226
+ context 'when author is whitelisted' do
227
+ it_is_successful
228
+ end
229
+
230
+ context 'when author is not whitelisted' do
231
+ let(:licensed_authors) { %w[customer-c@example.com] }
232
+
233
+ it_fails_with_message(<<~'MESSAGE')
234
+ Can not validate commercial license.
235
+ Licensed:
236
+ customer-c@example.com
237
+ Present:
238
+ customer-a@example.com
239
+ customer-b@example.com
240
+ MESSAGE
241
+ end
242
+
243
+ context 'when author cannot be found in commit or config' do
244
+ let(:git_config_result) { Mutant::Either::Left.new('fatal: error') }
245
+ let(:git_show_result) { Mutant::Either::Left.new('fatal: error') }
246
+
247
+ it_fails_with_message(<<~'MESSAGE')
248
+ Can not validate commercial license.
249
+ Licensed:
250
+ customer-a@example.com
251
+ customer-b@example.com
252
+ Present:
253
+ [none]
254
+ MESSAGE
255
+ end
256
+ end
257
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe Mutant::Loader, '.call' do
4
- subject do
4
+ def apply
5
5
  described_class.call(
6
6
  binding: binding,
7
7
  kernel: kernel,
@@ -12,7 +12,7 @@ RSpec.describe Mutant::Loader, '.call' do
12
12
 
13
13
  let(:path) { instance_double(Pathname, to_s: path_str) }
14
14
  let(:path_str) { instance_double(String) }
15
- let(:line) { instance_double(0.class) }
15
+ let(:line) { instance_double(Integer) }
16
16
  let(:kernel) { class_double(Kernel) }
17
17
  let(:binding) { instance_double(Binding) }
18
18
  let(:source) { instance_double(String) }
@@ -26,15 +26,54 @@ RSpec.describe Mutant::Loader, '.call' do
26
26
  )
27
27
  end
28
28
 
29
- it 'performs expected kernel interaction' do
30
- expect(kernel).to receive(:eval)
31
- .with(
32
- "# frozen_string_literal: true\n#[InstanceDouble(String) (anonymous)]",
33
- binding,
34
- path_str,
35
- line
36
- )
29
+ before do
30
+ allow(kernel).to receive_messages(eval: nil)
31
+ end
32
+
33
+ shared_examples 'kernel eval' do
34
+ it 'performs eval' do
35
+ apply
36
+
37
+ expect(kernel).to have_received(:eval)
38
+ .with(
39
+ "# frozen_string_literal: true\n#[InstanceDouble(String) (anonymous)]",
40
+ binding,
41
+ path_str,
42
+ line
43
+ )
44
+ end
45
+ end
46
+
47
+ context 'without exception being raised' do
48
+ it 'returns success result' do
49
+ expect(apply).to be(described_class::Result::Success.instance)
50
+ end
51
+
52
+ include_examples 'kernel eval'
53
+ end
54
+
55
+ context 'with void value syntax error' do
56
+ before do
57
+ allow(kernel).to receive(:eval)
58
+ .and_raise(SyntaxError, '/some/path.rb:1: void value expression')
59
+ end
60
+
61
+ it 'returns void value result' do
62
+ expect(apply).to be(described_class::Result::VoidValue.instance)
63
+ end
64
+
65
+ include_examples 'kernel eval'
66
+ end
67
+
68
+ context 'with other syntax error' do
69
+ let(:message) { '(eval):1: some other error' }
70
+
71
+ before do
72
+ allow(kernel).to receive(:eval).and_raise(SyntaxError, message)
73
+ end
37
74
 
38
- subject
75
+ it 'raises exception' do
76
+ expect { apply }.to raise_error(SyntaxError, message)
77
+ end
39
78
  end
40
79
  end
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Mutant::Matcher::Compiler, '#call' do
4
- let(:object) { described_class }
5
- let(:matcher_config) { Mutant::Matcher::Config::DEFAULT }
6
- let(:expression_a) { parse_expression('Foo*') }
7
- let(:expression_b) { parse_expression('Bar*') }
8
- let(:matcher_a) { expression_a.matcher }
9
-
10
- let(:expected_matcher) do
11
- Mutant::Matcher::Filter.new(
12
- expected_positive_matcher,
13
- expected_predicate
14
- )
15
- end
16
-
17
- let(:expected_predicate) do
18
- Morpher.compile(s(:and, s(:negate, s(:or)), s(:and)))
19
- end
20
-
21
- subject { object.call(matcher_config.with(attributes)) }
22
-
23
- context 'on empty config' do
24
- let(:attributes) { {} }
25
-
26
- let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([]) }
27
-
28
- it { should eql(expected_matcher) }
29
- end
30
-
31
- context 'on config with match expression' do
32
- let(:expected_predicate) do
33
- Morpher::Evaluator::Predicate::Boolean::And.new(
34
- [
35
- Morpher::Evaluator::Predicate::Negation.new(
36
- Morpher::Evaluator::Predicate::Boolean::Or.new(ignore_expression_predicates)
37
- ),
38
- Morpher::Evaluator::Predicate::Boolean::And.new(subject_filter_predicates)
39
- ]
40
- )
41
- end
42
-
43
- let(:expected_positive_matcher) { Mutant::Matcher::Chain.new([matcher_a]) }
44
- let(:attributes) { { match_expressions: [expression_a] } }
45
- let(:ignore_expression_predicates) { [] }
46
- let(:subject_filter_predicates) { [] }
47
-
48
- context 'and no other constraints' do
49
- it { should eql(expected_matcher) }
50
- end
51
-
52
- context 'and ignore expressions' do
53
- let(:attributes) do
54
- super().merge(ignore_expressions: [expression_b])
55
- end
56
-
57
- let(:ignore_expression_predicates) do
58
- [Mutant::Matcher::Compiler::SubjectPrefix.new(expression_b)]
59
- end
60
-
61
- it { should eql(expected_matcher) }
62
- end
63
-
64
- context 'and subject filters' do
65
- let(:subject_filter) { instance_double(Mutant::Matcher) }
66
-
67
- let(:attributes) do
68
- super().merge(subject_filters: [subject_filter])
69
- end
70
-
71
- let(:subject_filter_predicates) do
72
- [subject_filter]
73
- end
74
-
75
- it { should eql(expected_matcher) }
76
- end
77
- end
78
- end