Class: IntegrationDiff::Runner

Inherits:
Object
  • Object
show all
Includes:
Capybara::DSL
Defined in:
lib/integration_diff/runner.rb

Constant Summary collapse

DIR =
'tmp/idiff_images'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_uri, project_name, javascript_driver) ⇒ Runner

Returns a new instance of Runner.



17
18
19
20
21
22
23
24
# File 'lib/integration_diff/runner.rb', line 17

def initialize(base_uri, project_name, javascript_driver)
  @base_uri = base_uri
  @project_name = project_name
  @javascript_driver = javascript_driver

  Dir.mkdir('tmp') unless Dir.exist?('tmp')
  Dir.mkdir(DIR) unless Dir.exist?(DIR)
end

Class Method Details

.instanceObject



11
12
13
14
15
# File 'lib/integration_diff/runner.rb', line 11

def self.instance
  @runner ||= Runner.new(IntegrationDiff.base_uri,
                         IntegrationDiff.project_name,
                         IntegrationDiff.javascript_driver)
end

Instance Method Details

#screenshot(identifier) ⇒ Object



47
48
49
50
51
# File 'lib/integration_diff/runner.rb', line 47

def screenshot(identifier)
  screenshot_name = image_file(identifier)
  page.save_screenshot(screenshot_name, full: true)
  @identifiers << identifier
end

#start_runObject

TODO: Improve error handling here for network timeouts



27
28
29
30
31
32
33
# File 'lib/integration_diff/runner.rb', line 27

def start_run
  @identifiers = []
  draft_run
rescue StandardError => e
  IntegrationDiff.logger.fatal e.message
  raise e
end

#wrap_runObject

TODO: Improve error handling here for network timeouts



36
37
38
39
40
41
42
43
44
45
# File 'lib/integration_diff/runner.rb', line 36

def wrap_run
  @identifiers.each do |identifier|
    upload_image(identifier)
  end

  complete_run if @run_id
rescue StandardError => e
  IntegrationDiff.logger.fatal e.message
  raise e
end