changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/story/runner_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/story_helper'
2
3module Spec
4 module Story
5 describe Runner, "module" do
6 def dev_null
7 io = StringIO.new
8 def io.write(str)
9 str.to_s.size
10 end
11 return io
12 end
13
14 before :each do
15 Kernel.stub!(:at_exit)
16 @stdout, $stdout = $stdout, dev_null
17 @argv = Array.new(ARGV)
18 @runner_module = Runner.dup
19 @world_creator = World.dup
20 @runner_module.module_eval { @run_options = @story_runner = @scenario_runner = @world_creator = nil }
21 end
22
23 after :each do
24 $stdout = @stdout
25 ARGV.replace @argv
26 @runner_module.module_eval { @run_options = @story_runner = @scenario_runner = @world_creator = nil }
27 end
28
29 it 'should wire up a singleton StoryRunner' do
30 @runner_module.story_runner.should_not be_nil
31 end
32
33 it 'should set its options based on ARGV' do
34 # given
35 ARGV << '--dry-run'
36
37 # when
38 options = @runner_module.run_options
39
40 # then
41 options.dry_run.should be_true
42 end
43
44 it 'should add a reporter to the runner classes' do
45 # given
46 story_runner = mock('story runner', :null_object => true)
47 scenario_runner = mock('scenario runner', :null_object => true)
48 world_creator = mock('world', :null_object => true)
49
50 @runner_module::class_eval { @world_creator = world_creator }
51 @runner_module::StoryRunner.stub!(:new).and_return(story_runner)
52 @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner)
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 # given
65 ARGV << "--format" << "html"
66 story_runner = mock('story runner', :null_object => true)
67 scenario_runner = mock('scenario runner', :null_object => true)
68 world_creator = mock('world', :null_object => true)
69
70 @runner_module::class_eval { @world_creator = world_creator }
71 @runner_module::StoryRunner.stub!(:new).and_return(story_runner)
72 @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner)
73
74 # expect
75 world_creator.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
76 story_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
77 scenario_runner.should_receive(:add_listener).with(an_instance_of(Spec::Runner::Formatter::Story::HtmlFormatter))
78
79 # when
80 @runner_module.story_runner
81 end
82
83 it 'should add any registered listener to the runner classes' do
84 # given
85 ARGV << "--format" << "html"
86 story_runner = mock('story runner', :null_object => true)
87 scenario_runner = mock('scenario runner', :null_object => true)
88 world_creator = mock('world', :null_object => true)
89
90 @runner_module::class_eval { @world_creator = world_creator }
91 @runner_module::StoryRunner.stub!(:new).and_return(story_runner)
92 @runner_module::ScenarioRunner.stub!(:new).and_return(scenario_runner)
93
94 listener = Object.new
95
96 # expect
97 world_creator.should_receive(:add_listener).with(listener)
98 story_runner.should_receive(:add_listener).with(listener)
99 scenario_runner.should_receive(:add_listener).with(listener)
100
101 # when
102 @runner_module.register_listener listener
103 end
104 end
105 end
106end