changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/story/story_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__) + '/story_helper'
2
3module Spec
4 module Story
5 describe Story do
6 it 'should run itself in a given object' do
7 # given
8 $instance = nil
9 story = Story.new 'title', 'narrative' do
10 $instance = self
11 end
12 object = Object.new
13
14 # when
15 story.run_in(object)
16
17 # then
18 $instance.should be(object)
19 end
20
21 it 'should not raise an error if no block is supplied' do
22 # when
23 error = exception_from do
24 Story.new 'title', 'narrative'
25 end
26
27 # then
28 error.should be_nil
29 end
30
31 it "should raise when error raised running in another object" do
32 #given
33 story = Story.new 'title', 'narrative' do
34 raise "this is raised in the story"
35 end
36 object = Object.new
37
38 # when/then
39 lambda do
40 story.run_in(object)
41 end.should raise_error
42 end
43
44 it "should use the steps it is told to using a StepGroup" do
45 story = Story.new("title", "narrative", :steps => steps = StepGroup.new) do end
46 assignee = mock("assignee")
47 assignee.should_receive(:use).with(steps)
48 story.assign_steps_to(assignee)
49 end
50
51 it "should use the steps it is told to using a key" do
52 begin
53 orig_rspec_story_steps = $rspec_story_steps
54 $rspec_story_steps = StepGroupHash.new
55 $rspec_story_steps[:foo] = steps = Object.new
56
57 story = Story.new("title", "narrative", :steps_for => :foo) do end
58 assignee = mock("assignee")
59
60 assignee.should_receive(:use).with(steps)
61 story.assign_steps_to(assignee)
62 ensure
63 $rspec_story_steps = orig_rspec_story_steps
64 end
65 end
66
67 it "should use the steps it is told to using multiple keys" do
68 begin
69 orig_rspec_story_steps = $rspec_story_steps
70 $rspec_story_steps = StepGroupHash.new
71 $rspec_story_steps[:foo] = foo_steps = Object.new
72 $rspec_story_steps[:bar] = bar_steps = Object.new
73
74 story = Story.new("title", "narrative", :steps_for => [:foo, :bar]) do end
75 assignee = mock("assignee")
76
77 assignee.should_receive(:use).with(foo_steps)
78 assignee.should_receive(:use).with(bar_steps)
79 story.assign_steps_to(assignee)
80 ensure
81 $rspec_story_steps = orig_rspec_story_steps
82 end
83 end
84 end
85 end
86end