Class: Kontrast::PageTest

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

Instance Attribute Summary collapse

Attributes inherited from Test

#headers, #name, #path, #prefix, #spec

Instance Method Summary collapse

Methods inherited from Test

#bind_spec, #run_callback, #to_s, #to_str

Constructor Details

#initialize(prefix, name, path, headers: {}, url_params: {}) ⇒ PageTest

Returns a new instance of PageTest.



9
10
11
12
13
14
15
16
# File 'lib/kontrast/page_test.rb', line 9

def initialize(prefix, name, path, headers: {}, url_params: {})
    super(prefix, name, path, headers)
    @width = prefix
    @url_params = url_params

    # Re-define path so it includes all URL params
    @path = get_path_with_params(url_params)
end

Instance Attribute Details

#url_paramsObject (readonly)

Returns the value of attribute url_params.



7
8
9
# File 'lib/kontrast/page_test.rb', line 7

def url_params
  @url_params
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/kontrast/page_test.rb', line 7

def width
  @width
end

Instance Method Details

#get_path_with_params(url_params) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kontrast/page_test.rb', line 18

def get_path_with_params(url_params)
    uri = URI(@path)
    original_query = Rack::Utils.parse_query(uri.query)
    new_query = url_params.merge(original_query)
    uri.query = Rack::Utils.build_query(new_query)

    # Ensure there's no trailing "?"
    if uri.query == ""
        uri.query = nil
    end

    return uri.to_s
end