Sha256: fb8bb457a43c13b55349aa17ce7c178f647623ac64a20a5317c7ba86fdd9e3dc

Contents?: true

Size: 1.53 KB

Versions: 47

Compression:

Stored size: 1.53 KB

Contents

module Spec
  module Story
    module Runner
      class ScenarioRunner
        def initialize
          @listeners = []
        end
        
        def run(scenario, world)
          @listeners.each { |l| l.scenario_started(scenario.story.title, scenario.name) }
          run_story_ignoring_scenarios(scenario.story, world)
          
          world.start_collecting_errors

          unless scenario.body
            @listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, '') }
            return true
          end
          
          world.instance_eval(&scenario.body)
          if world.errors.empty?
            @listeners.each { |l| l.scenario_succeeded(scenario.story.title, scenario.name) }
          else
            if Spec::Example::ExamplePendingError === (e = world.errors.first)
              @listeners.each { |l| l.scenario_pending(scenario.story.title, scenario.name, e.message) }
            else
              @listeners.each { |l| l.scenario_failed(scenario.story.title, scenario.name, e) }
              return false
            end
          end
          true
        end
        
        def add_listener(listener)
          @listeners << listener
        end
        
        private
        
        def run_story_ignoring_scenarios(story, world)
          class << world
            def Scenario(name, &block)
              # do nothing
            end
          end
          story.run_in(world)
          class << world
            remove_method(:Scenario)
          end
        end
      end
    end
  end
end

Version data entries

47 entries across 47 versions & 10 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.1 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.2 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.3 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.4 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.5 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.6 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11.7 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-1.1.11 lib/spec/story/runner/scenario_runner.rb
dchelimsky-rspec-stories-1.0.0 lib/spec/story/runner/scenario_runner.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
samstokes-rspec-stories-1.0.1 lib/spec/story/runner/scenario_runner.rb
samstokes-rspec-stories-1.0.2 lib/spec/story/runner/scenario_runner.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/story/runner/scenario_runner.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/story/runner/scenario_runner.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/story/runner/scenario_runner.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/story/runner/scenario_runner.rb