Module: Checker

Defined in:
lib/generic_test/checker.rb

Overview

Module for checking parts on a site

Class Method Summary collapse

Class Method Details

.call_via_rest_client(href) ⇒ Object

Use rest-client to try and get status of URL



35
36
37
38
39
40
41
# File 'lib/generic_test/checker.rb', line 35

def call_via_rest_client(href)
  RestClient.get(href).code
rescue RestClient::Exception => e
  return e.response&.code if e.respond_to? :response

  raise e
end

Returns:

  • (Integer)

    Status code



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/generic_test/checker.rb', line 12

def link_status(href)
  return unless href

  init_options = "const myInit = {
    method: 'GET',
    credentials: 'same-origin',
    cache: 'default',
    mode: 'cors'
  };"
  get_js_code = "var url='#{href}'; #{init_options} return fetch(url, myInit).then(res=>{return res.status});"
  GenericTest.browser.execute_script get_js_code
rescue Selenium::WebDriver::Error::JavascriptError
  return call_via_rest_client(href) unless GenericTest.only_javascript

  raise GenericTest::Error, "Failed to fetch url '#{href}'"
end

.valid_email?(email_address) ⇒ Nil, String

Returns Nil if valid, string if error.

Returns:

  • (Nil, String)

    Nil if valid, string if error



30
31
32
# File 'lib/generic_test/checker.rb', line 30

def valid_email?(email_address)
  EmailAddress.error email_address
end