]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/story/runner/story_runner.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / story / runner / story_runner.rb
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