green_onion 0.0.4 → 0.0.5
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.
- data/Rakefile +9 -9
- data/green_onion.gemspec +5 -5
- data/lib/green_onion.rb +63 -63
- data/lib/green_onion/compare.rb +63 -56
- data/lib/green_onion/configuration.rb +16 -16
- data/lib/green_onion/screenshot.rb +54 -55
- data/lib/green_onion/version.rb +1 -1
- data/spec/sample_app/sample_app.rb +5 -1
- data/spec/unit/compare_spec.rb +19 -19
- data/spec/unit/green_onion_spec.rb +121 -121
- data/spec/unit/screenshot_spec.rb +78 -78
- metadata +22 -21
data/Rakefile
CHANGED
@@ -4,21 +4,21 @@ require 'rack'
|
|
4
4
|
|
5
5
|
desc "Running server..."
|
6
6
|
task :server do
|
7
|
-
|
8
|
-
|
7
|
+
require File.dirname(__FILE__) + '/spec/sample_app/sample_app.rb'
|
8
|
+
Rack::Handler::WEBrick.run SampleApp, :Port => 8070
|
9
9
|
end
|
10
10
|
|
11
11
|
desc "Running specs..."
|
12
12
|
task :specs do
|
13
|
-
|
13
|
+
system "rspec spec"
|
14
14
|
end
|
15
15
|
|
16
16
|
desc "Running specs on test server"
|
17
17
|
task :spec do
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# have the server run on its own thread so that it doesn't block the spec task
|
19
|
+
server = Thread.new do
|
20
|
+
task("server").execute
|
21
|
+
end
|
22
|
+
task("specs").execute
|
23
|
+
server.kill
|
24
24
|
end
|
data/green_onion.gemspec
CHANGED
@@ -10,15 +10,15 @@ Gem::Specification.new do |gem|
|
|
10
10
|
|
11
11
|
gem.add_development_dependency "rake"
|
12
12
|
gem.add_development_dependency "rspec"
|
13
|
-
gem.add_development_dependency "fileutils"
|
14
13
|
gem.add_development_dependency "pry"
|
15
14
|
gem.add_development_dependency "debugger"
|
16
15
|
gem.add_development_dependency "sinatra"
|
17
16
|
|
18
|
-
gem.add_dependency "capybara"
|
19
|
-
gem.add_dependency "capybara-webkit"
|
20
|
-
gem.add_dependency "oily_png"
|
21
|
-
gem.add_dependency "rainbow"
|
17
|
+
gem.add_dependency "capybara", "1.1.2"
|
18
|
+
gem.add_dependency "capybara-webkit", "0.12.1"
|
19
|
+
gem.add_dependency "oily_png", "1.0.2"
|
20
|
+
gem.add_dependency "rainbow", "1.1.4"
|
21
|
+
gem.add_dependency "fileutils", "0.7"
|
22
22
|
|
23
23
|
gem.files = `git ls-files`.split($\)
|
24
24
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/green_onion.rb
CHANGED
@@ -5,77 +5,77 @@ require "green_onion/configuration"
|
|
5
5
|
require "rainbow"
|
6
6
|
|
7
7
|
module GreenOnion
|
8
|
-
|
8
|
+
class << self
|
9
9
|
|
10
|
-
|
10
|
+
attr_reader :compare, :screenshot
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
# Pass configure block to set Configuration object
|
13
|
+
def configure
|
14
|
+
yield configuration
|
15
|
+
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def configuration
|
18
|
+
@configuration ||= GreenOnion::Configuration.new
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
# Bring the Screenshot and Compare classes together to create a skin
|
22
|
+
def skin(url)
|
23
|
+
@screenshot = Screenshot.new(
|
24
|
+
:dir => @configuration.skins_dir,
|
25
|
+
:dimensions => @configuration.dimensions
|
26
|
+
)
|
27
|
+
@compare = GreenOnion::Compare.new
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
@screenshot.test_screenshot(url)
|
30
|
+
end
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
# Finds the percentage of change between skins
|
33
|
+
# Threshold can be set in configuration, or as an argument itself, and can be specific to an instance
|
34
|
+
def skin_percentage(url, threshold=@configuration.threshold)
|
35
|
+
skin(url)
|
36
|
+
if(@screenshot.paths_hash.length > 1)
|
37
|
+
puts "\n" + url.color(:cyan)
|
38
|
+
@compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
39
|
+
threshold_alert(@compare.percentage_changed, threshold)
|
40
|
+
else
|
41
|
+
puts "\n#{url}".color(:cyan) + " has been saved to #{@screenshot.paths_hash[:original]}".color(:yellow)
|
42
|
+
end
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
45
|
+
# Creates a diffed screenshot between skins
|
46
|
+
def skin_visual(url)
|
47
|
+
skin(url)
|
48
|
+
if(@screenshot.paths_hash.length > 1)
|
49
|
+
puts "\n" + url.color(:cyan)
|
50
|
+
@compare.visual_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
51
|
+
else
|
52
|
+
puts "\n#{url}".color(:cyan) + " has been saved to #{@screenshot.paths_hash[:original]}".color(:yellow)
|
53
|
+
end
|
54
|
+
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
56
|
+
# Creates a diffed screenshot between skins AND prints percentage changed
|
57
|
+
def skin_visual_and_percentage(url, threshold=@configuration.threshold)
|
58
|
+
skin(url)
|
59
|
+
if(@screenshot.paths_hash.length > 1)
|
60
|
+
puts "\n" + url.color(:cyan)
|
61
|
+
@compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
62
|
+
@compare.visual_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
63
|
+
threshold_alert(@compare.percentage_changed, threshold)
|
64
|
+
else
|
65
|
+
puts "\n#{url}".color(:cyan) + " has been saved to #{@screenshot.paths_hash[:original]}".color(:yellow)
|
66
|
+
end
|
67
|
+
end
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
69
|
+
# This is used in skin_percentage to better alert if a set of skins are ok or not
|
70
|
+
def threshold_alert(actual, threshold)
|
71
|
+
if actual > threshold
|
72
|
+
puts "#{actual - threshold}% above threshold set @ #{threshold}%".color(:red)
|
73
|
+
puts "pixels changed (%): #{@compare.percentage_changed}%"
|
74
|
+
puts "pixels changed/total: #{@compare.changed_px}/#{@compare.total_px}"
|
75
|
+
else
|
76
|
+
puts "pixels changed/total: #{@compare.changed_px}/#{@compare.total_px}"
|
77
|
+
end
|
78
|
+
end
|
79
79
|
|
80
|
-
|
80
|
+
end
|
81
81
|
end
|
data/lib/green_onion/compare.rb
CHANGED
@@ -2,60 +2,67 @@ require "oily_png"
|
|
2
2
|
require "rainbow"
|
3
3
|
|
4
4
|
module GreenOnion
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
5
|
+
class Compare
|
6
|
+
|
7
|
+
attr_accessor :percentage_changed, :total_px, :changed_px
|
8
|
+
attr_reader :diffed_image
|
9
|
+
|
10
|
+
# Pulled from Jeff Kreeftmeijer's post here: http://jeffkreeftmeijer.com/2011/comparing-images-and-creating-image-diffs/
|
11
|
+
# Thanks Jeff!
|
12
|
+
def diff_images(org, fresh)
|
13
|
+
@images = [
|
14
|
+
ChunkyPNG::Image.from_file(org),
|
15
|
+
ChunkyPNG::Image.from_file(fresh)
|
16
|
+
]
|
17
|
+
|
18
|
+
@diff_index = []
|
19
|
+
|
20
|
+
@images.first.height.times do |y|
|
21
|
+
@images.first.row(y).each_with_index do |pixel, x|
|
22
|
+
unless pixel == @images.last[x,y]
|
23
|
+
@diff_index << [x,y]
|
24
|
+
@images.last[x,y] = ChunkyPNG::Color.rgb(
|
25
|
+
ChunkyPNG::Color.r(pixel) + ChunkyPNG::Color.r(@images.last[x,y]) - 2 * [ChunkyPNG::Color.r(pixel), ChunkyPNG::Color.r(@images.last[x,y])].min,
|
26
|
+
ChunkyPNG::Color.g(pixel) + ChunkyPNG::Color.g(@images.last[x,y]) - 2 * [ChunkyPNG::Color.g(pixel), ChunkyPNG::Color.g(@images.last[x,y])].min,
|
27
|
+
ChunkyPNG::Color.b(pixel) + ChunkyPNG::Color.b(@images.last[x,y]) - 2 * [ChunkyPNG::Color.b(pixel), ChunkyPNG::Color.b(@images.last[x,y])].min
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def percentage_diff(org, fresh)
|
35
|
+
diff_images(org, fresh)
|
36
|
+
@total_px = @images.first.pixels.length
|
37
|
+
@changed_px = @diff_index.length
|
38
|
+
@percentage_changed = ( (@diff_index.length.to_f / @images.first.pixels.length) * 100 ).round(2)
|
39
|
+
end
|
40
|
+
|
41
|
+
def visual_diff(org, fresh)
|
42
|
+
diff_images(org, fresh)
|
43
|
+
diff_iterating(org, fresh)
|
44
|
+
end
|
45
|
+
|
46
|
+
def percentage_and_visual_diff(org, fresh)
|
47
|
+
diff_images(org, fresh)
|
48
|
+
@total_px = @images.first.pixels.length
|
49
|
+
@changed_px = @diff_index.length
|
50
|
+
@percentage_changed = ( (@diff_index.length.to_f / @images.first.pixels.length) * 100 ).round(2)
|
51
|
+
end
|
52
|
+
|
53
|
+
def diff_iterating(org, fresh)
|
54
|
+
x, y = @diff_index.map{ |xy| xy[0] }, @diff_index.map{ |xy| xy[1] }
|
55
|
+
|
56
|
+
@diffed_image = org.insert(-5, '_diff')
|
57
|
+
|
58
|
+
begin
|
59
|
+
@images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
|
60
|
+
rescue NoMethodError
|
61
|
+
puts "Both skins are the same.".color(:yellow)
|
62
|
+
end
|
63
|
+
|
64
|
+
@images.last.save(@diffed_image)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
61
68
|
end
|
@@ -1,23 +1,23 @@
|
|
1
1
|
module GreenOnion
|
2
|
-
|
2
|
+
class Configuration
|
3
3
|
|
4
|
-
|
4
|
+
attr_writer :threshold, :skins_dir
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def dimensions=(options)
|
7
|
+
@dimensions = { :width => options[:width], :height => options[:height] }
|
8
|
+
end
|
9
|
+
|
10
|
+
def dimensions
|
11
|
+
@dimensions ||= { :height => 768, :width => 1024 }
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
def threshold
|
15
|
+
@threshold ||= 100
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
def skins_dir
|
19
|
+
@skins_dir ||= './spec/skins'
|
20
|
+
end
|
17
21
|
|
18
|
-
|
19
|
-
@skins_dir ||= './spec/skins'
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
22
|
+
end
|
23
23
|
end
|
@@ -1,61 +1,60 @@
|
|
1
1
|
require 'capybara/dsl'
|
2
2
|
require 'capybara-webkit'
|
3
3
|
require "fileutils"
|
4
|
-
require "debugger"
|
5
4
|
|
6
5
|
module GreenOnion
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
6
|
+
class Screenshot
|
7
|
+
include Capybara::DSL
|
8
|
+
|
9
|
+
attr_accessor :dir, :dimensions
|
10
|
+
attr_reader :paths_hash
|
11
|
+
|
12
|
+
def initialize(params = {})
|
13
|
+
Capybara.default_driver = :webkit
|
14
|
+
@dimensions = params[:dimensions]
|
15
|
+
@dir = params[:dir]
|
16
|
+
@paths_hash = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def snap_screenshot(url, path)
|
20
|
+
visit url
|
21
|
+
Capybara.page.driver.render(path, @dimensions)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_screenshot(url)
|
25
|
+
url_to_path(url)
|
26
|
+
snap_screenshot(url, @shot_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
def url_to_path(url)
|
30
|
+
get_path(url)
|
31
|
+
if File.exist?(@paths_hash[:original])
|
32
|
+
@paths_hash[:fresh] = @paths_hash[:original].dup.insert(-5, '_fresh')
|
33
|
+
@shot_path = @paths_hash[:fresh]
|
34
|
+
else
|
35
|
+
@shot_path = @paths_hash[:original]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_path(url)
|
40
|
+
@filename = url.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/)[5]
|
41
|
+
if @filename.empty? || @filename == '/'
|
42
|
+
@paths_hash[:original] = "#{@dir}/root.png"
|
43
|
+
else
|
44
|
+
@filename = @filename.gsub(/[\/]/, '')
|
45
|
+
@paths_hash[:original] = "#{@dir}/#{@filename}.png"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy(url)
|
50
|
+
get_path(url)
|
51
|
+
if File.exist?( @paths_hash[:original] )
|
52
|
+
FileUtils.rm( @paths_hash[:original] )
|
53
|
+
if File.exist?( @paths_hash[:fresh] )
|
54
|
+
FileUtils.rm( @paths_hash[:fresh] )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
61
60
|
end
|
data/lib/green_onion/version.rb
CHANGED
@@ -7,11 +7,15 @@ class SampleApp < Sinatra::Base
|
|
7
7
|
set :logging, false
|
8
8
|
|
9
9
|
get '/' do
|
10
|
-
|
10
|
+
"<div style='height:200px; width:200px; background-color:rgb(#{rand(266)}, #{rand(266)}, #{rand(266)})'><!-- Big blue box --></div>"
|
11
11
|
end
|
12
12
|
|
13
13
|
get "/fake_uri" do
|
14
14
|
"<h2>foo</h2>"
|
15
15
|
end
|
16
16
|
|
17
|
+
get "/onion_face" do
|
18
|
+
"<img src='onion_face_#{rand(2)}.jpg' />"
|
19
|
+
end
|
20
|
+
|
17
21
|
end
|
data/spec/unit/compare_spec.rb
CHANGED
@@ -2,27 +2,27 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe GreenOnion::Compare do
|
4
4
|
|
5
|
-
|
5
|
+
describe 'Comparing Screenshots' do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
before(:each) do
|
8
|
+
@comparison = GreenOnion::Compare.new
|
9
|
+
@spec_shot1 = './spec/skins/spec_shot.png'
|
10
|
+
@spec_shot2 = './spec/skins/spec_shot_fresh.png'
|
11
|
+
@diff_shot = './spec/skins/spec_shot_diff.png'
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
after(:all) do
|
15
|
+
FileUtils.rm('./spec/skins/spec_shot_diff.png', :force => true)
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
it 'should get a percentage of difference between two shots' do
|
19
|
+
@comparison.percentage_diff(@spec_shot1, @spec_shot2)
|
20
|
+
@comparison.percentage_changed.should eq(66.0)
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
it 'should create a new file with a visual diff between two shots' do
|
24
|
+
@comparison.visual_diff(@spec_shot1, @spec_shot2)
|
25
|
+
File.exist?(@diff_shot).should be_true
|
26
|
+
end
|
27
|
+
end
|
28
28
|
end
|
@@ -2,125 +2,125 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe GreenOnion do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
5
|
+
before(:all) do
|
6
|
+
@tmp_path = './spec/tmp'
|
7
|
+
@url = 'http://localhost:8070'
|
8
|
+
@url_w_uri = @url + '/fake_uri'
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "Skins" do
|
12
|
+
before(:each) do
|
13
|
+
FileUtils.mkdir(@tmp_path)
|
14
|
+
|
15
|
+
GreenOnion.configure do |c|
|
16
|
+
c.skins_dir = @tmp_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
after(:each) do
|
21
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should default to 1024x768 browser dimensions" do
|
25
|
+
( (GreenOnion.configuration.dimensions[:height] == 768) &&
|
26
|
+
(GreenOnion.configuration.dimensions[:width] == 1024) ).should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should set/get custom directory" do
|
30
|
+
GreenOnion.configuration.skins_dir.should eq(@tmp_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get the correct paths_hash" do
|
34
|
+
2.times do
|
35
|
+
GreenOnion.skin(@url)
|
36
|
+
end
|
37
|
+
( (GreenOnion.screenshot.paths_hash[:original] == "#{@tmp_path}/root.png") &&
|
38
|
+
(GreenOnion.screenshot.paths_hash[:fresh] == "#{@tmp_path}/root_fresh.png") ).should be_true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should measure the percentage of diff between skins" do
|
42
|
+
2.times do
|
43
|
+
GreenOnion.skin_percentage(@url)
|
44
|
+
end
|
45
|
+
GreenOnion.compare.percentage_changed.should be > 0
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should measure the percentage of diff between skins (even if there is no diff)" do
|
49
|
+
2.times do
|
50
|
+
GreenOnion.skin_percentage(@url_w_uri)
|
51
|
+
end
|
52
|
+
GreenOnion.compare.percentage_changed.should be == 0
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should print just URL and changed/total when diff percentage threshold has not been surpassed" do
|
56
|
+
$stdout.should_receive(:puts).exactly(3).times
|
57
|
+
2.times do
|
58
|
+
GreenOnion.skin_percentage(@url, 6)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should create visual diff between skins" do
|
63
|
+
2.times do
|
64
|
+
GreenOnion.skin_visual(@url)
|
65
|
+
end
|
66
|
+
GreenOnion.compare.diffed_image.should eq("#{@tmp_path}/root_diff.png")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should create visual diff between skins (even when there is no change)" do
|
70
|
+
2.times do
|
71
|
+
GreenOnion.skin_visual(@url_w_uri)
|
72
|
+
end
|
73
|
+
GreenOnion.compare.diffed_image.should eq("#{@tmp_path}/fake_uri_diff.png")
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should measure the percentage of diff between skins AND create visual diff" do
|
77
|
+
2.times do
|
78
|
+
GreenOnion.skin_visual_and_percentage(@url)
|
79
|
+
end
|
80
|
+
( (GreenOnion.compare.diffed_image.should eq("#{@tmp_path}/root_diff.png")) &&
|
81
|
+
(GreenOnion.compare.percentage_changed.should be > 0) ).should be_true
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "Skins with custom dimensions" do
|
86
|
+
before(:each) do
|
87
|
+
FileUtils.mkdir(@tmp_path)
|
88
|
+
|
89
|
+
GreenOnion.configure do |c|
|
90
|
+
c.skins_dir = @tmp_path
|
91
|
+
c.dimensions = { :width => 1440, :height => 900 }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
after(:each) do
|
96
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should allow custom browser dimensions" do
|
100
|
+
( (GreenOnion.configuration.dimensions[:height] == 900) &&
|
101
|
+
(GreenOnion.configuration.dimensions[:width] == 1440) ).should be_true
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "Skins with custom threshold" do
|
106
|
+
before(:each) do
|
107
|
+
FileUtils.mkdir(@tmp_path)
|
108
|
+
|
109
|
+
GreenOnion.configure do |c|
|
110
|
+
c.skins_dir = @tmp_path
|
111
|
+
c.threshold = 1
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
after(:each) do
|
116
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should alert when diff percentage threshold is surpassed" do
|
120
|
+
$stdout.should_receive(:puts).exactly(5).times
|
121
|
+
2.times do
|
122
|
+
GreenOnion.skin_percentage(@url)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
126
|
end
|
@@ -2,85 +2,85 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe GreenOnion::Screenshot do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
before(:all) do
|
6
|
+
@url = 'http://localhost:8070'
|
7
|
+
@url_w_uri = @url + '/fake_uri'
|
8
|
+
@tmp_path = './spec/tmp'
|
9
|
+
@dimensions = { :width => 1024, :height => 768 }
|
10
|
+
end
|
11
11
|
|
12
12
|
describe 'Snap single screenshot' do
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
14
|
+
before(:each) do
|
15
|
+
FileUtils.mkdir(@tmp_path)
|
16
|
+
|
17
|
+
@screenshot = GreenOnion::Screenshot.new(
|
18
|
+
:dir => @tmp_path,
|
19
|
+
:dimensions => @dimensions
|
20
|
+
)
|
21
|
+
@file = "#{@tmp_path}/fake_uri.png"
|
22
|
+
end
|
23
|
+
|
24
|
+
after(:each) do
|
25
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should build the path from the URI' do
|
29
|
+
@screenshot.url_to_path(@url_w_uri).should eq(@file)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should build the path from root' do
|
33
|
+
@screenshot.url_to_path('http://localhost:8070').should eq("#{@tmp_path}/root.png")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should build the path from root (even with trailing slash)' do
|
37
|
+
@screenshot.url_to_path('http://localhost:8070/').should eq("#{@tmp_path}/root.png")
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should snap and save screenshot' do
|
41
|
+
@screenshot.snap_screenshot(@url_w_uri, @file)
|
42
|
+
File.exist?(@file).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should destroy a singular screenshot" do
|
46
|
+
@screenshot.destroy(@url_w_uri)
|
47
|
+
File.exist?(@file).should be_false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe 'Snap two screenshots' do
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
FileUtils.mkdir(@tmp_path)
|
55
|
+
|
56
|
+
@screenshot = GreenOnion::Screenshot.new(
|
57
|
+
:dir => @tmp_path,
|
58
|
+
:dimensions => @dimensions
|
59
|
+
)
|
60
|
+
@file1 = "#{@tmp_path}/fake_uri.png"
|
61
|
+
@file2 = "#{@tmp_path}/fake_uri_fresh.png"
|
62
|
+
2.times do
|
63
|
+
@screenshot.test_screenshot(@url_w_uri)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
after(:each) do
|
68
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should create the paths_hash correctly" do
|
72
|
+
( (@screenshot.paths_hash[:original].should eq(@file1)) && (@screenshot.paths_hash[:fresh].should eq(@file2)) ).should be_true
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should snap and save another screenshot if a screenshot already exists" do
|
76
|
+
if File.exist?(@file1)
|
77
|
+
File.exist?(@file2).should be_true
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should destroy a set of screenshots" do
|
82
|
+
@screenshot.destroy(@url_w_uri)
|
83
|
+
( File.exist?(@file1) && File.exist?(@file2) ).should be_false
|
84
|
+
end
|
85
|
+
end
|
86
86
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: green_onion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ted O'Meara
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-07-
|
13
|
+
date: 2012-07-31 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -35,7 +35,7 @@ dependencies:
|
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: pry
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
|
-
name:
|
49
|
+
name: debugger
|
50
50
|
prerelease: false
|
51
51
|
requirement: &id004 !ruby/object:Gem::Requirement
|
52
52
|
none: false
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: sinatra
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -68,58 +68,58 @@ dependencies:
|
|
68
68
|
type: :development
|
69
69
|
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
71
|
+
name: capybara
|
72
72
|
prerelease: false
|
73
73
|
requirement: &id006 !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
|
-
- - "
|
76
|
+
- - "="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
79
|
-
type: :
|
78
|
+
version: 1.1.2
|
79
|
+
type: :runtime
|
80
80
|
version_requirements: *id006
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
|
-
name: capybara
|
82
|
+
name: capybara-webkit
|
83
83
|
prerelease: false
|
84
84
|
requirement: &id007 !ruby/object:Gem::Requirement
|
85
85
|
none: false
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 0.12.1
|
90
90
|
type: :runtime
|
91
91
|
version_requirements: *id007
|
92
92
|
- !ruby/object:Gem::Dependency
|
93
|
-
name:
|
93
|
+
name: oily_png
|
94
94
|
prerelease: false
|
95
95
|
requirement: &id008 !ruby/object:Gem::Requirement
|
96
96
|
none: false
|
97
97
|
requirements:
|
98
|
-
- - "
|
98
|
+
- - "="
|
99
99
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
100
|
+
version: 1.0.2
|
101
101
|
type: :runtime
|
102
102
|
version_requirements: *id008
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
|
-
name:
|
104
|
+
name: rainbow
|
105
105
|
prerelease: false
|
106
106
|
requirement: &id009 !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - "="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 1.1.4
|
112
112
|
type: :runtime
|
113
113
|
version_requirements: *id009
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
|
-
name:
|
115
|
+
name: fileutils
|
116
116
|
prerelease: false
|
117
117
|
requirement: &id010 !ruby/object:Gem::Requirement
|
118
118
|
none: false
|
119
119
|
requirements:
|
120
|
-
- - "
|
120
|
+
- - "="
|
121
121
|
- !ruby/object:Gem::Version
|
122
|
-
version: "0"
|
122
|
+
version: "0.7"
|
123
123
|
type: :runtime
|
124
124
|
version_requirements: *id010
|
125
125
|
description: UI testing/screenshot diffing tool
|
@@ -188,3 +188,4 @@ test_files:
|
|
188
188
|
- spec/unit/compare_spec.rb
|
189
189
|
- spec/unit/green_onion_spec.rb
|
190
190
|
- spec/unit/screenshot_spec.rb
|
191
|
+
has_rdoc:
|