Sha256: ff16891e12317a3bd289bd1ef1610c090d01a713495da4a14e84665901356834

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module OpalSpec
  class Runner
    def self.in_browser?
      %x{
        if (typeof(window) !== 'undefined' && typeof(document) !== 'undefined') {
          return true;
        }

        return false;
      }
    end

    def self.in_phantom?
      %x{
        if (typeof(phantom) !== 'undefined' && phantom.exit) {
          return true;
        }

        return false;
      }
    end

    def self.autorun
      if in_browser?
        %x{
          setTimeout(function() {
            #{ 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 = ExampleGroup.example_groups
      @formatter.start
      groups.each { |group| group.run self }
      @formatter.finish
    end

    def example_group_started group
      @formatter.example_group_started group
    end

    def example_group_finished group
      @formatter.example_group_finished 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

1 entries across 1 versions & 1 rubygems

Version Path
opal-spec-0.2.0 lib/opal-spec/runner.rb