Blob of rspec/spec/spec/story/runner/plain_text_story_runner_spec.rb (raw blob data)

1 require File.dirname(__FILE__) + '/../story_helper'
2
3 module Spec
4 module Story
5 module Runner
6 describe PlainTextStoryRunner do
7 before(:each) 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")
11 end
12
13 it "should provide access to steps" do
14 runner = PlainTextStoryRunner.new("path")
15
16 runner.steps do |add|
17 add.given("baz") {}
18 end
19
20 runner.steps.find(:given, "baz").should_not be_nil
21 end
22
23 it "should parse a story file" do
24 runner = PlainTextStoryRunner.new("path")
25 during {
26 runner.run(mock('runner'))
27 }.expect {
28 @parser.should_receive(:parse).with(["this", "and that"])
29 }
30 end
31
32 it "should build up a mediator with its own steps and the singleton story_runner" do
33 @story_runner = mock('story runner', :null_object => true)
34
35 runner = PlainTextStoryRunner.new("path")
36
37 Spec::Story::Runner::StoryMediator.should_receive(:new).with(
38 runner.steps, @story_runner, {}
39 ).and_return(mediator = stub("mediator", :run_stories => nil))
40 runner.run(@story_runner)
41 end
42
43 it "should build up a parser with the mediator" do
44 runner = PlainTextStoryRunner.new("path")
45 Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator = stub("mediator", :run_stories => nil))
46 Spec::Story::Runner::StoryParser.should_receive(:new).with(mediator).and_return(@parser)
47 runner.run(stub("story_runner"))
48 end
49
50 it "should tell the mediator to run the stories" do
51 runner = PlainTextStoryRunner.new("path")
52 mediator = mock("mediator")
53 Spec::Story::Runner::StoryMediator.should_receive(:new).and_return(mediator)
54 mediator.should_receive(:run_stories)
55 runner.run(mock('runner'))
56 end
57
58 it "should accept a block instead of a path" do
59 runner = PlainTextStoryRunner.new do |runner|
60 runner.load("path/to/story")
61 end
62 File.should_receive(:read).with("path/to/story").and_return("this\nand that")
63 runner.run(mock('runner'))
64 end
65
66 it "should tell you if you try to run with no path set" do
67 runner = PlainTextStoryRunner.new
68 lambda {
69 runner.run(mock('runner'))
70 }.should raise_error(RuntimeError, "You must set a path to the file with the story. See the RDoc.")
71 end
72
73 it "should pass options to the mediator" do
74 runner = PlainTextStoryRunner.new("path", :foo => :bar)
75 Spec::Story::Runner::StoryMediator.should_receive(:new).
76 with(anything, anything, :foo => :bar).
77 and_return(mediator = stub("mediator", :run_stories => nil))
78 runner.run(mock('runner'))
79 end
80
81 it "should provide access to its options" do
82 runner = PlainTextStoryRunner.new("path")
83 runner[:foo] = :bar
84 Spec::Story::Runner::StoryMediator.should_receive(:new).
85 with(anything, anything, :foo => :bar).
86 and_return(mediator = stub("mediator", :run_stories => nil))
87 runner.run mock('runner')
88 end
89
90 end
91 end
92 end
93 end