Module: EvilSystems::Settings

Defined in:
lib/evil_systems/settings.rb

Overview

Capybara settings (not covered by Rails system tests)

Class Method Summary collapse

Class Method Details

.app_hostString

Finds the current app host via ENV, ‘hostname`, or defaults to “0.0.0.0”

Returns:

  • (String)


8
9
10
# File 'lib/evil_systems/settings.rb', line 8

def self.app_host
  "http://#{ENV.fetch("APP_HOST", `hostname`&.strip&.downcase || "0.0.0.0")}"
end

Finds the current cookie domain

Returns:

  • (String)


14
15
16
17
18
19
20
21
# File 'lib/evil_systems/settings.rb', line 14

def self.cookie_domain
  URI.parse(app_host).host.then do |host|
    # If host is a top-level domain
    next host unless host.include?(".")

    ".#{host}"
  end
end

.initial_setupObject

The setup to be run prior to the test suite



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/evil_systems/settings.rb', line 24

def self.initial_setup
  prepend_session_to_capybara

  ::Capybara.app_host = app_host

  # Make server listening on all hosts
  ::Capybara.server_host = "0.0.0.0"

  # Silence puma
  ::Capybara.server = :puma, {Silent: true}

  # Don't wait too long in `have_xyz` matchers
  ::Capybara.default_max_wait_time = 2

  # Normalizes whitespaces when using `has_text?` and similar matchers
  ::Capybara.default_normalize_ws = true

  # Where to store artifacts (e.g. screenshots, downloaded files, etc.)
  ::Capybara.save_path = ENV.fetch("CAPYBARA_ARTIFACTS", "./tmp/capybara")

  # Disable animations in Capybara by default
  ::Capybara.disable_animation = ENV.fetch("DISABLE_ANIMATION", "true") == "true"
end

.prepend_session_to_capybaraObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/evil_systems/settings.rb', line 48

def self.prepend_session_to_capybara
  ::Capybara.singleton_class.prepend(Module.new do
    attr_accessor :last_used_session

    def using_session(name, &block)
      self.last_used_session = name
      super
    ensure
      self.last_used_session = nil
    end
  end)
end