1 require File.dirname(__FILE__) + '/../story_helper'
7 describe StoryMediator 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" }
15 @scenario_runner = ScenarioRunner.new
16 @runner = StoryRunner.new @scenario_runner
17 @mediator = StoryMediator.new @step_group, @runner
25 it "should have no stories" do
26 @mediator.stories.should be_empty
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"
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"
41 it "should create a scenario" do
42 @mediator.create_story "title", "narrative"
43 @mediator.create_scenario "scenario name"
46 @runner.should have(1).scenarios
47 @runner.scenarios.first.name.should == "scenario name"
48 @runner.scenarios.first.story.should == @runner.stories.first
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"
59 $story_mediator_spec_value.should == "previous scenario matched"
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"
69 $story_mediator_spec_value.should == "given matched"
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
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"
88 $story_mediator_spec_value.should == "when matched"
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
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"
107 $story_mediator_spec_value.should == "then matched"
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
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"
126 @runner.stories.first[:foo].should == :bar