Sha256: cb4a9b9093bebdb700ceb62d3422b61814a19c363e27767471a4b8e5a2eecdcc

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

module Opal
  module RSpec
    class Runner

      class << self
        def browser?
          `typeof(document) !== "undefined"`
        end

        def phantom?
          `typeof(phantom) !== 'undefined' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined'`
        end

        def default_formatter
          if phantom?
            TextFormatter
          else # browser
            BrowserFormatter
          end
        end

        def autorun
          if browser?
            `setTimeout(function() { #{Runner.new.run} }, 0)`
          else # phantom
            Runner.new.run
          end
        end
      end

      def initialize(options = {})
        @options = options
        @world = ::RSpec.world
        @configuration = ::RSpec.configuration
      end

      def run(err=$stdout, out=$stdout)
        @configuration.error_stream = err
        @configuration.output_stream ||= out

        self.start
        run_examples

        run_async_examples do
          self.finish
        end
      end

      def run_examples
        @world.example_groups.map { |g| g.run(@reporter) }.all?
      end

      def run_async_examples(&block)
        AsyncRunner.new(self, @reporter, block).run
      end

      def start
        @reporter = @configuration.reporter
        @reporter.start(@world.example_count)
        @configuration.run_hook(:before, :suite)
      end

      def finish
        @configuration.run_hook(:after, :suite)
        @reporter.finish
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
opal-rspec-cj-0.4.4 opal/opal/rspec/runner.rb
opal-rspec-0.4.3 opal/opal/rspec/runner.rb
opal-rspec-0.4.2 opal/opal/rspec/runner.rb
opal-rspec-0.4.1 opal/opal/rspec/runner.rb
opal-rspec-0.4.0 opal/opal/rspec/runner.rb
opal-rspec-0.4.0.beta4 opal/opal/rspec/runner.rb
opal-rspec-0.4.0.beta3 opal/opal/rspec/runner.rb
opal-rspec-0.4.0.beta2 opal/opal/rspec/runner.rb
opal-rspec-0.4.0.beta1 opal/opal/rspec/runner.rb
opal-rspec-0.3.0.beta3 opal/opal/rspec/runner.rb
opal-rspec-0.3.0.beta2 opal/opal/rspec/runner.rb
opal-rspec-0.3.0.beta1 opal/opal/rspec/runner.rb
opal-rspec-0.2.1 opal/opal/rspec/runner.rb
opal-rspec-0.2.0 opal/opal/rspec/runner.rb
opal-rspec-0.1.0 opal/opal/rspec/runner.rb
opal-rspec-0.0.1.beta2 opal/opal/rspec/runner.rb