Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / lib / spec / story / runner.rb
1 require 'spec/story/runner/scenario_collector.rb'
2 require 'spec/story/runner/scenario_runner.rb'
3 require 'spec/story/runner/story_runner.rb'
4 require 'spec/story/runner/story_parser.rb'
5 require 'spec/story/runner/story_mediator.rb'
6 require 'spec/story/runner/plain_text_story_runner.rb'
7
8 module Spec
9   module Story
10     module Runner
11       class << self
12         def run_options # :nodoc:
13           rspec_options
14           # @run_options ||= ::Spec::Runner::OptionParser.parse(ARGV, $stderr, $stdout)
15         end
16         
17         def story_runner # :nodoc:
18           unless @story_runner
19             @story_runner = create_story_runner
20             run_options.story_formatters.each do |formatter|
21               register_listener(formatter)
22             end
23             self.register_exit_hook
24           end
25           @story_runner
26         end
27         
28         def scenario_runner # :nodoc:
29           @scenario_runner ||= ScenarioRunner.new
30         end
31         
32         def world_creator # :nodoc:
33           @world_creator ||= World
34         end
35         
36         def create_story_runner
37           StoryRunner.new(scenario_runner, world_creator)
38         end
39         
40         # Use this to register a customer output formatter.
41         def register_listener(listener)
42           story_runner.add_listener(listener) # run_started, story_started, story_ended, #run_ended
43           world_creator.add_listener(listener) # found_scenario, step_succeeded, step_failed, step_failed
44           scenario_runner.add_listener(listener) # scenario_started, scenario_succeeded, scenario_pending, scenario_failed
45         end
46         
47         def register_exit_hook # :nodoc:
48           at_exit do
49             exit Runner.story_runner.run_stories unless $!
50           end
51         end
52         
53         def dry_run
54           run_options.dry_run
55         end
56         
57       end
58     end
59   end
60 end