Sha256: 16bba9c6d2fe7e9f6f8675764179b5b317feca4ae4c38df608bd5657dca946ab

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

require 'hashie/mash'

# Fabricates test manifests (.polytrix.yml files)
LANGUAGES = %w(java ruby python nodejs c# golang php)
SAMPLE_NAMES = [
  'hello world',
  'quine',
  'my_kata'
]

Fabricator(:manifest, from: Polytrix::Manifest) do
  initialize_with { @_klass.new to_hash } # Hash based initialization
  transient suite_count: 3
  transient samples_per_suite: 3
  implementors do
    Fabricate(:implementor)
  end
  global_env do
    {
      VAR1: 1,
      VAR2: 2
    }
  end
  suites do |attr|
    suite_count = attr[:suite_count]
    if suite_count
      suites = attr[:suite_count].times.reduce({}) do |h, i|
        name = LANGUAGES[i] ||= "suite_#{i}"
        h[name] = Fabricate(:suite, name: name, sample_count: attr[:samples_per_suite])
        h
      end
      suites
    else
      nil
    end
  end
end

Fabricator(:suite, from: Hashie::Mash) do
  initialize_with { @_klass.new to_hash } # Hash based initialization
  transient name: LANGUAGES[0]
  transient sample_count: 3
  samples do |attr|
    sample_count = attr[:sample_count]
    if sample_count
      attr[:sample_count].times.map do |i|
        SAMPLE_NAMES[i] ||= "sample_#{i}"
      end
    else
      nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
polytrix-0.1.2 spec/fabricators/manifest_fabricator.rb
polytrix-0.1.1 spec/fabricators/manifest_fabricator.rb
polytrix-0.1.0 spec/fabricators/manifest_fabricator.rb