Module: Emendate::Examples::TranslationTestable

Defined in:
lib/emendate/examples/translation_testable.rb

Overview

Mixin module for Examples::Tester

Instance Method Summary collapse

Instance Method Details

#expected_resultObject



9
10
11
12
13
# File 'lib/emendate/examples/translation_testable.rb', line 9

def expected_result
  return nil unless example.testable?

  example.rows.map { |row| row.send(name.to_sym) }
end

#tested_resultObject



15
16
17
18
19
20
21
22
# File 'lib/emendate/examples/translation_testable.rb', line 15

def tested_result
  return nil unless example.testable?

  result = translate
  return "nilValue" if result.values.nil?

  result.values
end

#translateObject



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/emendate/examples/translation_testable.rb', line 24

def translate
  pm = Emendate::ProcessingManager.new(
    example.test_string,
    **translate_options
  )
  pm.call
  result = Emendate::Translator.call(pm)
rescue => err
  example.add_error(name.to_sym, Emendate::ErrorUtil.msg(err))
  nil
else
  result
end

#translate_optionsObject



38
39
40
41
42
43
44
45
46
# File 'lib/emendate/examples/translation_testable.rb', line 38

def translate_options
  translate_opt = {dialect: name.delete_prefix("translation_").to_sym}
  if example.test_options
    instance_eval("{#{example.test_options}}", __FILE__,
      __LINE__ - 1).merge(translate_opt)
  else
    translate_opt
  end
end