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
@@ -0,0 +1,132 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Mutant::Transform::Error do
4
+ subject { described_class.new(attributes) }
5
+
6
+ let(:message) { 'root-message' }
7
+ let(:direct_cause) { nil }
8
+ let(:indirect_cause) { nil }
9
+
10
+ let(:attributes) do
11
+ transform =
12
+ if direct_cause
13
+ Mutant::Transform::Named.new('root', direct_cause.transform)
14
+ else
15
+ Mutant::Transform::Boolean.new
16
+ end
17
+
18
+ {
19
+ cause: direct_cause,
20
+ input: nil,
21
+ message: message,
22
+ transform: transform
23
+ }
24
+ end
25
+
26
+ shared_context 'direct cause' do
27
+ let(:direct_cause) do
28
+ transform =
29
+ if indirect_cause
30
+ Mutant::Transform::Named.new('direct-cause', indirect_cause.transform)
31
+ else
32
+ Mutant::Transform::Boolean.new
33
+ end
34
+
35
+ described_class.new(
36
+ cause: indirect_cause,
37
+ input: nil,
38
+ message: 'direct-cause-message',
39
+ transform: transform
40
+ )
41
+ end
42
+ end
43
+
44
+ shared_examples 'indirect cause' do
45
+ let(:indirect_cause) do
46
+ described_class.new(
47
+ cause: nil,
48
+ input: nil,
49
+ message: 'indirect-cause-message',
50
+ transform: Mutant::Transform::Boolean.new
51
+ )
52
+ end
53
+ end
54
+
55
+ describe '#trace' do
56
+ def apply
57
+ subject.trace
58
+ end
59
+
60
+ context 'without cause' do
61
+ it 'returns path to self' do
62
+ expect(apply).to eql([subject])
63
+ end
64
+ end
65
+
66
+ context 'with direct cause' do
67
+ include_context 'direct cause'
68
+
69
+ it 'returns path to direct cause' do
70
+ expect(apply).to eql([subject, direct_cause])
71
+ end
72
+ end
73
+
74
+ context 'with indirect cause' do
75
+ include_context 'direct cause'
76
+ include_context 'indirect cause'
77
+
78
+ it 'returns path to direct cause' do
79
+ expect(apply).to eql([subject, direct_cause, indirect_cause])
80
+ end
81
+ end
82
+ end
83
+
84
+ describe '#compact_message' do
85
+ def apply
86
+ subject.compact_message
87
+ end
88
+
89
+ context 'root cause' do
90
+ it 'returns expected message' do
91
+ expect(apply).to eql('Mutant::Transform::Boolean: root-message')
92
+ end
93
+ end
94
+
95
+ context 'with direct cause' do
96
+ include_context 'direct cause'
97
+
98
+ it 'returns expected message' do
99
+ expect(apply).to eql(<<~'MESSAGE'.chomp)
100
+ root/Mutant::Transform::Boolean: direct-cause-message
101
+ MESSAGE
102
+ end
103
+ end
104
+
105
+ context 'with indirect cause' do
106
+ include_context 'direct cause'
107
+ include_context 'indirect cause'
108
+
109
+ context 'with present slugs' do
110
+ it 'returns expected message' do
111
+ expect(apply).to eql(<<~'MESSAGE'.chomp)
112
+ root/direct-cause/Mutant::Transform::Boolean: indirect-cause-message
113
+ MESSAGE
114
+ end
115
+ end
116
+
117
+ context 'with empty slug' do
118
+ let(:direct_cause) do
119
+ super().with(
120
+ transform: Mutant::Transform::Named.new('', indirect_cause.transform)
121
+ )
122
+ end
123
+
124
+ it 'returns expected message' do
125
+ expect(apply).to eql(<<~'MESSAGE'.chomp)
126
+ root/Mutant::Transform::Boolean: indirect-cause-message
127
+ MESSAGE
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Mutant::Transform::Exception do
4
+ subject { described_class.new(error_class, block) }
5
+
6
+ let(:error_class) do
7
+ Class.new(RuntimeError)
8
+ end
9
+
10
+ describe '#apply' do
11
+ def apply
12
+ subject.apply(input)
13
+ end
14
+
15
+ let(:input) { 2 }
16
+
17
+ context 'block that does not raise' do
18
+ let(:block) { ->(input) { input*input } }
19
+
20
+ it 'returns expected success value' do
21
+ expect(apply).to eql(Mutant::Either::Right.new(4))
22
+ end
23
+ end
24
+
25
+ context 'on block that raises' do
26
+ context 'a covered exception' do
27
+ let(:block) { ->(_input) { fail(error_class, 'some message') } }
28
+
29
+ let(:error) do
30
+ Mutant::Transform::Error.new(
31
+ cause: nil,
32
+ input: input,
33
+ message: 'some message',
34
+ transform: subject
35
+ )
36
+ end
37
+
38
+ it 'returns expected error' do
39
+ expect(apply).to eql(Mutant::Either::Left.new(error))
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,236 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Mutant::Transform::Hash do
4
+ subject { described_class.new(attributes) }
5
+
6
+ let(:required) { [] }
7
+ let(:optional) { [] }
8
+ let(:symbol) { Mutant::Transform::Primitive.new(Symbol) }
9
+
10
+ let(:attributes) do
11
+ {
12
+ required: required,
13
+ optional: optional
14
+ }
15
+ end
16
+
17
+ describe '#apply' do
18
+ def apply
19
+ subject.apply(input)
20
+ end
21
+
22
+ context 'on Hash input' do
23
+ context 'empty' do
24
+ let(:input) { {} }
25
+
26
+ it 'returns sucess' do
27
+ expect(apply).to eql(Mutant::Either::Right.new(input))
28
+ end
29
+ end
30
+
31
+ context 'missing key' do
32
+ let(:input) { {} }
33
+ let(:required) { [described_class::Key.new(:foo, symbol)] }
34
+
35
+ let(:error) do
36
+ Mutant::Transform::Error.new(
37
+ cause: nil,
38
+ input: input,
39
+ message: 'Missing keys: [:foo], Unexpected keys: []',
40
+ transform: subject
41
+ )
42
+ end
43
+
44
+ it 'returns error' do
45
+ expect(apply).to eql(Mutant::Either::Left.new(error))
46
+ end
47
+ end
48
+
49
+ context 'extra key' do
50
+ let(:input) { { foo: :bar } }
51
+
52
+ let(:error) do
53
+ Mutant::Transform::Error.new(
54
+ cause: nil,
55
+ input: input,
56
+ message: 'Missing keys: [], Unexpected keys: [:foo]',
57
+ transform: subject
58
+ )
59
+ end
60
+
61
+ it 'returns error' do
62
+ expect(apply).to eql(Mutant::Either::Left.new(error))
63
+ end
64
+ end
65
+
66
+ context 'using required' do
67
+ let(:input) { { foo: :bar } }
68
+ let(:required) { [described_class::Key.new(:foo, symbol)] }
69
+
70
+ it 'returns success' do
71
+ expect(apply).to eql(Mutant::Either::Right.new(input))
72
+ end
73
+ end
74
+
75
+ context 'using optional' do
76
+ let(:optional) { [described_class::Key.new(:foo, symbol)] }
77
+
78
+ context 'not providing the optional key' do
79
+ let(:input) { {} }
80
+
81
+ it 'returns success' do
82
+ expect(apply).to eql(Mutant::Either::Right.new(input))
83
+ end
84
+ end
85
+
86
+ context 'providing the optional key' do
87
+ let(:input) { { foo: :bar } }
88
+
89
+ it 'returns success' do
90
+ expect(apply).to eql(Mutant::Either::Right.new(input))
91
+ end
92
+ end
93
+ end
94
+
95
+ shared_examples 'key transform error' do
96
+ let(:innermost_error) do
97
+ Mutant::Transform::Error.new(
98
+ cause: nil,
99
+ input: 'bar',
100
+ message: 'Expected: Symbol but got: String',
101
+ transform: symbol
102
+ )
103
+ end
104
+
105
+ let(:inner_error) do
106
+ Mutant::Transform::Error.new(
107
+ cause: innermost_error,
108
+ input: 'bar',
109
+ message: nil,
110
+ transform: key_transform
111
+ )
112
+ end
113
+
114
+ let(:error) do
115
+ Mutant::Transform::Error.new(
116
+ cause: inner_error,
117
+ input: input,
118
+ message: nil,
119
+ transform: subject
120
+ )
121
+ end
122
+
123
+ it 'returns failure' do
124
+ expect(apply).to eql(Mutant::Either::Left.new(error))
125
+ end
126
+ end
127
+
128
+ context 'key transform error' do
129
+ let(:input) { { foo: 'bar' } }
130
+
131
+ let(:key_transform) { described_class::Key.new(:foo, symbol) }
132
+
133
+ context 'on optional key' do
134
+ let(:optional) { [key_transform] }
135
+
136
+ include_examples 'key transform error'
137
+ end
138
+
139
+ context 'on required key' do
140
+ let(:required) { [key_transform] }
141
+
142
+ include_examples 'key transform error'
143
+ end
144
+ end
145
+ end
146
+
147
+ context 'on other input' do
148
+ let(:input) { [] }
149
+
150
+ let(:error) do
151
+ Mutant::Transform::Error.new(
152
+ cause: nil,
153
+ input: input,
154
+ message: 'Expected: Hash but got: Array',
155
+ transform: subject
156
+ )
157
+ end
158
+
159
+ it 'returns failure' do
160
+ expect(apply).to eql(Mutant::Either::Left.new(error))
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ RSpec.describe Mutant::Transform::Hash::Symbolize do
167
+ subject { described_class.new }
168
+
169
+ describe '#apply' do
170
+ def apply
171
+ subject.apply(input)
172
+ end
173
+
174
+ let(:input) { { 'foo' => 'bar' } }
175
+
176
+ it 'returns success' do
177
+ expect(apply).to eql(Mutant::Either::Right.new(foo: 'bar'))
178
+ end
179
+ end
180
+ end
181
+
182
+ RSpec.describe Mutant::Transform::Hash::Key do
183
+ subject { described_class.new(:foo, boolean) }
184
+
185
+ let(:boolean) { Mutant::Transform::Boolean.new }
186
+
187
+ describe '#slug' do
188
+ def apply
189
+ subject.slug
190
+ end
191
+
192
+ it 'returns expected slug' do
193
+ expect(apply).to eql('[:foo]')
194
+ end
195
+ end
196
+
197
+ describe '#apply' do
198
+ def apply
199
+ subject.apply(input)
200
+ end
201
+
202
+ context 'on valid input' do
203
+ let(:input) { true }
204
+
205
+ it 'returns success' do
206
+ expect(apply).to eql(Mutant::Either::Right.new(true))
207
+ end
208
+ end
209
+
210
+ context 'on invalid input' do
211
+ let(:input) { 1 }
212
+
213
+ let(:inner_error) do
214
+ Mutant::Transform::Error.new(
215
+ cause: nil,
216
+ input: 1,
217
+ message: 'Expected: boolean but got: 1',
218
+ transform: boolean
219
+ )
220
+ end
221
+
222
+ let(:error) do
223
+ Mutant::Transform::Error.new(
224
+ cause: inner_error,
225
+ input: 1,
226
+ message: nil,
227
+ transform: subject
228
+ )
229
+ end
230
+
231
+ it 'returns failure' do
232
+ expect(apply).to eql(Mutant::Either::Left.new(error))
233
+ end
234
+ end
235
+ end
236
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Mutant::Transform::Index do
4
+ subject { described_class.new(index: index, transform: transform) }
5
+
6
+ let(:index) { 1 }
7
+ let(:transform) { Mutant::Transform::Boolean.new }
8
+
9
+ describe '#slug' do
10
+ def apply
11
+ subject.slug
12
+ end
13
+
14
+ it 'retursn expected value' do
15
+ expect(apply).to eql('1')
16
+ end
17
+
18
+ it 'returns frozen value' do
19
+ expect(apply.frozen?).to be(true)
20
+ end
21
+
22
+ it 'returns idempotent value' do
23
+ expect(apply).to be(apply)
24
+ end
25
+ end
26
+
27
+ describe '#apply' do
28
+ def apply
29
+ subject.apply(input)
30
+ end
31
+
32
+ context 'on valid input' do
33
+ let(:input) { true }
34
+
35
+ it 'returns sucess' do
36
+ expect(apply).to eql(Mutant::Either::Right.new(input))
37
+ end
38
+ end
39
+
40
+ context 'on nvalid input' do
41
+ let(:input) { 1 }
42
+
43
+ let(:boolean_error) do
44
+ Mutant::Transform::Error.new(
45
+ cause: nil,
46
+ input: input,
47
+ message: 'Expected: boolean but got: 1',
48
+ transform: transform
49
+ )
50
+ end
51
+
52
+ let(:error) do
53
+ Mutant::Transform::Error.new(
54
+ cause: boolean_error,
55
+ input: input,
56
+ message: nil,
57
+ transform: subject
58
+ )
59
+ end
60
+
61
+ it 'returns failure' do
62
+ expect(apply).to eql(Mutant::Either::Left.new(error))
63
+ end
64
+ end
65
+ end
66
+
67
+ describe '.wrap' do
68
+ def apply
69
+ described_class.wrap(error, index)
70
+ end
71
+
72
+ let(:error) do
73
+ Mutant::Transform::Error.new(
74
+ cause: :nil,
75
+ input: 1,
76
+ message: nil,
77
+ transform: transform
78
+ )
79
+ end
80
+
81
+ it 'returns wrapped error' do
82
+ expect(apply).to eql(
83
+ Mutant::Transform::Error.new(
84
+ cause: error,
85
+ input: 1,
86
+ message: nil,
87
+ transform: described_class.new(index: index, transform: transform)
88
+ )
89
+ )
90
+ end
91
+ end
92
+ end