Sha256: efb055e380c0f13d14399b442da7efac6c3d0be6c5e162b73928fae7cfee93ee

Contents?: true

Size: 1.89 KB

Versions: 11

Compression:

Stored size: 1.89 KB

Contents

require "tmpdir"
require 'watirspec/guards'
require 'watirspec/implementation'
require 'watirspec/runner'
require 'watirspec/server'

module WatirSpec
  class << self
    attr_accessor :browser_args, :unguarded, :implementation

    def html
      @html ||= File.expand_path("../../spec/watirspec/html", __FILE__)
    end

    def run!
      load_support
      WatirSpec::Runner.execute_if_necessary
    end

    def url_for(str)
      File.join(host, str)
    end

    def host
      @host ||= "http://#{Server.bind}:#{Server.port}"
    end

    def unguarded?
      @unguarded ||= false
    end

    def load_support
      root = File.expand_path("../../spec/watirspec", __FILE__)
      Dir.glob("#{root}/support/**/*.rb").each do |file|
        require file
      end
    end

    def implementation
      @implementation ||= (
        imp = WatirSpec::Implementation.new
        yield imp if block_given?

        imp
      )
    end

    def implementation=(imp)
      unless imp.is_a?(WatirSpec::Implementation)
        raise TypeError, "expected WatirSpec::Implementation, got #{imp.class}"
      end

      @implementation = imp
    end

    def new_browser
      klass = WatirSpec.implementation.browser_class
      args = Array(WatirSpec.implementation.browser_args).map { |e| Hash === e ? e.dup : e }

      instance = klass.new(*args)
      print_browser_info_once(instance)

      instance
    end

    private

    def print_browser_info_once(instance)
      return if defined?(@did_print_browser_info) && @did_print_browser_info
      @did_print_browser_info = true

      info = []
      info << instance.class.name

      caps = instance.driver.capabilities

      info << "#{caps.browser_name}"
      info << "#{caps.version}"

      $stderr.puts "running watirspec against #{info.join ' '} using:\n#{WatirSpec.implementation.inspect_args}"
    rescue
      # ignored
    end

  end # class << WatirSpec
end # WatirSpec

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
watir-6.5.0 lib/watirspec.rb
watir-6.4.3 lib/watirspec.rb
watir-6.4.2 lib/watirspec.rb
watir-6.4.1 lib/watirspec.rb
watir-6.4.0 lib/watirspec.rb
watir-6.4.0.rc2 lib/watirspec.rb
watir-6.4.0.rc1 lib/watirspec.rb
watir-6.3.0 lib/watirspec.rb
watir-6.2.1 lib/watirspec.rb
watir-6.2.0 lib/watirspec.rb
watir-6.1.0 lib/watirspec.rb