Module: Synthra::Scenarios::RSpecHelpers

Defined in:
lib/synthra/scenarios.rb

Overview

RSpec integration

Instance Method Summary collapse

Instance Method Details

#include_scenario(scenario_name, **options) ⇒ Object

Include a scenario in a test

Parameters:

  • scenario_name (Symbol)

    name of scenario to include

  • options (Hash)

    options

Options Hash (**options):

  • :seed (Integer)

    random seed

Raises:

  • (ArgumentError)


356
357
358
359
360
361
362
363
364
365
366
# File 'lib/synthra/scenarios.rb', line 356

def include_scenario(scenario_name, **options)
  scenario = Scenarios[scenario_name]
  raise ArgumentError, "Unknown scenario: #{scenario_name}" unless scenario

  let(:scenario_context) { scenario.build(**options) }

  # Define let helpers for each fixture
  scenario.fixtures.keys.each do |fixture_name|
    let(fixture_name) { scenario_context[fixture_name] }
  end
end

#use_scenario(scenario_name, **options) ⇒ Object

Use scenario data in a before block



369
370
371
372
373
374
375
376
377
378
379
# File 'lib/synthra/scenarios.rb', line 369

def use_scenario(scenario_name, **options)
  before(:each) do
    scenario = Scenarios[scenario_name]
    @scenario_context = scenario.build(**options)

    # Make fixtures available as instance variables
    @scenario_context.data.each do |name, value|
      instance_variable_set("@#{name}", value)
    end
  end
end