Module: Compatriot

Defined in:
lib/compatriot.rb,
lib/compatriot/runner.rb,
lib/compatriot/browser.rb,
lib/compatriot/version.rb,
lib/compatriot/reporter.rb,
lib/compatriot/assertions.rb,
lib/compatriot/results_presenter.rb,
lib/compatriot/minitest_report_driver.rb,
lib/compatriot/image_differ/color_differ.rb,
lib/compatriot/image_differ/image_differ.rb

Defined Under Namespace

Modules: Assertions Classes: Browser, ColorDiffer, ImageDiffer, MinitestReportDriver, Reporter, ResultsPresenter, Runner

Constant Summary collapse

VERSION =
"0.1.3"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.appObject

Returns the value of attribute app.



11
12
13
# File 'lib/compatriot.rb', line 11

def app
  @app
end

.frameworkObject

Returns the value of attribute framework.



11
12
13
# File 'lib/compatriot.rb', line 11

def framework
  @framework
end

.screenshot_directoryObject

Returns the value of attribute screenshot_directory.



11
12
13
# File 'lib/compatriot.rb', line 11

def screenshot_directory
  @screenshot_directory
end

.show_diffsObject

Returns the value of attribute show_diffs.



11
12
13
# File 'lib/compatriot.rb', line 11

def show_diffs
  @show_diffs
end

.ui_difference_thresholdObject

Returns the value of attribute ui_difference_threshold.



11
12
13
# File 'lib/compatriot.rb', line 11

def ui_difference_threshold
  @ui_difference_threshold
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Compatriot)

    the object that the method was called on



15
16
17
# File 'lib/compatriot.rb', line 15

def configure
  yield self
end

.filename_for_test(test, description) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/compatriot.rb', line 43

def filename_for_test(test, description)
  test_name = test.name.match(/test_[0-9]+_(.*)/)[1]
  class_name = test.class.name
  filename = class_name + '_' + test_name
  filename += '_' + description unless description.empty?
  filename.tr(' ', '_').downcase + '.png'
end

.filepath_for_screenshot(type, filename) ⇒ Object



51
52
53
# File 'lib/compatriot.rb', line 51

def filepath_for_screenshot(type, filename)
  File.expand_path(self.screenshot_directory + '/' + type + '/' + filename)
end

.percentage_changed(test, description = '') ⇒ Object



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

def percentage_changed(test, description = '')
  variable_img_path = take_screenshot(test, description)
  control_img_path = filepath_for_screenshot('control', filename_for_test(test, description))
  diff = Compatriot::ColorDiffer.diff(variable_img_path, control_img_path)
  variable_image = ChunkyPNG::Image.from_file(variable_img_path)
  Compatriot::ColorDiffer.color_difference_percentage(variable_image, diff)
end

.run(paths) ⇒ Object



19
20
21
# File 'lib/compatriot.rb', line 19

def run(paths)
  Compatriot::Runner.start(app, paths)
end

.take_screenshot(test, description) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/compatriot.rb', line 23

def take_screenshot(test, description)
  filename = filename_for_test(test, description)
  control_image_path = filepath_for_screenshot('control', filename)

  if File.exist?(control_image_path)
    screenshot_type = 'variable'
  else
    screenshot_type = 'control'
  end
  framework.current_session.save_screenshot filepath_for_screenshot(screenshot_type, filename)
end