6
attr_accessor :current_story_runner
8
def scenario_from_current_story(scenario_name)
9
current_story_runner.scenario_from_current_story(scenario_name)
13
attr_accessor :stories, :scenarios, :current_story
15
def initialize(scenario_runner, world_creator = World)
16
StoryRunner.current_story_runner = self
17
@scenario_runner = scenario_runner
18
@world_creator = world_creator
20
@scenarios_by_story = {}
25
def Story(title, narrative, params = {}, &body)
26
story = Story.new(title, narrative, params, &body)
30
collector = ScenarioCollector.new(story)
31
story.run_in(collector)
32
@scenarios += collector.scenarios
33
@scenarios_by_story[story.title] = collector.scenarios
37
return if @stories.empty?
38
@listeners.each { |l| l.run_started(scenarios.size) }
39
@stories.each do |story|
40
story.assign_steps_to(World)
41
@current_story = story
42
@listeners.each { |l| l.story_started(story.title, story.narrative) }
43
scenarios = @scenarios_by_story[story.title]
44
scenarios.each do |scenario|
45
type = story[:type] || Object
46
args = story[:args] || []
47
world = @world_creator.create(type, *args)
48
@scenario_runner.run(scenario, world)
50
@listeners.each { |l| l.story_ended(story.title, story.narrative) }
51
World.step_mother.clear
53
unique_steps = (World.step_names.collect {|n| Regexp === n ? n.source : n.to_s}).uniq.sort
54
@listeners.each { |l| l.collected_steps(unique_steps) }
55
@listeners.each { |l| l.run_ended }
58
def add_listener(listener)
59
@listeners << listener
62
def scenario_from_current_story(scenario_name)
63
@scenarios_by_story[@current_story.title].find {|s| s.name == scenario_name }