class Kontrast::Configuration

Attributes

_after_run[RW]
_after_screenshot[RW]
_before_run[RW]
_before_screenshot[RW]
aws_bucket[RW]
aws_key[RW]
aws_secret[RW]
browser_driver[RW]
browser_profile[RW]
current_node[RW]
distortion_metric[RW]
fail_build[RW]
highlight_color[RW]
local_path[RW]
lowlight_color[RW]
oauth_token_from_response[RW]
oauth_token_url[RW]
production_domain[RW]
production_oauth_app_secret[RW]
production_oauth_app_uid[RW]
remote_path[RW]
run_parallel[RW]
test_domain[RW]
test_oauth_app_proc[RW]
test_oauth_app_secret[RW]
test_oauth_app_uid[RW]
total_nodes[RW]
workers_pool_size[RW]

Public Class Methods

new() click to toggle source
# File lib/kontrast/configuration.rb, line 40
def initialize
    # Set defaults
    @browser_driver = "firefox"
    @browser_profile = {}

    @run_parallel = false
    @total_nodes = 1
    @current_node = 0

    @distortion_metric = "MeanAbsoluteErrorMetric"
    @highlight_color = "blue"
    @lowlight_color = "rgba(255, 255, 255, 0.3)"

    @fail_build = false
end

Public Instance Methods

after_run(&block) click to toggle source
# File lib/kontrast/configuration.rb, line 100
def after_run(&block)
    if block_given?
        @_after_run = block
    else
        @_after_run.call if @_after_run
    end
end
after_screenshot(test_driver = nil, production_driver = nil, current_test = nil, &block) click to toggle source
# File lib/kontrast/configuration.rb, line 132
def after_screenshot(test_driver = nil, production_driver = nil, current_test = nil, &block)
    if block_given?
        @_after_screenshot = block
    else
        @_after_screenshot.call(test_driver, production_driver, current_test) if @_after_screenshot
    end
end
api_endpoints(group_name) { |api_endpoint_test_builder| ... } click to toggle source
# File lib/kontrast/configuration.rb, line 84
def api_endpoints(group_name)
    if !block_given?
        raise ConfigurationException.new("You must pass a block to the api_endpoints config option.")
    end
    Kontrast.api_endpoint_test_builder.prefix = group_name
    yield(Kontrast.api_endpoint_test_builder)
end
before_run(&block) click to toggle source
# File lib/kontrast/configuration.rb, line 92
def before_run(&block)
    if block_given?
        @_before_run = block
    else
        @_before_run.call if @_before_run
    end
end
before_screenshot(test_driver = nil, production_driver = nil, current_test = nil, &block) click to toggle source
# File lib/kontrast/configuration.rb, line 124
def before_screenshot(test_driver = nil, production_driver = nil, current_test = nil, &block)
    if block_given?
        @_before_screenshot = block
    else
        @_before_screenshot.call(test_driver, production_driver, current_test) if @_before_screenshot
    end
end
pages(width, url_params = {}) { |page_test_builder| ... } click to toggle source
# File lib/kontrast/configuration.rb, line 75
def pages(width, url_params = {})
    if !block_given?
        raise ConfigurationException.new("You must pass a block to the pages config option.")
    end
    Kontrast.page_test_builder.prefix = width
    Kontrast.page_test_builder.url_params = url_params
    yield(Kontrast.page_test_builder)
end
validate() click to toggle source
# File lib/kontrast/configuration.rb, line 56
def validate
    # Check that Kontrast has everything it needs to proceed
    check_nil_vars(["test_domain", "production_domain"])
    if Kontrast.page_test_suite.nil? && Kontrast.api_endpoint_test_suite.nil?
        raise ConfigurationException.new("Kontrast has no tests to run.")
    end

    # If remote, check for more options
    if @run_parallel
        check_nil_vars(["aws_bucket", "aws_key", "aws_secret"])
        check_nil_vars(["local_path", "remote_path"])

        # Make sure total nodes is >= 1 so we don't get divide by 0 errors
        if @total_nodes < 1
            raise ConfigurationException.new("total_nodes cannot be less than 1.")
        end
    end
end

Private Instance Methods

check_nil_vars(vars) click to toggle source
# File lib/kontrast/configuration.rb, line 145
def check_nil_vars(vars)
    vars.each do |var|
        if instance_variable_get("@#{var}").nil?
            raise ConfigurationException.new("Kontrast config is missing the #{var} option.")
        end
    end
end