Module: AeEasy::Core::Mock::FakeExecutor
- Defined in:
- lib/ae_easy_override/core/mock/fake_executor.rb
Instance Attribute Summary collapse
-
#input_dir ⇒ Object
Current assigned input directory.
-
#root_input_dir ⇒ Object
Root input directory.
Instance Method Summary collapse
-
#expand_relative_input(dir) ⇒ String
Expand a relative input directory.
-
#load_expected_outputs(opts = {}) ⇒ FakeExecutor
Load expected outputs into executor from options or input files.
-
#load_expected_pages(opts = {}) ⇒ FakeExecutor
Load expected pages into executor from options or input files.
-
#load_failed_content(opts = {}) ⇒ FakeExecutor
Load failed content into executor from options or input files.
-
#load_input(opts = {}) ⇒ FakeExecutor
Load data into executor from options or input files.
-
#match_expected_outputs(opts = {}) ⇒ Hash
Match expected outputs.
-
#match_expected_pages(opts = {}) ⇒ Hash
Match expected pages.
-
#new_executor ⇒ AeEasy::Core::Mock::FakeExecutor
Create an executor based on the current executor type.
-
#should_match_outputs(opts = {}) ⇒ Boolean
Match saved outputs with expected and verbose diff.
-
#should_match_pages(opts = {}) ⇒ Boolean
Match saved pages with expected and verbose diff.
Instance Attribute Details
#input_dir ⇒ Object
Current assigned input directory.
9 10 11 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 9 def input_dir @input_dir end |
#root_input_dir ⇒ Object
Root input directory.
6 7 8 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 6 def root_input_dir @root_input_dir end |
Instance Method Details
#expand_relative_input(dir) ⇒ String
Expand a relative input directory.
16 17 18 19 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 16 def dir return nil if dir.nil? File. File.join(root_input_dir, dir) end |
#load_expected_outputs(opts = {}) ⇒ FakeExecutor
Load expected outputs into executor from options or input files.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 166 def load_expected_outputs opts = {} opts = { rel_dir: nil, input_dir: nil, outputs: nil }.merge opts dir = opts[:input_dir] || (opts[:rel_dir]) || self.input_dir # Load overrides save_outputs opts[:outputs] unless opts[:outputs].nil? # Load input files unless dir.nil? expected_outputs = AeEasy::Test::Helper.load_json_file(File.join(dir, 'expected_outputs.json')) save_outputs expected_outputs unless expected_outputs.nil? end self end |
#load_expected_pages(opts = {}) ⇒ FakeExecutor
Load expected pages into executor from options or input files.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 132 def load_expected_pages opts = {} opts = { rel_dir: nil, input_dir: nil, pages: nil }.merge opts dir = opts[:input_dir] || (opts[:rel_dir]) || self.input_dir # Load overrides save_pages opts[:pages] unless opts[:pages].nil? # Load input files unless dir.nil? expected_pages = AeEasy::Test::Helper.load_json_file(File.join(dir, 'expected_pages.json')) save_pages expected_pages unless expected_pages.nil? end self end |
#load_failed_content(opts = {}) ⇒ FakeExecutor
Load failed content into executor from options or input files.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 99 def load_failed_content opts = {} opts = { rel_dir: nil, input_dir: nil, failed_content: nil }.merge opts dir = opts[:input_dir] || (opts[:rel_dir]) || self.input_dir # Load overrides self.failed_content = opts[:failed_content] # Load input files unless dir.nil? self.failed_content ||= AeEasy::Test::Helper.load_file(File.join(dir, 'failed_content.json')) end self end |
#load_input(opts = {}) ⇒ FakeExecutor
Load data into executor from options or input files.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 47 def load_input opts = {} opts = { rel_dir: nil, input_dir: nil, content: nil, page: nil, vars: nil, pages: nil, outputs: nil }.merge opts dir = self.input_dir = opts[:input_dir] || (opts[:rel_dir]) || self.input_dir # Load overrides self.content = opts[:content] new_page = AeEasy::Core.deep_stringify_keys(opts[:page]) unless opts[:page].nil? save_pages opts[:pages] unless opts[:pages].nil? save_outputs opts[:outputs] unless opts[:outputs].nil? vars = nil vars = AeEasy::Core.deep_stringify_keys(opts[:vars]) unless opts[:vars] # Load input files unless dir.nil? self.content ||= AeEasy::Test::Helper.load_file(File.join(dir, 'content')) new_page ||= AeEasy::Test::Helper.load_json_file(File.join(dir, 'page.json')) input_pages = AeEasy::Test::Helper.load_json_file(File.join(dir, 'pages.json')) save_pages input_pages unless input_pages.nil? input_outputs = AeEasy::Test::Helper.load_json_file(File.join(dir, 'outputs.json')) save_outputs outputs unless input_outputs.nil? input_vars = AeEasy::Test::Helper.load_json_file(File.join(dir, 'vars.json')) vars ||= input_vars if opts[:page].nil? end # Load vars only when no page override and not nil self.page = new_page unless new_page.nil? page['vars'] = vars unless vars.nil? self end |
#match_expected_outputs(opts = {}) ⇒ Hash
Match expected outputs.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 285 def match_expected_outputs opts = {} opts = { rel_dir: nil, input_dir: nil, outputs: nil, skip_fields: [], default_skip_fields: true, }.merge opts # Expected context expected_opts = {}.merge opts expected_opts[:input_dir] ||= input_dir expected = new_executor expected.root_input_dir = root_input_dir expected.load_expected_outputs expected_opts # Config skip fields skip_fields = opts[:skip_fields] skip_fields += ['_created_at', '_gid', '_job_id'] if opts[:default_skip_fields] skip_fields.uniq! # Diff diff = AeEasy::Test::Helper.match_collections( saved_outputs, expected.saved_outputs, skip: skip_fields, compare_way: :left ) { match: diff[:match], saved: diff[:diff][:items_a], expected: diff[:diff][:items_b] } end |
#match_expected_pages(opts = {}) ⇒ Hash
Match expected pages.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 213 def match_expected_pages opts = {} opts = { rel_dir: nil, input_dir: nil, pages: nil, skip_fields: [], default_skip_fields: true, }.merge opts opts[:input_dir] ||= input_dir # Expected context expected_opts = {}.merge opts expected_opts[:input_dir] ||= input_dir expected = new_executor expected.root_input_dir = root_input_dir expected.load_expected_pages expected_opts # Config skip fields skip_fields = opts[:skip_fields] skip_fields += ['gid', 'job_id'] if opts[:default_skip_fields] skip_fields.uniq! # Diff diff = AeEasy::Test::Helper.match_collections( saved_pages, expected.saved_pages, skip: skip_fields, compare_way: :left ) { match: diff[:match], saved: diff[:diff][:items_a], expected: diff[:diff][:items_b] } end |
#new_executor ⇒ AeEasy::Core::Mock::FakeExecutor
Create an executor based on the current executor type.
189 190 191 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 189 def new_executor self.class.new end |
#should_match_outputs(opts = {}) ⇒ Boolean
Match saved outputs with expected and verbose diff. Test::Helper#match_expected_outputs
326 327 328 329 330 331 332 333 334 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 326 def should_match_outputs opts = {} flush diff = match_expected_outputs opts log_caller = opts[:log_caller] || ([] + caller) unless diff[:match] AeEasy::Test.verbose_match_diff 'outputs', diff, log_caller end diff[:match] end |
#should_match_pages(opts = {}) ⇒ Boolean
Match saved pages with expected and verbose diff. Test::Helper#match_expected
255 256 257 258 259 260 261 262 263 |
# File 'lib/ae_easy_override/core/mock/fake_executor.rb', line 255 def should_match_pages opts = {} flush diff = match_expected_pages opts log_caller = opts[:log_caller] || ([] + caller) unless diff[:match] AeEasy::Test.verbose_match_diff 'pages', diff, log_caller end diff[:match] end |