compaa 0.0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ results.html
3
+ pkg
4
+ html
5
+ Gemfile.lock
6
+ coverage
7
+ tags
8
+ tmp
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - ruby-head
4
+ - 1.9.3
5
+ - 1.8.7
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+ - rbx-18mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,14 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'cucumber' do
5
+ watch(%r{^features/.+\.feature$})
6
+ watch(%r{^features/support/.+$}) { 'features' }
7
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
8
+ end
9
+
10
+ guard 'minitest' do
11
+ watch(%r|^spec/(.*)_spec\.rb|)
12
+ watch(%r|^lib/compaa/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
13
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
14
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jamie English
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ [![Build Status](https://secure.travis-ci.org/jamienglish/compaa.png?branch=master)](https://travis-ci.org/jamienglish/compaa)
2
+
3
+ # compaa
4
+
5
+ As a companion to `Symilaa`, `Compaa` compares screenshots and presents the user
6
+ with a prompt to accept or reject the new screenshot.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'compaa'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install compaa
21
+
22
+ ## Usage
23
+
24
+ See cucumber features.
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
@@ -0,0 +1,18 @@
1
+ require 'bundler'
2
+
3
+ require 'rake'
4
+ require 'rake/testtask'
5
+ require 'cucumber/rake/task'
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ Rake::TestTask.new :spec do |t|
10
+ t.libs << 'spec'
11
+ t.pattern = 'spec/**/*_spec.rb'
12
+ end
13
+
14
+ Cucumber::Rake::Task.new :features do |t|
15
+ t.cucumber_opts = 'features --format pretty'
16
+ end
17
+
18
+ task :default => [:spec, :features]
data/app.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'sinatra'
2
+
3
+ module Compaa
4
+ class Screenshots < Sinatra::Base
5
+ get '/' do
6
+ haml :index
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'methadone'
5
+ require 'compaa'
6
+ require 'sinatra'
7
+ require 'watir-webdriver'
8
+ require 'cgi'
9
+
10
+ class App
11
+ include Methadone::Main
12
+ include Methadone::CLILogging
13
+
14
+ PORT = '7788'
15
+
16
+ main do
17
+
18
+ sinatra_pid = fork do
19
+ user_project_path = Dir.pwd
20
+
21
+ Dir.chdir(File.dirname(__FILE__))
22
+ Dir.chdir("../")
23
+ puts Dir.pwd
24
+
25
+ puts "ln -s #{user_project_path} #{Dir.pwd}/public"
26
+
27
+ exec "thin start -p #{PORT}"
28
+ end
29
+
30
+ browser = Watir::Browser.new
31
+ browser.window.resize_to 1368, 1200
32
+
33
+ sleep 3
34
+
35
+ Compaa::DifferenceImage.all.each do |difference_image|
36
+ browser.goto "http://localhost:#{PORT}/?filepath=#{CGI::escape(difference_image.path)}"
37
+ puts "Comparing: #{difference_image.path}"
38
+ puts "Would you like to make this the reference image?"
39
+
40
+ difference_image.create_reference_image if screenshot_approved?
41
+ end
42
+
43
+ Compaa::GeneratedImage.all.each do |generated_image|
44
+ next if generated_image.has_reference_image?
45
+
46
+ puts "Approving: #{generated_image.path}"
47
+ generated_image.create_reference_image if screenshot_approved?
48
+ end
49
+
50
+ `kill -9 #{sinatra_pid}`
51
+
52
+ browser.close
53
+
54
+ end
55
+
56
+ def self.screenshot_approved?
57
+ STDIN.gets.chomp.downcase.start_with? 'y'
58
+ end
59
+
60
+ version Compaa::VERSION
61
+
62
+ use_log_level_option
63
+
64
+ go!
65
+ end
@@ -0,0 +1,37 @@
1
+ lib = File.expand_path 'lib', File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
3
+ require 'compaa/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'compaa'
7
+ gem.version = Compaa::VERSION
8
+ gem.authors = ['BSkyB Helpcentre']
9
+ gem.email = ['skyhelpcentre@gmail.com']
10
+ gem.summary = <<-SUMMARY
11
+ Command line tool to compare screenshots outputted from our
12
+ screenshot_comparison gem
13
+ SUMMARY
14
+ gem.homepage = 'https://github.com/bskyb-commerce-helpcentre/compaa'
15
+
16
+ gem.files = `git ls-files`.split $/
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename f }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ %w[rake aruba simplecov wrong minitest guard-minitest guard-cucumber].each do |lib|
22
+ gem.add_development_dependency lib
23
+ end
24
+
25
+ gem.add_development_dependency 'rb-inotify' if RUBY_PLATFORM =~ /linux/
26
+
27
+ if RUBY_PLATFORM =~ /darwin/
28
+ gem.add_development_dependency 'rb-fsevent'
29
+ gem.add_development_dependency 'terminal-notifier-guard'
30
+ end
31
+
32
+ gem.add_dependency 'methadone', '~> 1.2.2'
33
+ gem.add_dependency 'sinatra'
34
+ gem.add_dependency 'thin'
35
+ gem.add_dependency 'haml'
36
+ gem.add_dependency 'watir-webdriver'
37
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require './app'
5
+
6
+ run Compaa::Screenshots
@@ -0,0 +1,38 @@
1
+ Feature: Generate Rake Artifacts Tasks
2
+
3
+ In order to be able to view screenshot failures and decide whether accept or reject them
4
+ As a Help Centre developer
5
+ I want to be able to compare screenshots
6
+
7
+ Scenario: App just runs
8
+ When I get help for "compaa"
9
+ Then the exit status should be 0
10
+ And the banner should be present
11
+ And the banner should document that this app takes options
12
+ And the following options should be documented:
13
+ | --version |
14
+ And the banner should document that this app takes no arguments
15
+
16
+ Scenario: Compare screenshots and approve
17
+ Given a sample reference screenshot
18
+ And a sample generated screenshot
19
+ And a sample difference screenshot
20
+ When I run `compaa` interactively
21
+ And I approve the screenshot
22
+ Then the new reference screenshot should be the same as the sample generated screenshot
23
+ And the difference image should have been deleted
24
+
25
+ Scenario: Compare screenshots and reject
26
+ Given a sample reference screenshot
27
+ And a sample generated screenshot
28
+ And a sample difference screenshot
29
+ When I run `compaa` interactively
30
+ And I reject the screenshot
31
+ Then the new reference screenshot should be the same as the original reference screenshot
32
+
33
+ Scenario: Generated images without corresponding reference images require approval
34
+ Given a sample generated screenshot
35
+ And no reference images or difference images
36
+ When I run `compaa` interactively
37
+ And I approve the screenshot
38
+ Then the new reference screenshot should be the same as the sample generated screenshot
@@ -0,0 +1,51 @@
1
+ Given /^no reference images or difference images$/ do
2
+ # do nothing
3
+ end
4
+
5
+ Given /^a sample reference screenshot$/ do
6
+ write_file 'artifacts/reference_screenshots/dir/image.png',
7
+ sample_reference_image
8
+ end
9
+
10
+ Given /^a sample generated screenshot$/ do
11
+ write_file 'artifacts/screenshots_generated_this_run/dir/image.png',
12
+ sample_generated_image
13
+ end
14
+
15
+ Given /^a sample difference screenshot$/ do
16
+ write_file 'artifacts/differences_in_screenshots_this_run/dir/image.png_difference.gif',
17
+ sample_difference_image
18
+ end
19
+
20
+ When /^I reject the screenshot$/ do
21
+ type 'No'
22
+ end
23
+
24
+ When /^I approve the screenshot$/ do
25
+ type 'Yes'
26
+ end
27
+
28
+ Then /^the new reference screenshot should be the same as the sample generated screenshot$/ do
29
+ sample_generated_file_path = File.join fixture_image_path, 'sample_generated.png'
30
+ new_reference_file_path = File.join current_dir, *%w[artifacts reference_screenshots dir image.png]
31
+
32
+ eventually :timeout => RUBY_PLATFORM == 'java' ? 20 : 3 do
33
+ new_reference_file_path.should be_the_same_file_as sample_generated_file_path
34
+ end
35
+ end
36
+
37
+ Then /^the new reference screenshot should be the same as the original reference screenshot$/ do
38
+ original_reference_file_path = File.join fixture_image_path, 'sample_reference.png'
39
+ new_reference_file_path = File.join current_dir, *%w[artifacts reference_screenshots dir image.png]
40
+
41
+ eventually :timeout => RUBY_PLATFORM == 'java' ? 20 : 3 do
42
+ new_reference_file_path.should be_the_same_file_as original_reference_file_path
43
+ end
44
+ end
45
+
46
+ Then /^the difference image should have been deleted$/ do
47
+ difference_image = File.join current_dir,
48
+ *%w[artifacts differences_in_screenshots_this_run dir image.png_difference.gif]
49
+
50
+ difference_image.should_not exist
51
+ end
@@ -0,0 +1,29 @@
1
+ require 'aruba/cucumber'
2
+ require 'methadone/cucumber'
3
+ require 'wrong'
4
+
5
+ include Wrong
6
+
7
+ ENV['APP_ENV'] = 'test'
8
+
9
+ bin_dir = File.expand_path File.dirname(__FILE__), '../../bin'
10
+ ENV['PATH'] = bin_dir + File::PATH_SEPARATOR + ENV['PATH']
11
+ LIB_DIR = File.expand_path File.dirname(__FILE__), '../../lib'
12
+
13
+ Before do
14
+ # Using "announce" causes massive warnings on 1.9.2
15
+ @puts = true
16
+ @original_rubylib = ENV['RUBYLIB']
17
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
18
+ @aruba_timeout_seconds = RUBY_PLATFORM == 'java' ? 20 : 5
19
+ end
20
+
21
+ Aruba.configure do |config|
22
+ config.before_cmd do |cmd|
23
+ set_env('JRUBY_OPTS', "-X-C #{ENV['JRUBY_OPTS']}") # disable JIT since these processes are so short lived
24
+ end
25
+ end if RUBY_PLATFORM == 'java'
26
+
27
+ After do
28
+ ENV['RUBYLIB'] = @original_rubylib
29
+ end
@@ -0,0 +1,23 @@
1
+ module FileHelpers
2
+ def sample_reference_image
3
+ fixture_image('sample_reference.png').read
4
+ end
5
+
6
+ def sample_generated_image
7
+ fixture_image('sample_generated.png').read
8
+ end
9
+
10
+ def sample_difference_image
11
+ fixture_image('sample_generated.png_difference.gif').read
12
+ end
13
+
14
+ def fixture_image file_name
15
+ File.new File.join(fixture_image_path, file_name)
16
+ end
17
+
18
+ def fixture_image_path
19
+ File.expand_path "../../fixtures", File.dirname(__FILE__)
20
+ end
21
+ end
22
+
23
+ World FileHelpers
@@ -0,0 +1,13 @@
1
+ require 'fileutils'
2
+
3
+ RSpec::Matchers.define :be_the_same_file_as do |expected|
4
+ match do |actual|
5
+ FileUtils.cmp actual, expected
6
+ end
7
+ end
8
+
9
+ RSpec::Matchers.define :exist do
10
+ match do |path|
11
+ File.exists? path
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ require 'compaa/version'
2
+ require 'compaa/difference_image'
3
+ require 'compaa/generated_image'
@@ -0,0 +1,37 @@
1
+ require 'fileutils'
2
+
3
+ module Compaa
4
+ class DifferenceImage < Struct.new(:path)
5
+ attr_writer :file_manager
6
+
7
+ def self.all
8
+ Dir.glob(File.join %w[artifacts differences_in_screenshots_this_run ** *.gif]).map { |path|
9
+ new path
10
+ }
11
+ end
12
+
13
+ def create_reference_image
14
+ file_manager.mkdir_p File.dirname reference_path
15
+ file_manager.cp generated_path, reference_path
16
+ file_manager.rm path
17
+ end
18
+
19
+ def reference_path
20
+ path.gsub(
21
+ 'differences_in_screenshots_this_run', 'reference_screenshots'
22
+ ).gsub('_difference.gif', '')
23
+ end
24
+
25
+ def generated_path
26
+ path.gsub(
27
+ 'differences_in_screenshots_this_run', 'screenshots_generated_this_run'
28
+ ).gsub('_difference.gif', '')
29
+ end
30
+
31
+ private
32
+
33
+ def file_manager
34
+ @file_manager ||= FileUtils
35
+ end
36
+ end
37
+ end