Sha256: cc4fea7f6eb5cf6b2beba527741381296eb02643c1562380177e7f8f71cf5d16

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'methadone'
require 'compaa'
require 'rack'
if ENV['TRAVIS'] == 'true'
  require 'watir-webdriver-fake'
else
  require 'watir-webdriver'
end
require 'cgi'

class App
  include Methadone::Main
  include Methadone::CLILogging

  PORT = 7788

  main do
    begin
      start_server_in_background

      browser = Watir::Browser.new
      browser.window.resize_to 1368, 1200

      Compaa::DifferenceImage.all.each do |difference_image|
        browser.goto "http://localhost:#{PORT}/?filepath=#{difference_image.path}"
        puts "Comparing: #{difference_image.path}"
        puts "Would you like to make this the reference image?"

        difference_image.create_reference_image if screenshot_approved?
      end

      Compaa::GeneratedImage.all.each do |generated_image|
        next if generated_image.has_reference_image?

        browser.goto "http://localhost:#{PORT}/#{generated_image.path}"
        puts "Approving: #{generated_image.path}"
        puts "Would you like accept this new reference image?"
        generated_image.create_reference_image if screenshot_approved?
      end
    ensure
      shutdown_server
      browser.close
    end
  end

  def self.start_server_in_background
    Thread.new do
      Rack::Handler::WEBrick.run Compaa::RackApp.new.app,
        :Port      => PORT,
        :Logger    => Compaa::NullObject.new,
        :AccessLog => [nil, nil]
    end
  end

  def self.shutdown_server
    Rack::Handler::WEBrick.shutdown
  end

  def self.screenshot_approved?
    STDIN.gets.chomp.downcase.start_with? 'y'
  end

  version Compaa::VERSION

  use_log_level_option

  go!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
compaa-0.0.3 bin/compaa