ae_easy-test 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +0,0 @@
1
- module AeEasy
2
- module Test
3
- # Gem version
4
- VERSION = "0.0.3"
5
- end
6
- end
@@ -1,7 +0,0 @@
1
- require 'ae_easy_override/core/plugin'
2
- require 'ae_easy_override/core/mock'
3
-
4
- module AeEasy
5
- module Core
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- require 'ae_easy_override/core/mock/fake_executor'
2
-
3
- module AeEasy
4
- module Core
5
- module Modk
6
- end
7
- end
8
- end
@@ -1,338 +0,0 @@
1
- module AeEasy
2
- module Core
3
- module Mock
4
- module FakeExecutor
5
- # Root input directory.
6
- attr_accessor :root_input_dir
7
-
8
- # Current assigned input directory.
9
- attr_accessor :input_dir
10
-
11
- # Expand a relative input directory.
12
- #
13
- # @param [String, nil] dir Relative input directory
14
- #
15
- # @return [String] Absolute path
16
- def expand_relative_input dir
17
- return nil if dir.nil?
18
- File.expand_path File.join(root_input_dir, dir)
19
- end
20
-
21
- # Load data into executor from options or input files.
22
- #
23
- # @param [Hash] opts ({}) Configuration options.
24
- # @option opts [String,nil] :input_dir (nil) Will load files from this
25
- # directory. The files map as follows (file_name -> variable):
26
- # ```
27
- # content -> content
28
- # page.json -> page
29
- # vars.json -> page['vars']
30
- # pages.json -> saved_pages
31
- # outputs.json -> saved_outputs
32
- # ```
33
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
34
- # but relative to root input directory (see #root_input_dir).
35
- # @option opts [String,nil] :content Content to load. It will override
36
- # `content` file from input directory.
37
- # @option opts [Hash,nil] :page Page to load. It will override `page.json`
38
- # from input directory.
39
- # @option opts [Hash,nil] :vars Variables to load. It will override
40
- # `vars.json` from input directory.
41
- # @option opts [Hash,nil] :pages Pages to load. It will override
42
- # `pages.json` from input directory.
43
- # @option opts [Hash,nil] :outputs Outputs to load. It will override
44
- # `outputs.json` from input directory.
45
- #
46
- # @return [FakeExecutor]
47
- def load_input opts = {}
48
- opts = {
49
- rel_dir: nil,
50
- input_dir: nil,
51
- content: nil,
52
- page: nil,
53
- vars: nil,
54
- pages: nil,
55
- outputs: nil
56
- }.merge opts
57
- dir = self.input_dir = opts[:input_dir] || expand_relative_input(opts[:rel_dir]) || self.input_dir
58
-
59
- # Load overrides
60
- self.content = opts[:content]
61
- new_page = AeEasy::Core.deep_stringify_keys(opts[:page]) unless opts[:page].nil?
62
- save_pages opts[:pages] unless opts[:pages].nil?
63
- save_outputs opts[:outputs] unless opts[:outputs].nil?
64
- vars = nil
65
- vars = AeEasy::Core.deep_stringify_keys(opts[:vars]) unless opts[:vars]
66
-
67
- # Load input files
68
- unless dir.nil?
69
- self.content ||= AeEasy::Test::Helper.load_file(File.join(dir, 'content'))
70
- new_page ||= AeEasy::Test::Helper.load_json_file(File.join(dir, 'page.json'))
71
- input_pages = AeEasy::Test::Helper.load_json_file(File.join(dir, 'pages.json'))
72
- save_pages input_pages unless input_pages.nil?
73
- input_outputs = AeEasy::Test::Helper.load_json_file(File.join(dir, 'outputs.json'))
74
- save_outputs input_outputs unless input_outputs.nil?
75
- input_vars = AeEasy::Test::Helper.load_json_file(File.join(dir, 'vars.json'))
76
- vars ||= input_vars if opts[:page].nil?
77
- end
78
-
79
- # Load vars only when no page override and not nil
80
- self.page = new_page unless new_page.nil?
81
- page['vars'] = vars unless vars.nil?
82
- self
83
- end
84
-
85
- # Load failed content into executor from options or input files.
86
- #
87
- # @param [Hash] opts ({}) Configuration options.
88
- # @option opts [String,nil] :input_dir (nil) Will load files from this
89
- # directory. The files map as follows (file_name -> variable):
90
- # ```
91
- # failed_content.json -> failed_content
92
- # ```
93
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
94
- # but relative to root input directory (see #root_input_dir).
95
- # @option opts [Hash,nil] :failed_content Failed content to load. It
96
- # will override `failed_content.json` from input directory.
97
- #
98
- # @return [FakeExecutor]
99
- def load_failed_content opts = {}
100
- opts = {
101
- rel_dir: nil,
102
- input_dir: nil,
103
- failed_content: nil
104
- }.merge opts
105
- dir = opts[:input_dir] || expand_relative_input(opts[:rel_dir]) || self.input_dir
106
-
107
- # Load overrides
108
- self.failed_content = opts[:failed_content]
109
-
110
- # Load input files
111
- unless dir.nil?
112
- self.failed_content ||= AeEasy::Test::Helper.load_file(File.join(dir, 'failed_content.json'))
113
- end
114
-
115
- self
116
- end
117
-
118
- # Load expected pages into executor from options or input files.
119
- #
120
- # @param [Hash] opts ({}) Configuration options.
121
- # @option opts [String,nil] :input_dir (nil) Will load files from this
122
- # directory. The files map as follows (file_name -> variable):
123
- # ```
124
- # expected_pages.json -> saved_pages
125
- # ```
126
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
127
- # but relative to root input directory (see #root_input_dir).
128
- # @option opts [Hash,nil] :pages Pages to load. It will override
129
- # `expected_pages.json` from input directory.
130
- #
131
- # @return [FakeExecutor]
132
- def load_expected_pages opts = {}
133
- opts = {
134
- rel_dir: nil,
135
- input_dir: nil,
136
- pages: nil
137
- }.merge opts
138
- dir = opts[:input_dir] || expand_relative_input(opts[:rel_dir]) || self.input_dir
139
-
140
- # Load overrides
141
- save_pages opts[:pages] unless opts[:pages].nil?
142
-
143
- # Load input files
144
- unless dir.nil?
145
- expected_pages = AeEasy::Test::Helper.load_json_file(File.join(dir, 'expected_pages.json'))
146
- save_pages expected_pages unless expected_pages.nil?
147
- end
148
-
149
- self
150
- end
151
-
152
- # Load expected outputs into executor from options or input files.
153
- #
154
- # @param [Hash] opts ({}) Configuration options.
155
- # @option opts [String,nil] :input_dir (nil) Will load files from this
156
- # directory. The files map as follows (file_name -> variable):
157
- # ```
158
- # expected_outputs.json -> saved_outputs
159
- # ```
160
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
161
- # but relative to root input directory (see #root_input_dir).
162
- # @option opts [Hash,nil] :outputs Outputs to load. It will override
163
- # `expected_outputs.json` from input directory.
164
- #
165
- # @return [FakeExecutor]
166
- def load_expected_outputs opts = {}
167
- opts = {
168
- rel_dir: nil,
169
- input_dir: nil,
170
- outputs: nil
171
- }.merge opts
172
- dir = opts[:input_dir] || expand_relative_input(opts[:rel_dir]) || self.input_dir
173
-
174
- # Load overrides
175
- save_outputs opts[:outputs] unless opts[:outputs].nil?
176
-
177
- # Load input files
178
- unless dir.nil?
179
- expected_outputs = AeEasy::Test::Helper.load_json_file(File.join(dir, 'expected_outputs.json'))
180
- save_outputs expected_outputs unless expected_outputs.nil?
181
- end
182
-
183
- self
184
- end
185
-
186
- # Create an executor based on the current executor type.
187
- #
188
- # @return [AeEasy::Core::Mock::FakeExecutor]
189
- def new_executor
190
- self.class.new
191
- end
192
-
193
- # Match expected pages.
194
- #
195
- # @param [Hash] opts ({}) Configuration options.
196
- # @option opts [String,nil] :input_dir (nil) Will load files from this
197
- # directory. The files map as follows (file_name -> description):
198
- # ```
199
- # expected_pages.json -> expected pages to compare with saved_pages.
200
- # ```
201
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
202
- # but relative to root input directory (see #root_input_dir).
203
- # @option opts [Hash,nil] :pages Expected pages to load. It will override
204
- # `expected_pages.json` from input directory.
205
- # @option opts [Array] :skip_fields (nil) Fields to skip on match.
206
- # @option opts [Boolean] :default_skip_fields (true) Add `gid` and
207
- # `job_id` to the `:skip_fields` list when `true`.
208
- #
209
- # @return [Hash] A hash with the following fields:
210
- # * `[Boolean] match` `true` when match, `false` when diff.
211
- # * `[Hash] saved` Non matching saved pages.
212
- # * `[Hash] expected` Non matching expected pages.
213
- def match_expected_pages opts = {}
214
- opts = {
215
- rel_dir: nil,
216
- input_dir: nil,
217
- pages: nil,
218
- skip_fields: [],
219
- default_skip_fields: true,
220
- }.merge opts
221
- opts[:input_dir] ||= input_dir
222
-
223
- # Expected context
224
- expected_opts = {}.merge opts
225
- expected_opts[:input_dir] ||= input_dir
226
- expected = new_executor
227
- expected.root_input_dir = root_input_dir
228
- expected.load_expected_pages expected_opts
229
-
230
- # Config skip fields
231
- skip_fields = opts[:skip_fields]
232
- skip_fields += ['gid', 'job_id'] if opts[:default_skip_fields]
233
- skip_fields.uniq!
234
-
235
- # Diff
236
- diff = AeEasy::Test::Helper.match_collections(
237
- saved_pages,
238
- expected.saved_pages,
239
- skip: skip_fields,
240
- compare_way: :left
241
- )
242
- {
243
- match: diff[:match],
244
- saved: diff[:diff][:items_a],
245
- expected: diff[:diff][:items_b]
246
- }
247
- end
248
-
249
- # Match saved pages with expected and verbose diff.
250
- # {AeEasy::Test::Helper#match_expected}
251
- # @option opts [Array] :log_caller (nil) Log caller. Defaults to method
252
- # `caller`.
253
- #
254
- # @return [Boolean] `true` when pass, else `false`.
255
- def should_match_pages opts = {}
256
- flush
257
- diff = match_expected_pages opts
258
- log_caller = opts[:log_caller] || ([] + caller)
259
- unless diff[:match]
260
- AeEasy::Test.verbose_match_diff 'pages', diff, log_caller
261
- end
262
- diff[:match]
263
- end
264
-
265
- # Match expected outputs.
266
- #
267
- # @param [Hash] opts ({}) Configuration options.
268
- # @option opts [String,nil] :input_dir (nil) Will load files from this
269
- # directory. The files map as follows (file_name -> description):
270
- # ```
271
- # expected_outputs.json -> expected outputs to compare with saved_outputs.
272
- # ```
273
- # @option opts [String,nil] :rel_dir (nil) Same as +:input_dir+ option
274
- # but relative to root input directory (see #root_input_dir).
275
- # @option opts [Hash,nil] :outputs Expected outputs to load. It will
276
- # override `expected_outputs.json` from input directory.
277
- # @option opts [Array] :skip_fields (nil) Fields to skip on match.
278
- # @option opts [Boolean] :default_skip_fields (true) Add `_gid`,
279
- # `_job_id` and `_created_at` to the `:skip_fields` list when `true`.
280
- #
281
- # @return [Hash] A hash with the following structure:
282
- # * `[Boolean] match` `true` when match, `false` when diff.
283
- # * `[Hash] expected` Non matching expected outputs.
284
- # * `[Hash] saved` Non matching saved outputs.
285
- def match_expected_outputs opts = {}
286
- opts = {
287
- rel_dir: nil,
288
- input_dir: nil,
289
- outputs: nil,
290
- skip_fields: [],
291
- default_skip_fields: true,
292
- }.merge opts
293
-
294
- # Expected context
295
- expected_opts = {}.merge opts
296
- expected_opts[:input_dir] ||= input_dir
297
- expected = new_executor
298
- expected.root_input_dir = root_input_dir
299
- expected.load_expected_outputs expected_opts
300
-
301
- # Config skip fields
302
- skip_fields = opts[:skip_fields]
303
- skip_fields += ['_created_at', '_gid', '_job_id'] if opts[:default_skip_fields]
304
- skip_fields.uniq!
305
-
306
- # Diff
307
- diff = AeEasy::Test::Helper.match_collections(
308
- saved_outputs,
309
- expected.saved_outputs,
310
- skip: skip_fields,
311
- compare_way: :left
312
- )
313
- {
314
- match: diff[:match],
315
- saved: diff[:diff][:items_a],
316
- expected: diff[:diff][:items_b]
317
- }
318
- end
319
-
320
- # Match saved outputs with expected and verbose diff.
321
- # {AeEasy::Test::Helper#match_expected_outputs}
322
- # @option opts [Array] :log_caller (nil) Log caller. Defaults to method
323
- # `caller`.
324
- #
325
- # @return [Boolean] `true` when pass, else `false`.
326
- def should_match_outputs opts = {}
327
- flush
328
- diff = match_expected_outputs opts
329
- log_caller = opts[:log_caller] || ([] + caller)
330
- unless diff[:match]
331
- AeEasy::Test.verbose_match_diff 'outputs', diff, log_caller
332
- end
333
- diff[:match]
334
- end
335
- end
336
- end
337
- end
338
- end
@@ -1,8 +0,0 @@
1
- require 'ae_easy_override/core/plugin/executor_behavior'
2
-
3
- module AeEasy
4
- module Core
5
- module Plugin
6
- end
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- module AeEasy
2
- module Core
3
- module Plugin
4
- module ExecutorBehavior
5
- def test_mode?
6
- AeEasy::Test.test_mode?
7
- end
8
- end
9
- end
10
- end
11
- end