Class: ParameterGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/rast/parameter_generator.rb

Overview

Generates the test parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml_path: '') ⇒ ParameterGenerator

Returns a new instance of ParameterGenerator.



16
17
18
# File 'lib/rast/parameter_generator.rb', line 16

def initialize(yaml_path: '')
  @specs_config = YAML.load_file(yaml_path)['specs'] if File.exist? yaml_path
end

Instance Attribute Details

#specs_configObject

Allow access so yaml-less can build the config via dsl.



14
15
16
# File 'lib/rast/parameter_generator.rb', line 14

def specs_config
  @specs_config
end

Instance Method Details

#generate_fixtures(spec_id: '') ⇒ Object

addCase. Generate the combinations, then add the fixture to the final list



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rast/parameter_generator.rb', line 21

def generate_fixtures(spec_id: '')
  return nil if @specs_config.nil?

  spec_config = @specs_config[spec_id]

  raise "Spec not found for: #{spec_id}. Check yaml file." if spec_config.nil?

  spec_config[:description] = spec_id

  # Keep, for backwards compatibility
  spec_config['rules'] ||= spec_config['outcomes']
  spec_config['default'] ||= spec_config['else']

  spec_config['variables'] = expand_variables(spec_config['variables'])

  spec = build_spec(spec_config)

  list = []

  variables = spec.variables
  # dict.first method returns the first key and value as an array, so invoking
  # .first, then . last would return the
  # first value.
  var_first = variables.first
  multipliers = []

  (1...variables.size).each { |i| multipliers << variables.values[i].dup }
  scenarios = var_first.last.product(*multipliers)

  add_fixtures(scenarios: scenarios, spec: spec, list: list)
  list
end