Class: Bucky::Core::TestCore::TestClassGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/bucky/core/test_core/test_class_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_cond) ⇒ TestClassGenerator

Returns a new instance of TestClassGenerator.



43
44
45
46
# File 'lib/bucky/core/test_core/test_class_generator.rb', line 43

def initialize(test_cond)
  @test_classes = TestClasses
  @test_cond = test_cond
end

Instance Attribute Details

#test_classesObject

Returns the value of attribute test_classes.



41
42
43
# File 'lib/bucky/core/test_core/test_class_generator.rb', line 41

def test_classes
  @test_classes
end

Instance Method Details

#generate_test_class(data: [], linkstatus_url_log: {}, w_pipe: {}) ⇒ Object

Genrate test class by test suite and test case data



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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/bucky/core/test_core/test_class_generator.rb', line 49

def generate_test_class(data: [], linkstatus_url_log: {}, w_pipe: {})
  test_cond = @test_cond
  # Common proccessing
  # e.g.) TestSampleAppPcE2e1, TestSampleAppPcHttpstatus1
  test_class_name = make_test_class_name(data)
  # Select super class by test category
  super_suite_class = eval format('Bucky::TestEquipment::TestCase::%<test_category>sTestCase', test_category: data[:test_category].capitalize)
  # Define test suite class
  test_classes.const_set(test_class_name.to_sym, Class.new(super_suite_class) do |_klass|
    extend TestClassGeneratorHelper
    include TestClassGeneratorHelper
    define_method(:suite_data, proc { data[:suite] })
    define_method(:suite_id, proc { data[:test_suite_id] })
    define_method(:simple_test_class_name) do |original_name|
      match_obj = /\Atest_(.+)\(.+::(Test.+)\)\z/.match(original_name)
      "#{match_obj[1]}(#{match_obj[2]})"
    end
    define_method(:w_pipe, proc { w_pipe })

    # Class structure is different for each test category
    case data[:test_category]
    when 'linkstatus' then
      data[:suite][:cases].each_with_index do |t_case, i|
        method_name = make_test_method_name(data, t_case, i)
        description(
          t_case[:case_name],
          define_method(method_name) do
            puts "\n#{simple_test_class_name(name)}"
            t_case[:urls].each do |url|
              linkstatus_check_args = { url: url, device: data[:suite][:device], exclude_urls: data[:suite][:exclude_urls], link_check_max_times: test_cond[:link_check_max_times], url_log: linkstatus_url_log }
              linkstatus_check(linkstatus_check_args)
            end
          end
        )
      end

    when 'e2e' then
      if data[:suite][:setup_each]
        def setup
          super
          puts "[setup]#{simple_test_class_name(name)}"
          add_test_procedure(suite_data[:setup_each][:procs])
        end
      end

      if data[:suite][:teardown_each]
        def teardown
          puts "[teardown]#{simple_test_class_name(name)}"
          add_test_procedure(suite_data[:teardown_each][:procs])
          super
        end
      end

      # Generate test case method
      data[:suite][:cases].each_with_index do |t_case, i|
        # e.g.) test_sample_app_pc_e2e_1_2
        method_name = make_test_method_name(data, t_case, i)
        method_obj = proc do
          puts "\n#{simple_test_class_name(name)}\n #{t_case[:desc]} ...."
          add_test_procedure(t_case[:procs])
        end
        description(t_case[:case_name], define_method(method_name, method_obj))
      end
    end
  end)
end