Sha256: f6c53b2a3e94ee5e9a6ed2e26dda8fe1830bba5b50a2bc40f121f176548b1d76

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module SauceRSpec
  class Config
    attr_reader :caps
    attr_accessor :opts, :user, :key, :host, :port

    public

    def initialize
      clear
    end

    # Sauce URL
    def url
      fail 'Missing user' unless user
      fail 'Missing key' unless key
      fail 'Missing host' unless host
      fail 'Missing port' unless port
      "http://#{user}:#{key}@#{host}:#{port}/wd/hub"
    end

    def caps= value
      fail 'caps must be an array' unless value && value.is_a?(Array)
      @caps = value
    end

    def clear
      @caps = []
      @opts = {}
      @user = sauce_user
      @key  = sauce_key
      @host = 'ondemand.saucelabs.com'
      @port = '80'
    end

    # We're able to run on sauce if we have a user, key, host, and port
    # caps and opts aren't required to run on sauce because the user may
    # provide the caps outside of the SauceRSpec config.
    def sauce?
      @user && @key && @host && @port
    end

    def to_h
      {
        caps: @caps.dup,
        opts: @opts.dup,
        user: @user.dup,
        key:  @key.dup,
        host: @host.dup,
        port: @port.dup
      }
    end
  end # class Config

  @config = SauceRSpec::Config.new

  class << self
    def config &block
      return @config unless block_given?
      block.call @config
      @config
    end
  end # class << self
end # module SauceRSpec

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sauce_rspec-0.0.1 lib/sauce_rspec/config.rb