Class: Kontrast::TestBuilder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTestBuilder

Returns a new instance of TestBuilder.



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

def initialize
    @suite = TestSuite.new
    @prefix = nil
    @headers = {}
    @url_params = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

Adds a given test from config to the suite



37
38
39
# File 'lib/kontrast/test_builder.rb', line 37

def method_missing(name, *args)
    @suite << PageTest.new(@prefix, name.to_s, args.first, url_params: @url_params)
end

Instance Attribute Details

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#prefixObject

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#suiteObject (readonly)

Returns the value of attribute suite.



6
7
8
# File 'lib/kontrast/test_builder.rb', line 6

def suite
  @suite
end

#url_paramsObject

Returns the value of attribute url_params.



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

def url_params
  @url_params
end

Instance Method Details

#lazy_api_endpoints(&block) ⇒ Object



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

def lazy_api_endpoints(&block)
    @suite.lazy_tests << LazyTest.new(@prefix, @headers.dup, block)
end

#tests(param = nil) ⇒ Object

Needed in case someone tries to name a test “tests”



17
18
19
20
21
22
# File 'lib/kontrast/test_builder.rb', line 17

def tests(param = nil)
    if param
        raise ConfigurationException.new("'tests' is not a valid name for a test.")
    end
    return @suite.tests
end