Sha256: 411c4931b75ae78aab5c8a2cc4f62d3c5db4e981759719a3b73fbafe2a84a0df

Contents?: true

Size: 1.57 KB

Versions: 26

Compression:

Stored size: 1.57 KB

Contents

module DeepTest
  module Spec
    class WorkUnit
      def initialize(identifier)
        @identifier = identifier
      end

      def run
        # Dup options here to avoid clobbering the reporter on someone
        # elses options reference (Such as ExampleGroupRunner)
        original_options = ::Spec::Runner.options
        ::Spec::Runner.use ::Spec::Runner.options.dup
        ::Spec::Runner.options.reporter = ResultReporter.new(@identifier)
        result = run_without_deadlock_protection
        result = run_without_deadlock_protection if result.failed_due_to_deadlock?
        result = result.deadlock_result if result.failed_due_to_deadlock?
        result
      ensure
        ::Spec::Runner.use original_options
      end

      def to_s
        "#{@identifier.group_description}: #{@identifier.description}"
      end

      protected

      def run_without_deadlock_protection
        output = capture_stdout do
          ::Spec::Runner.options.run_one_example(@identifier)
        end
        ::Spec::Runner.options.reporter.result(output)
      end

      class ResultReporter
        attr_reader :result

        def initialize(identifier)
          @identifier = identifier 
        end

        def add_example_group(example_group); end
        def dump; end
        def end; end
        def example_started(name); end

        def example_finished(example, error)
          @example, @error = example, error
        end

        def result(output)
          Spec::WorkResult.new(@identifier, @error, output)
        end

        def start(example); end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 5 rubygems

Version Path
jason-o-matic-deep_test-1.2.2.1 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.10 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.11 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.12 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.13 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.14 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.2 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.3 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.4 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.5 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.6 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.7 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.8 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.9 lib/deep_test/spec/work_unit.rb
jperkins-deep_test-1.2.2 lib/deep_test/spec/work_unit.rb
deep_test_pre-2.0 lib/deep_test/spec/work_unit.rb
jason-o-matic-deep_test-1.2.2.15 lib/deep_test/spec/work_unit.rb
jstorimer-deep-test-2.0.0 lib/deep_test/spec/work_unit.rb
jstorimer-deep-test-1.4.0 lib/deep_test/spec/work_unit.rb
jstorimer-deep-test-1.3.0 lib/deep_test/spec/work_unit.rb