Class: Moto::Test::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/test/generator.rb

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



12
13
14
# File 'lib/test/generator.rb', line 12

def initialize
  @internal_counter = 0
end

Instance Method Details

#get_test_with_variants(test_metadata, variants_limit = 0) ⇒ Array

Method returns an array of test instances that represent all variants (parameter sets from test’s config).

Example: A test with no config file will be returned as an array with single Moto::Test::Base in it.
Example: A test with a config file and 2 sets of parameters there will be returned as array with two elements.

Parameters:

  • test_metadata (Moto::Test::Metadata)

    Metadata that describes test to be instantiated

  • variants_limit (Integer) (defaults to: 0)

    Limit how many params will be parsed per test. Default: 0 (no limit)

Returns:

  • (Array)

    An array of [Moto::Test::Base] descendants each entry is a Test with set of parameters injected



24
25
26
# File 'lib/test/generator.rb', line 24

def get_test_with_variants(, variants_limit = 0)
  variantize(, variants_limit)
end

#inject_error_to_test(test, error_message) ⇒ Object

Injects raise into test.run so it will report an error when executed

Parameters:

  • test (Moto::Test::Base)

    An instance of test that is supposed to be modified

  • error_message (String)

    Message to be attached to the raised exception



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/test/generator.rb', line 111

def inject_error_to_test(test, error_message)
  class << test
    attr_accessor :injected_error_message

    def run
      raise injected_error_message
    end
  end

  test.injected_error_message = error_message
end