Class | Spec::Story::Runner::StoryRunner
In: | lib/spec/story/runner/story_runner.rb
Parent: | Object

### Methods

Story add_listener new run_stories scenario_from_current_story scenario_from_current_story

### Attributes

current_story | [RW] |
current_story_runner | [RW] |
scenarios | [RW] |
stories | [RW] |

### Public Class methods

new(scenario_runner, world_creator = World)

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 15
    15:         def initialize(scenario_runner, world_creator = World)
    16:           StoryRunner.current_story_runner = self
    17:           @scenario_runner = scenario_runner
    18:           @world_creator = world_creator
    19:           @stories = []
    20:           @scenarios_by_story = {}
    21:           @scenarios = []
    22:           @listeners = []
    23:         end

scenario_from_current_story(scenario_name)

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 8
     8:           def scenario_from_current_story(scenario_name)
     9:             current_story_runner.scenario_from_current_story(scenario_name)
    10:           end

### Public Instance methods

Story(title, narrative, params = {}, &body)

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 25
    25:         def Story(title, narrative, params = {}, &body)
    26:           story = Story.new(title, narrative, params, &body)
    27:           @stories << story
    28:
    29:           # collect scenarios
    30:           collector = ScenarioCollector.new(story)
    31:           story.run_in(collector)
    32:           @scenarios += collector.scenarios
    33:           @scenarios_by_story[story.title] = collector.scenarios
    34:         end

add_listener(listener)

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 60
    60:         def add_listener(listener)
    61:           @listeners << listener
    62:         end

run_stories()

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 36
    36:         def run_stories
    37:           return if @stories.empty?
    38:           @listeners.each { |l| l.run_started(scenarios.size) }
    39:           success = true
    40:           @stories.each do |story|
    41:             story.assign_steps_to(World)
    42:             @current_story = story
    43:             @listeners.each { |l| l.story_started(story.title, story.narrative) }
    44:             scenarios = @scenarios_by_story[story.title]
    45:             scenarios.each do |scenario|
    46:               type = story[:type] || Object
    47:               args = story[:args] || []
    48:               world = @world_creator.create(type, *args)
    49:               success = success & @scenario_runner.run(scenario, world)
    50:             end
    51:             @listeners.each { |l| l.story_ended(story.title, story.narrative) }
    52:             World.step_mother.clear
    53:           end
    54:           unique_steps = (World.step_names.collect {|n| Regexp === n ? n.source : n.to_s}).uniq.sort
    55:           @listeners.each { |l| l.collected_steps(unique_steps) }
    56:           @listeners.each { |l| l.run_ended }
    57:           return success
    58:         end

scenario_from_current_story(scenario_name)

[Source]

        # File lib/spec/story/runner/story_runner.rb, line 64
    64:         def scenario_from_current_story(scenario_name)
    65:           @scenarios_by_story[@current_story.title].find {|s| s.name == scenario_name }
    66:         end

[Validate]