Sha256: 7a74e54e18375d847c088446a46db3616894a525a32d9c5888d67db21f99af8c

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

module OpalSpec
  class Runner
    def self.in_browser?
      $global[:document]
    end

    def self.in_phantom?
      $global[:phantom] or $global[:OPAL_SPEC_PHANTOM]
    end

    def self.autorun
      if in_browser?
        $global.setTimeout -> { Runner.new.run }, 0
      else
        Runner.new.run
      end
    end

    def initialize
      if Runner.in_phantom?
        @formatter = PhantomFormatter.new
      elsif Runner.in_browser?
        @formatter = BrowserFormatter.new
      end
    end

    def run
      @groups = Example.groups.dup
      @formatter.start
      run_next_group
    end

    def run_next_group
      if @groups.empty?
        @formatter.finish
      else
        @groups.shift.run self
      end
    end

    def example_group_started group
      @formatter.example_group_started group
    end

    def example_group_finished group
      @formatter.example_group_finished group
      run_next_group
    end

    def example_started example
      @formatter.example_started example
    end

    def example_passed example
      @formatter.example_passed example
    end

    def example_failed example
      @formatter.example_failed example
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-spec-0.2.17 opal/opal/spec/runner.rb
opal-spec-0.2.16 opal/opal/spec/runner.rb