]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/story/runner.rb
2dd36fbc65cc92976f40c561b7a3ebce2b007717
[rails.git] / vendor / gems / rspec-1.1.2 / 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           @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           # TODO - when story runner uses test/unit runners like example runner does we can kill
44           # this and also the assorted Kernel.stub!(:at_exit) in examples
45           at_exit do
46             Runner.story_runner.run_stories unless $!
47           end
48           # TODO exit with non-zero status if run fails
49         end
50         
51         def dry_run
52           run_options.dry_run
53         end
54         
55       end
56     end
57   end
58 end