]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/story/runner/scenario_runner.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / story / runner / scenario_runner.rb
1 module Spec
2   module Story
3     module Runner
4       class ScenarioRunner
5         def initialize
6           @listeners = []
7         end
8         
9         def run(scenario, world)
10           @listeners.each { |l| l.scenario_started(scenario.story.title, scenario.name) }
11           run_story_ignoring_scenarios(scenario.story, world)
12           
13           world.start_collecting_errors
14           world.instance_eval(&scenario.body)
15           if world.errors.empty?
16             @listeners.each { |l| l.scenario_succeeded(scenario.story.title, scenario.name) }
17           else
18             if Spec::Example::ExamplePendingError === (e = world.errors.first)
19               @listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, e.message) }
20             else
21               @listeners.each { |l| l.scenario_failed(scenario.story.title, scenario.name, e) }
22             end
23           end
24         end
25         
26         def add_listener(listener)
27           @listeners << listener
28         end
29         
30         private
31         
32         def run_story_ignoring_scenarios(story, world)
33           class << world
34             def Scenario(name, &block)
35               # do nothing
36             end
37           end
38           story.run_in(world)
39           class << world
40             remove_method(:Scenario)
41           end
42         end
43       end
44     end
45   end
46 end