Class: Kontrast::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/kontrast/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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

Instance Attribute Details

Returns the value of attribute _after_gallery.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _after_gallery
  @_after_gallery
end

#_after_runObject

Returns the value of attribute _after_run.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _after_run
  @_after_run
end

#_after_screenshotObject

Returns the value of attribute _after_screenshot.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _after_screenshot
  @_after_screenshot
end

Returns the value of attribute _before_gallery.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _before_gallery
  @_before_gallery
end

#_before_runObject

Returns the value of attribute _before_run.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _before_run
  @_before_run
end

#_before_screenshotObject

Returns the value of attribute _before_screenshot.



29
30
31
# File 'lib/kontrast/configuration.rb', line 29

def _before_screenshot
  @_before_screenshot
end

#aws_bucketObject

Returns the value of attribute aws_bucket.



31
32
33
# File 'lib/kontrast/configuration.rb', line 31

def aws_bucket
  @aws_bucket
end

#aws_keyObject

Returns the value of attribute aws_key.



31
32
33
# File 'lib/kontrast/configuration.rb', line 31

def aws_key
  @aws_key
end

#aws_secretObject

Returns the value of attribute aws_secret.



31
32
33
# File 'lib/kontrast/configuration.rb', line 31

def aws_secret
  @aws_secret
end

#browser_driverObject

Returns the value of attribute browser_driver.



33
34
35
# File 'lib/kontrast/configuration.rb', line 33

def browser_driver
  @browser_driver
end

#browser_profileObject

Returns the value of attribute browser_profile.



33
34
35
# File 'lib/kontrast/configuration.rb', line 33

def browser_profile
  @browser_profile
end

#current_nodeObject

Returns the value of attribute current_node.



28
29
30
# File 'lib/kontrast/configuration.rb', line 28

def current_node
  @current_node
end

#distortion_metricObject

Returns the value of attribute distortion_metric.



30
31
32
# File 'lib/kontrast/configuration.rb', line 30

def distortion_metric
  @distortion_metric
end

#fail_buildObject

Returns the value of attribute fail_build.



34
35
36
# File 'lib/kontrast/configuration.rb', line 34

def fail_build
  @fail_build
end

#highlight_colorObject

Returns the value of attribute highlight_color.



30
31
32
# File 'lib/kontrast/configuration.rb', line 30

def highlight_color
  @highlight_color
end

#local_pathObject

Returns the value of attribute local_path.



31
32
33
# File 'lib/kontrast/configuration.rb', line 31

def local_path
  @local_path
end

#lowlight_colorObject

Returns the value of attribute lowlight_color.



30
31
32
# File 'lib/kontrast/configuration.rb', line 30

def lowlight_color
  @lowlight_color
end

#oauth_token_from_responseObject

Returns the value of attribute oauth_token_from_response.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def oauth_token_from_response
  @oauth_token_from_response
end

#oauth_token_urlObject

Returns the value of attribute oauth_token_url.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def oauth_token_url
  @oauth_token_url
end

#production_domainObject

Returns the value of attribute production_domain.



32
33
34
# File 'lib/kontrast/configuration.rb', line 32

def production_domain
  @production_domain
end

#production_oauth_app_secretObject

Returns the value of attribute production_oauth_app_secret.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def production_oauth_app_secret
  @production_oauth_app_secret
end

#production_oauth_app_uidObject

Returns the value of attribute production_oauth_app_uid.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def production_oauth_app_uid
  @production_oauth_app_uid
end

#remote_pathObject

Returns the value of attribute remote_path.



31
32
33
# File 'lib/kontrast/configuration.rb', line 31

def remote_path
  @remote_path
end

#run_parallelObject

Returns the value of attribute run_parallel.



28
29
30
# File 'lib/kontrast/configuration.rb', line 28

def run_parallel
  @run_parallel
end

#test_domainObject

Returns the value of attribute test_domain.



32
33
34
# File 'lib/kontrast/configuration.rb', line 32

def test_domain
  @test_domain
end

#test_oauth_app_procObject

Returns the value of attribute test_oauth_app_proc.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def test_oauth_app_proc
  @test_oauth_app_proc
end

#test_oauth_app_secretObject

Returns the value of attribute test_oauth_app_secret.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def test_oauth_app_secret
  @test_oauth_app_secret
end

#test_oauth_app_uidObject

Returns the value of attribute test_oauth_app_uid.



36
37
38
# File 'lib/kontrast/configuration.rb', line 36

def test_oauth_app_uid
  @test_oauth_app_uid
end

#total_nodesObject

Returns the value of attribute total_nodes.



28
29
30
# File 'lib/kontrast/configuration.rb', line 28

def total_nodes
  @total_nodes
end

#workers_pool_sizeObject

Returns the value of attribute workers_pool_size.



35
36
37
# File 'lib/kontrast/configuration.rb', line 35

def workers_pool_size
  @workers_pool_size
end

Instance Method Details



116
117
118
119
120
121
122
# File 'lib/kontrast/configuration.rb', line 116

def after_gallery(diffs = nil, gallery = nil, &block)
    if block_given?
        @_after_gallery = block
    else
        @_after_gallery.call(diffs, gallery) if @_after_gallery
    end
end

#after_run(&block) ⇒ Object



100
101
102
103
104
105
106
# 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) ⇒ Object



132
133
134
135
136
137
138
# 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) {|Kontrast.api_endpoint_test_builder| ... } ⇒ Object



84
85
86
87
88
89
90
# 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


108
109
110
111
112
113
114
# File 'lib/kontrast/configuration.rb', line 108

def before_gallery(&block)
    if block_given?
        @_before_gallery = block
    else
        @_before_gallery.call if @_before_gallery
    end
end

#before_run(&block) ⇒ Object



92
93
94
95
96
97
98
# 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) ⇒ Object



124
125
126
127
128
129
130
# 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 = {}) {|Kontrast.page_test_builder| ... } ⇒ Object



75
76
77
78
79
80
81
82
# 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

#validateObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# 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