Class: Compatriot::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/compatriot/runner.rb

Constant Summary collapse

BROWSERS =
["firefox", "chrome"]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, paths, clock) ⇒ Runner

Returns a new instance of Runner.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/compatriot/runner.rb', line 19

def initialize(app, paths, clock)
  @app   = app
  @paths = paths
  @clock = clock

  timestamp = @clock.now.strftime("%Y-%m-%d-%H-%M-%S")
  @results_directory = File.join("tmp", "results", timestamp)

  @browsers = Compatriot::Browser.create_browsers(
    :browser_names     => BROWSERS,
    :results_directory => @results_directory
  )
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/compatriot/runner.rb', line 17

def app
  @app
end

#results_directoryObject (readonly)

Returns the value of attribute results_directory.



17
18
19
# File 'lib/compatriot/runner.rb', line 17

def results_directory
  @results_directory
end

Class Method Details

.start(app, paths, clock = DateTime) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/compatriot/runner.rb', line 6

def self.start(app, paths, clock = DateTime)
  runner = new(app, paths, clock)
  runner.create_results_directory
  runner.take_screenshots
  runner.compute_diffs
  runner.make_index_page
  runner
end

Instance Method Details

#compute_diffsObject



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

def compute_diffs
  @differ = Compatriot::ImageDiffer.new(
    :paths    => @paths,
    :browsers => @browsers,
    :strategy => Compatriot::ColorDiffer,
    :results_directory => @results_directory
  )
  @differ.compute!
end

#create_results_directoryObject



61
62
63
# File 'lib/compatriot/runner.rb', line 61

def create_results_directory
  FileUtils.mkdir_p(@results_directory)
end

#make_index_pageObject



52
53
54
55
56
57
58
59
# File 'lib/compatriot/runner.rb', line 52

def make_index_page
  presenter = Compatriot::ResultsPresenter.new(@results_directory)
  presenter.make_index_page(
    :paths    => @paths,
    :browsers => @browsers,
    :differ   => @differ
  )
end

#take_screenshotsObject



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

def take_screenshots
  @browsers.each do |browser_object|
    browser_object.take_screenshots(
      :app   => @app,
      :paths => @paths
    )
  end
end