Sha256: da8796afcab292a7b6d2b5f776295c222e825565e83c62484a0fa29e2520c6e9

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Opal
  module Spec
    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' || typeof(OPAL_SPEC_PHANTOM) !== 'undefined') {
            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.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
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opal-spec-0.2.8 lib/assets/javascripts/opal/spec/runner.rb
opal-spec-0.2.7 lib/assets/javascripts/opal/spec/runner.rb