Class: Spec::Story::Runner::StoryRunner

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 58
    58:         def add_listener(listener)
    59:           @listeners << listener
    60:         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:           @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)
    49:             end
    50:             @listeners.each { |l| l.story_ended(story.title, story.narrative) }
    51:             World.step_mother.clear
    52:           end
    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 }
    56:         end

scenario_from_current_story(scenario_name)

[Source]

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

[Validate]