Module: Synthra::Scenarios
- Defined in:
- lib/synthra/scenarios.rb
Overview
Scenario-based Test Data Fixtures
Define complex, interconnected test data scenarios that can be easily reused across tests. Think "Fixtures 2.0" - dynamic, relationship-aware, and DRY.
Defined Under Namespace
Modules: MinitestHelpers, RSpecHelpers Classes: FixtureDefinition, LazyFixture, Scenario, ScenarioContext
Class Method Summary collapse
-
.[](name) ⇒ Scenario?
Get a scenario by name.
-
.define(name, **options) { ... } ⇒ Scenario
Define a new scenario.
-
.list ⇒ Array<Symbol>
List all defined scenarios.
-
.load_dir(dir) ⇒ Object
Load all scenarios from a directory.
-
.load_file(path) ⇒ Object
Load scenarios from a file.
-
.registry ⇒ Object
Registry of defined scenarios.
-
.reset! ⇒ Object
Clear all scenarios.
Class Method Details
.[](name) ⇒ Scenario?
Get a scenario by name
55 56 57 |
# File 'lib/synthra/scenarios.rb', line 55 def [](name) registry[name] end |
.define(name, **options) { ... } ⇒ Scenario
Define a new scenario
43 44 45 46 47 48 |
# File 'lib/synthra/scenarios.rb', line 43 def define(name, **, &block) scenario = Scenario.new(name, **) scenario.instance_eval(&block) if block registry[name] = scenario scenario end |
.list ⇒ Array<Symbol>
List all defined scenarios
63 64 65 |
# File 'lib/synthra/scenarios.rb', line 63 def list registry.keys end |
.load_dir(dir) ⇒ Object
Load all scenarios from a directory
80 81 82 83 84 |
# File 'lib/synthra/scenarios.rb', line 80 def load_dir(dir) Dir.glob(File.join(dir, "**/*.rb")).each do |file| load_file(file) end end |
.load_file(path) ⇒ Object
Load scenarios from a file
71 72 73 74 |
# File 'lib/synthra/scenarios.rb', line 71 def load_file(path) content = File.read(path) instance_eval(content, path) end |
.registry ⇒ Object
Registry of defined scenarios
31 32 33 |
# File 'lib/synthra/scenarios.rb', line 31 def registry @registry ||= {} end |
.reset! ⇒ Object
Clear all scenarios
87 88 89 |
# File 'lib/synthra/scenarios.rb', line 87 def reset! @registry = {} end |