Sha256: bc097cc2223b08946cde30529610714ea193d0dd3b8f724e002bb1f29fbb18fe

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require "capybara"

module Konacha
  class Runner
    def self.start
      new.run
    end

    attr_reader :reporter

    def initialize
      @reporter = Konacha::Reporter.new(*formatters)
    end

    def run
      session.visit('/')

      events_consumed = 0
      done = false
      begin
        sleep 0.1
        events = JSON.parse(session.evaluate_script('Konacha.getEvents()'))
        if events
          events[events_consumed..-1].each do |event|
            done = true if event['event'] == 'end'
            reporter.process_mocha_event(event)
          end

          events_consumed = events.length
        end
      end until done

      reporter.passed?
    rescue => e
      raise e, "Error communicating with browser process: #{e}", e.backtrace
    end

    def session
      @session ||= Capybara::Session.new(Konacha.driver, Konacha.application)
    end

    private
    def formatters
      if ENV['FORMAT']
        ENV['FORMAT'].split(',').map do |string|
          eval(string).new(STDOUT)
        end
      else
        [Konacha::Formatter.new(STDOUT)]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
konacha-2.0.0 lib/konacha/runner.rb