~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/spec/spec/story/story_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require File.dirname(__FILE__) + '/story_helper'
 
2
 
 
3
module 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
 
86
end