Class: Qualspec::Suite::VariantsConfig
- Inherits:
-
Object
- Object
- Qualspec::Suite::VariantsConfig
- Defined in:
- lib/qualspec/suite/dsl.rb
Overview
Configuration for variant generation
Instance Attribute Summary collapse
-
#factory_name ⇒ Object
readonly
Returns the value of attribute factory_name.
-
#trait_combinations ⇒ Object
readonly
Returns the value of attribute trait_combinations.
-
#variant_definitions ⇒ Object
readonly
Returns the value of attribute variant_definitions.
Instance Method Summary collapse
-
#build_variants ⇒ Object
Build all variant instances.
-
#initialize(factory: :prompt_variant, &block) ⇒ VariantsConfig
constructor
A new instance of VariantsConfig.
-
#trait_matrix(*dimensions) ⇒ Object
DSL: Define a trait matrix for combinatorial testing Each argument is an array of traits for that dimension.
-
#variant(name, traits: [], **attributes) ⇒ Object
DSL: Define an individual named variant.
Constructor Details
#initialize(factory: :prompt_variant, &block) ⇒ VariantsConfig
Returns a new instance of VariantsConfig.
77 78 79 80 81 82 83 |
# File 'lib/qualspec/suite/dsl.rb', line 77 def initialize(factory: :prompt_variant, &block) @factory_name = factory @variant_definitions = [] @trait_combinations = nil instance_eval(&block) if block_given? # rubocop:disable Style/EvalWithLocation -- DSL pattern end |
Instance Attribute Details
#factory_name ⇒ Object (readonly)
Returns the value of attribute factory_name.
75 76 77 |
# File 'lib/qualspec/suite/dsl.rb', line 75 def factory_name @factory_name end |
#trait_combinations ⇒ Object (readonly)
Returns the value of attribute trait_combinations.
75 76 77 |
# File 'lib/qualspec/suite/dsl.rb', line 75 def trait_combinations @trait_combinations end |
#variant_definitions ⇒ Object (readonly)
Returns the value of attribute variant_definitions.
75 76 77 |
# File 'lib/qualspec/suite/dsl.rb', line 75 def variant_definitions @variant_definitions end |
Instance Method Details
#build_variants ⇒ Object
Build all variant instances
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/qualspec/suite/dsl.rb', line 111 def build_variants variants = [] # Build explicitly defined variants @variant_definitions.each do |defn| variants << build_variant(defn[:name], defn[:traits], defn[:attributes]) end # Build matrix variants if defined @trait_combinations&.each do |trait_combo| name = trait_combo.join('_') variants << build_variant(name, trait_combo, {}) end # Default to a single empty variant if nothing defined variants << build_default_variant if variants.empty? # Deduplicate by name, preserving first occurrence seen = {} variants.select { |v| !seen.key?(v.name) && (seen[v.name] = true) } end |
#trait_matrix(*dimensions) ⇒ Object
DSL: Define a trait matrix for combinatorial testing Each argument is an array of traits for that dimension.
100 101 102 103 104 105 106 107 108 |
# File 'lib/qualspec/suite/dsl.rb', line 100 def trait_matrix(*dimensions) raise ArgumentError, 'trait_matrix requires at least 1 dimension' if dimensions.empty? dimensions.each_with_index do |dim, i| raise ArgumentError, "trait_matrix dimension #{i} must be a non-empty array" unless dim.is_a?(Array) && !dim.empty? end @trait_combinations = dimensions.first.product(*dimensions[1..]) end |
#variant(name, traits: [], **attributes) ⇒ Object
DSL: Define an individual named variant
86 87 88 89 90 91 92 |
# File 'lib/qualspec/suite/dsl.rb', line 86 def variant(name, traits: [], **attributes) @variant_definitions << { name: name, traits: Array(traits), attributes: attributes } end |