Module: EvilSystems::Helpers

Includes:
ActionView::RecordIdentifier, CupriteHelpers, SessionHelpers
Defined in:
lib/evil_systems/helpers.rb

Overview

Helpers to make life easier

Instance Method Summary collapse

Methods included from SessionHelpers

#within_session

Methods included from CupriteHelpers

#debug, #pause

Instance Method Details

#absolute_image_pathString

Use our `Capybara.save_path` to store screenshots with other capybara artifacts (Rails screenshots path is not configurable github.com/rails/rails/blob/49baf092439fc74fc3377b12e3334c3dd9d0752f/actionpack/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb#L79)

Returns:

  • (String)

13
14
15
16
17
# File 'lib/evil_systems/helpers.rb', line 13

def absolute_image_path
  return ::Rails.root.join("#{::Capybara.save_path}/screenshots/#{image_name}.png") if defined? ::Rails

  File.join("#{::Capybara.save_path}/screenshots/#{image_name}.png")
end

#dom_id(*args) ⇒ String

Convert dom_id to a selector.

Examples:

dom_id(Facility.first)
# => "#facility-1"

Returns:

  • (String)

40
41
42
# File 'lib/evil_systems/helpers.rb', line 40

def dom_id(*args)
  "##{super}"
end

#image_pathString

Use relative path in screenshot message to make it clickable in VS Code when running in Docker

Returns:

  • (String)

21
22
23
24
25
# File 'lib/evil_systems/helpers.rb', line 21

def image_path
  return absolute_image_path.relative_path_from(::Rails.root).to_s if defined? ::Rails

  absolute_image_path.relative_path_from(Dir.pwd)
end

#take_screenshotObject

Make failure screenshots compatible with multi-session setup

Returns:

  • void


29
30
31
32
33
# File 'lib/evil_systems/helpers.rb', line 29

def take_screenshot
  return super unless ::Capybara.last_used_session

  ::Capybara.using_session(::Capybara.last_used_session) { super }
end