~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/lib/spec/story/runner/story_runner.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock
  • Date: 2009-04-13 17:12:47 UTC
  • mfrom: (1.2.2 upstream)
  • mto: (3.1.3 squeeze) (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20090413171247-61zlnwi5esw1lhtv
ImportĀ upstreamĀ versionĀ 0.24.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
module Spec
2
 
  module Story
3
 
    module Runner
4
 
      class StoryRunner
5
 
        class << self
6
 
          attr_accessor :current_story_runner
7
 
          
8
 
          def scenario_from_current_story(scenario_name)
9
 
            current_story_runner.scenario_from_current_story(scenario_name)
10
 
          end
11
 
        end
12
 
        
13
 
        attr_accessor :stories, :scenarios, :current_story
14
 
        
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
24
 
        
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
35
 
        
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
57
 
        
58
 
        def add_listener(listener)
59
 
          @listeners << listener
60
 
        end
61
 
        
62
 
        def scenario_from_current_story(scenario_name)
63
 
          @scenarios_by_story[@current_story.title].find {|s| s.name == scenario_name }
64
 
        end
65
 
      end
66
 
    end
67
 
  end
68
 
end