aboutsummaryrefslogtreecommitdiffstats
path: root/unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'unix.c')
0 files changed, 0 insertions, 0 deletions
ix/0.17.0.5'>hotfix/0.17.0.5 Unnamed repository; edit this file 'description' to name the repository.MimesBrønn
aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/plugins/rspec/lib/spec/story/runner/story_mediator.rb
blob: 1f4744b9f87492dcc4c98bd660b2ee2324635dc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 module Spec
  module Story
    module Runner

      class StoryMediator
        def initialize(step_group, runner, options={})
          @step_group = step_group
          @stories = []
          @runner = runner
          @options = options
        end
        
        def stories
          @stories.collect { |p| p.to_proc }
        end
        
        def create_story(title, narrative)
          @stories << Story.new(title, narrative, @step_group, @options)
        end
        
        def create_scenario(title)
          current_story.add_scenario Scenario.new(title)
        end
        
        def create_given(name)
          current_scenario.add_step Step.new('Given', name)
        end
        
        def create_given_scenario(name)
          current_scenario.add_step Step.new('GivenScenario', name)
        end
        
        def create_when(name)
          current_scenario.add_step Step.new('When', name)
        end
        
        def create_then(name)
          current_scenario.add_step Step.new('Then', name)
        end
        
        def run_stories
          stories.each { |story| @runner.instance_eval(&story) }
        end
        
        private
        def current_story
          @stories.last
        end
        
        def current_scenario
          current_story.current_scenario
        end
        
        class Story
          def initialize(title, narrative, step_group, options)
            @title = title
            @narrative = narrative
            @scenarios = []
            @step_group = step_group
            @options = options
          end
          
          def to_proc
            title = @title
            narrative = @narrative
            scenarios = @scenarios.collect { |scenario| scenario.to_proc }
            options = @options.merge(:steps => @step_group)
            lambda do
              Story title, narrative, options do
                scenarios.each { |scenario| instance_eval(&scenario) }
              end
            end
          end
          
          def add_scenario(scenario)
            @scenarios << scenario
          end
          
          def current_scenario
            @scenarios.last
          end
        end
        
        class Scenario
          def initialize(name)
            @name = name
            @steps = []
          end
          
          def to_proc
            name = @name
            steps = @steps.collect { |step| step.to_proc }
            lambda do
              Scenario name do
                steps.each { |step| instance_eval(&step) }
              end
            end
          end
          
          def add_step(step)
            @steps << step
          end
        end
        
        class Step
          def initialize(type, name)
            @type = type
            @name = name
          end
          
          def to_proc
            type = @type
            name = @name
            lambda do
              send(type, name)
            end
          end
        end
      end
      
    end
  end
end