Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / spec / spec / story / runner_spec.rb
1 require File.dirname(__FILE__) + '/story_helper'
2 require 'spec/runner/formatter/story/plain_text_formatter'
3 require 'spec/runner/formatter/story/html_formatter'
4
5 module Spec
6   module Story
7     describe Runner, "module" do
8       before(:each) do
9         @world_creator = World.dup
10         @runner_module = Runner.dup
11         @runner_module.instance_eval {@story_runner = nil}
12         @runner_module.stub!(:register_exit_hook)
13       end
14       
15       def create_options(args=[])
16         Spec::Runner::OptionParser.parse(args, StringIO.new, StringIO.new)
17       end
18       
19       it 'should wire up a singleton StoryRunner' do
20         @runner_module.story_runner.should_not be_nil
21       end
22       
23       it 'should set its options based on ARGV' do
24         # given
25         @runner_module.should_receive(:run_options).and_return(
26           create_options(['--dry-run'])
27         )
28
29         # when
30         options = @runner_module.run_options
31         
32         # then
33         options.dry_run.should be_true
34       end
35       
36       describe "initialization" do
37         
38         before(:each) do
39           # given
40           @story_runner = mock('story runner', :null_object => true)
41           @scenario_runner = mock('scenario runner', :null_object => true)
42           @world_creator = mock('world', :null_object => true)
43         
44           @runner_module.stub!(:world_creator).and_return(@world_creator)
45           @runner_module.stub!(:create_story_runner).and_return(@story_runner)
46           @runner_module.stub!(:scenario_runner).and_return(@scenario_runner)
47         end
48
49         it 'should add a reporter to the runner classes' do
50           @runner_module.should_receive(:run_options).and_return(
51             create_options
52           )
53         
54           # expect
55           @world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
56           @story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
57           @scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::PlainTextFormatter))
58         
59           # when
60           @runner_module.story_runner
61         end
62       
63         it 'should add a documenter to the runner classes if one is specified' do
64         
65           @runner_module.should_receive(:run_options).and_return(
66             create_options(["--format","html"])
67           )
68
69           # expect
70           @world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
71           @story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
72           @scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
73         
74           # when
75           @runner_module.story_runner
76         end
77       
78         it 'should add any registered listener to the runner classes' do
79           # given
80           listener = Object.new
81         
82           # expect
83           @world_creator.should_receive(:add_listener).with(listener)
84           @story_runner.should_receive(:add_listener).with(listener)
85           @scenario_runner.should_receive(:add_listener).with(listener)
86         
87           # when
88           @runner_module.register_listener listener
89         end
90       end
91       end
92   end
93 end