Updated to latest rspec
[gitorious:georgyos-clone.git] / vendor / plugins / rspec / spec / spec / story / runner / story_mediator_spec.rb
1 require File.dirname(__FILE__) + '/../story_helper'
2
3 module Spec
4   module Story
5     module Runner
6       
7       describe StoryMediator do
8         before(:each) do
9           $story_mediator_spec_value = nil
10           @step_group = StepGroup.new
11           @step_group.create_matcher(:given, "given") { $story_mediator_spec_value = "given matched" }
12           @step_group.create_matcher(:when, "when") { $story_mediator_spec_value = "when matched" }
13           @step_group.create_matcher(:then, "then") { $story_mediator_spec_value = "then matched" }
14           
15           @scenario_runner = ScenarioRunner.new
16           @runner = StoryRunner.new @scenario_runner
17           @mediator = StoryMediator.new @step_group, @runner
18         end
19         
20         def run_stories
21           @mediator.run_stories
22           @runner.run_stories
23         end
24         
25         it "should have no stories" do
26           @mediator.stories.should be_empty
27         end
28         
29         it "should create two stories" do
30           @mediator.create_story "story title", "story narrative"
31           @mediator.create_story "story title 2", "story narrative 2"
32           run_stories
33           
34           @runner.should have(2).stories
35           @runner.stories.first.title.should == "story title"
36           @runner.stories.first.narrative.should == "story narrative"
37           @runner.stories.last.title.should == "story title 2"
38           @runner.stories.last.narrative.should == "story narrative 2"
39         end
40         
41         it "should create a scenario" do
42           @mediator.create_story "title", "narrative"
43           @mediator.create_scenario "scenario name"
44           run_stories
45           
46           @runner.should have(1).scenarios
47           @runner.scenarios.first.name.should == "scenario name"
48           @runner.scenarios.first.story.should == @runner.stories.first
49         end
50         
51         it "should create a given scenario step if one matches" do
52           pending("need to untangle the dark mysteries of the story runner - something needs to get stubbed here") do
53             story = @mediator.create_story "title", "narrative"
54             @mediator.create_scenario "previous scenario"
55             @mediator.create_scenario "current scenario"
56             @mediator.create_given_scenario "previous scenario"
57             run_stories
58           
59             $story_mediator_spec_value.should == "previous scenario matched"
60           end
61         end
62                 
63         it "should create a given step if one matches" do
64           @mediator.create_story "title", "narrative"
65           @mediator.create_scenario "scenario"
66           @mediator.create_given "given"
67           run_stories
68           
69           $story_mediator_spec_value.should == "given matched"
70         end
71         
72         it "should create a pending step if no given step matches" do
73           @mediator.create_story "title", "narrative"
74           @mediator.create_scenario "scenario"
75           @mediator.create_given "no match"
76           mock_listener = stub_everything("listener")
77           mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match")
78           @scenario_runner.add_listener mock_listener
79           run_stories
80         end
81         
82         it "should create a when step if one matches" do
83           @mediator.create_story "title", "narrative"
84           @mediator.create_scenario "scenario"
85           @mediator.create_when "when"
86           run_stories
87           
88           $story_mediator_spec_value.should == "when matched"
89         end
90         
91         it "should create a pending step if no when step matches" do
92           @mediator.create_story "title", "narrative"
93           @mediator.create_scenario "scenario"
94           @mediator.create_when "no match"
95           mock_listener = stub_everything("listener")
96           mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match")
97           @scenario_runner.add_listener mock_listener
98           run_stories
99         end
100         
101         it "should create a then step if one matches" do
102           @mediator.create_story "title", "narrative"
103           @mediator.create_scenario "scenario"
104           @mediator.create_then "then"
105           run_stories
106           
107           $story_mediator_spec_value.should == "then matched"
108         end
109         
110         it "should create a pending step if no 'then' step matches" do
111           @mediator.create_story "title", "narrative"
112           @mediator.create_scenario "scenario"
113           @mediator.create_then "no match"
114           mock_listener = stub_everything("listener")
115           mock_listener.should_receive(:scenario_pending).with("title", "scenario", "Unimplemented step: no match")
116           @scenario_runner.add_listener mock_listener
117           run_stories
118         end
119         
120         it "should pass options to the stories it creates" do
121           @mediator = StoryMediator.new @step_group, @runner, :foo => :bar
122           @mediator.create_story "story title", "story narrative"
123         
124           run_stories
125           
126           @runner.stories.first[:foo].should == :bar
127         end
128         
129         it "should description" do
130           @mediator = StoryMediator.new @step_group, @runner, :foo => :bar
131           @mediator.create_story "title", "narrative"
132           @mediator.create_scenario "scenario"
133           @mediator.create_given "something"
134           given = @mediator.last_step
135           @mediator.add_to_last " else"
136           given.name.should == "something else"
137         end
138         
139       end
140       
141     end
142   end
143 end