Sha256: e8a9d4ff024fe5dd7ca631d92a3759ddbcae44a942afbec9e5057c2840ff6a91

Contents?: true

Size: 1.31 KB

Versions: 1

Compression:

Stored size: 1.31 KB

Contents

require 'logger'
require 'cucumber/pro/formatter'
require 'cucumber/pro/web_socket/session'
require 'cucumber/pro/errors'

module Cucumber
  module Pro
    class << self
      def new(runtime, output, options)
        create_logger(output)

        working_copy = Scm::WorkingCopy.detect

        if token
          working_copy.check_clean
          session = WebSocket::Session.new(url, logger, timeout: config.timeout)
        else
          session = WebSocket::NullSession.new
        end

        Formatter.new(session, working_copy)
      end

      def configure
        yield config
      end

      private

      attr_reader :logger
      private :logger

      def config
        @config ||= Config.new
      end

      def url
        config.url + "?token=#{token}"
      end

      def create_logger(output)
        @logger = config.logger || Logger.new(output)
      end

      def token
        config.token
      end
    end

    class Config
      attr_accessor :url, :logger, :token, :timeout
    end

    # Default config
    configure do |config|
      config.url     = ENV['CUCUMBER_PRO_URL'] || 'wss://results.cucumber.pro/ws'
      config.token   = ENV['CUCUMBER_PRO_TOKEN']
      config.timeout = 5
      if file = ENV['CUCUMBER_PRO_LOG_FILE']
        config.logger = Logger.new(file)
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cucumber-pro-0.0.13 lib/cucumber/pro.rb