adding all of botlist, initial add
[botlist.git] / openbotlist / WEB-INF / lib / ruby / rspec / lib / spec / story / runner.rb
blob1f6dd9e7a6e59e5cba02ca002c8d1eee9db59ffc
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'
8 module Spec
9   module Story
10     module Runner
11       class << self
12         def run_options # :nodoc:
13           @run_options ||= ::Spec::Runner::OptionParser.parse(ARGV, $stderr, $stdout)
14         end
15         
16         def story_runner # :nodoc:
17           unless @story_runner
18             @story_runner = StoryRunner.new(scenario_runner, world_creator)
19             run_options.story_formatters.each do |formatter|
20               register_listener(formatter)
21             end
22             Runner.register_exit_hook
23           end
24           @story_runner
25         end
26         
27         def scenario_runner # :nodoc:
28           @scenario_runner ||= ScenarioRunner.new
29         end
30         
31         def world_creator # :nodoc:
32           @world_creator ||= World
33         end
34         
35         # Use this to register a customer output formatter.
36         def register_listener(listener)
37           story_runner.add_listener(listener) # run_started, story_started, story_ended, #run_ended
38           world_creator.add_listener(listener) # found_scenario, step_succeeded, step_failed, step_failed
39           scenario_runner.add_listener(listener) # scenario_started, scenario_succeeded, scenario_pending, scenario_failed
40         end
41         
42         def register_exit_hook # :nodoc:
43           at_exit do
44             Runner.story_runner.run_stories unless $!
45           end
46           # TODO exit with non-zero status if run fails
47         end
48         
49         def dry_run
50           run_options.dry_run
51         end
52         
53       end
54     end
55   end
56 end