1 require File.dirname(__FILE__) + '/../../../spec_helper'
6 describe "the main object extended with Main", :shared => true do
8 @main = Class.new do; include Main; end
9 @original_rspec_story_steps, $rspec_story_steps = $rspec_story_steps, nil
13 $rspec_story_steps = @original_rspec_story_steps
16 def have_step(type, name)
17 return simple_matcher(%[step group containing a #{type} named #{name.inspect}]) do |actual|
18 Spec::Story::Step === actual.find(type, name)
23 describe Main, "#run_story" do
24 it_should_behave_like "the main object extended with Main"
26 it "should create a PlainTextStoryRunner with run_story" do
27 Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(mock("runner", :null_object => true))
31 it "should yield the runner if arity == 1" do
32 File.should_receive(:read).with("some/path").and_return("Story: foo")
33 $main_spec_runner = nil
34 @main.run_story("some/path") do |runner|
35 $main_spec_runner = runner
37 $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
40 it "should run in the runner if arity == 0" do
41 File.should_receive(:read).with("some/path").and_return("Story: foo")
42 $main_spec_runner = nil
43 @main.run_story("some/path") do
44 $main_spec_runner = self
46 $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
49 it "should tell the PlainTextStoryRunner to run with run_story" do
50 runner = mock("runner")
51 Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(runner)
52 runner.should_receive(:run)
57 describe Main, "#steps_for" do
58 it_should_behave_like "the main object extended with Main"
60 it "should have no steps for a non existent key" do
61 @main.steps_for(:key).find(:given, "foo").should be_nil
64 it "should create steps for a key" do
65 $main_spec_invoked = false
66 @main.steps_for(:key) do
68 $main_spec_invoked = true
71 @main.steps_for(:key).find(:given, "foo").perform(Object.new, "foo")
72 $main_spec_invoked.should be_true
75 it "should append steps to steps_for a given key" do
76 @main.steps_for(:key) do
79 @main.steps_for(:key) do
82 @main.steps_for(:key).should have_step(:given, "first")
83 @main.steps_for(:key).should have_step(:given, "second")
87 describe Main, "#with_steps_for adding new steps" do
88 it_should_behave_like "the main object extended with Main"
90 it "should result in a group containing pre-existing steps and newly defined steps" do
91 first_group = @main.steps_for(:key) do
94 second_group = @main.with_steps_for(:key) do
98 second_group.should have_step(:given, "first")
99 second_group.should have_step(:given, "second")
102 it "should not add its steps to the existing group" do
103 first_group = @main.steps_for(:key) do
106 second_group = @main.with_steps_for(:key) do
110 first_group.should have_step(:given, "first")
111 first_group.should_not have_step(:given, "second")
115 describe Main, "#with_steps_for running a story" do
116 it_should_behave_like "the main object extended with Main"
119 @runner = mock("runner")
120 @runner_step_group = StepGroup.new
121 @runner.stub!(:steps).and_return(@runner_step_group)
123 Spec::Story::Runner::PlainTextStoryRunner.stub!(:new).and_return(@runner)
126 it "should create a PlainTextStoryRunner with a path" do
127 Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with('path/to/file',{}).and_return(@runner)
128 @main.with_steps_for(:foo) do
133 it "should create a PlainTextStoryRunner with a path and options" do
134 Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).with(anything,{:bar => :baz}).and_return(@runner)
135 @main.with_steps_for(:foo) do
136 run 'path/to/file', :bar => :baz
140 it "should pass the group it creates to the runner's steps" do
141 steps = @main.steps_for(:ice_cream) do
144 @main.with_steps_for(:ice_cream) do
147 @runner_step_group.should have_step(:given, "vanilla")
150 it "should run a story" do
151 @runner.should_receive(:run)
152 Spec::Story::Runner::PlainTextStoryRunner.should_receive(:new).and_return(@runner)
153 @main.with_steps_for(:foo) do