changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/story/extensions/main_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../spec_helper'
2
3module Spec
4 module Story
5 module Extensions
6 describe "the main object extended with Main", :shared => true do
7 before(:each) do
8 @main = Class.new do; include Main; end
9 @original_rspec_story_steps, $rspec_story_steps = $rspec_story_steps, nil
10 end
11
12 after(:each) do
13 $rspec_story_steps = @original_rspec_story_steps
14 end
15
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)
19 end
20 end
21 end
22
23 describe Main, "#run_story" do
24 it_should_behave_like "the main object extended with Main"
25
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))
28 @main.run_story
29 end
30
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
36 end
37 $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
38 end
39
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
45 end
46 $main_spec_runner.should be_an_instance_of(Spec::Story::Runner::PlainTextStoryRunner)
47 end
48
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)
53 @main.run_story
54 end
55 end
56
57 describe Main, "#steps_for" do
58 it_should_behave_like "the main object extended with Main"
59
60 it "should have no steps for a non existent key" do
61 @main.steps_for(:key).find(:given, "foo").should be_nil
62 end
63
64 it "should create steps for a key" do
65 $main_spec_invoked = false
66 @main.steps_for(:key) do
67 Given("foo") {
68 $main_spec_invoked = true
69 }
70 end
71 @main.steps_for(:key).find(:given, "foo").perform(Object.new, "foo")
72 $main_spec_invoked.should be_true
73 end
74
75 it "should append steps to steps_for a given key" do
76 @main.steps_for(:key) do
77 Given("first") {}
78 end
79 @main.steps_for(:key) do
80 Given("second") {}
81 end
82 @main.steps_for(:key).should have_step(:given, "first")
83 @main.steps_for(:key).should have_step(:given, "second")
84 end
85 end
86
87 describe Main, "#with_steps_for adding new steps" do
88 it_should_behave_like "the main object extended with Main"
89
90 it "should result in a group containing pre-existing steps and newly defined steps" do
91 first_group = @main.steps_for(:key) do
92 Given("first") {}
93 end
94 second_group = @main.with_steps_for(:key) do
95 Given("second") {}
96 end
97
98 second_group.should have_step(:given, "first")
99 second_group.should have_step(:given, "second")
100 end
101
102 it "should not add its steps to the existing group" do
103 first_group = @main.steps_for(:key) do
104 Given("first") {}
105 end
106 second_group = @main.with_steps_for(:key) do
107 Given("second") {}
108 end
109
110 first_group.should have_step(:given, "first")
111 first_group.should_not have_step(:given, "second")
112 end
113 end
114
115 describe Main, "#with_steps_for running a story" do
116 it_should_behave_like "the main object extended with Main"
117
118 before(:each) do
119 @runner = mock("runner")
120 @runner_step_group = StepGroup.new
121 @runner.stub!(:steps).and_return(@runner_step_group)
122 @runner.stub!(:run)
123 Spec::Story::Runner::PlainTextStoryRunner.stub!(:new).and_return(@runner)
124 end
125
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
129 run 'path/to/file'
130 end
131 end
132
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
137 end
138 end
139
140 it "should pass the group it creates to the runner's steps" do
141 steps = @main.steps_for(:ice_cream) do
142 Given("vanilla") {}
143 end
144 @main.with_steps_for(:ice_cream) do
145 run 'foo'
146 end
147 @runner_step_group.should have_step(:given, "vanilla")
148 end
149
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
154 run 'path/to/file'
155 end
156 end
157
158 end
159 end
160 end
161end