1 require File.dirname(__FILE__) + '/../story_helper'
6 describe PlainTextStoryRunner do
8 StoryParser.stub!(:new).and_return(@parser = mock("parser"))
9 @parser.stub!(:parse).and_return([])
10 File.stub!(:read).with("path").and_return("this\nand that")
13 it "should provide access to steps" do
14 runner = PlainTextStoryRunner.new("path")
20 runner.steps.find(:given, "baz").should_not be_nil
23 it "should parse a story file" do
24 runner = PlainTextStoryRunner.new("path")
29 @parser.should_receive(:parse).with(["this", "and that"])
33 it "should build up a mediator with its own steps and the singleton story_runner" do
34 runner = PlainTextStoryRunner.new("path")
35 Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner"))
36 Spec::Story::Runner::StoryMediator.should_receive(:new).with(runner.steps, story_runner, {}).
37 and_return(mediator = stub("mediator", :run_stories => nil))
41 it "should build up a parser with the mediator" do
42 runner = PlainTextStoryRunner.new("path")
43 Spec::Story::Runner.should_receive(:story_runner).and_return(story_runner = mock("story runner"))
44 Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator = stub("mediator", :run_stories => nil))
45 Spec::Story::Runner::StoryParser.should_receive(:new).with(mediator).and_return(@parser)
49 it "should tell the mediator to run the stories" do
50 runner = PlainTextStoryRunner.new("path")
51 mediator = mock("mediator")
52 Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator)
53 mediator.should_receive(:run_stories)
57 it "should accept a block instead of a path" do
58 runner = PlainTextStoryRunner.new do |runner|
59 runner.load("path/to/story")
61 File.should_receive(:read).with("path/to/story").and_return("this\nand that")
65 it "should tell you if you try to run with no path set" do
66 runner = PlainTextStoryRunner.new
69 }.should raise_error(RuntimeError, "You must set a path to the file with the story. See the RDoc.")
72 it "should pass options to the mediator" do
73 runner = PlainTextStoryRunner.new("path", :foo => :bar)
74 Spec::Story::Runner::StoryMediator.should_receive(:new).
75 with(anything, anything, :foo => :bar).
76 and_return(mediator = stub("mediator", :run_stories => nil))
80 it "should provide access to its options" do
81 runner = PlainTextStoryRunner.new("path")
83 Spec::Story::Runner::StoryMediator.should_receive(:new).
84 with(anything, anything, :foo => :bar).
85 and_return(mediator = stub("mediator", :run_stories => nil))