green_onion 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +7 -0
- data/README.md +3 -0
- data/green_onion.gemspec +2 -1
- data/lib/green_onion.rb +34 -1
- data/lib/green_onion/compare.rb +12 -4
- data/lib/green_onion/configuration.rb +11 -0
- data/lib/green_onion/screenshot.rb +23 -22
- data/lib/green_onion/version.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/compare_spec.rb +6 -0
- data/spec/unit/green_onion_spec.rb +49 -0
- data/spec/unit/screenshot_spec.rb +9 -1
- metadata +20 -5
data/.travis.yml
ADDED
data/README.md
CHANGED
data/green_onion.gemspec
CHANGED
@@ -12,9 +12,10 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.add_development_dependency "rspec"
|
13
13
|
gem.add_development_dependency "fileutils"
|
14
14
|
gem.add_development_dependency "pry"
|
15
|
+
gem.add_development_dependency "debugger"
|
15
16
|
|
16
17
|
gem.add_dependency "capybara"
|
17
|
-
gem.add_dependency "
|
18
|
+
gem.add_dependency "oily_png"
|
18
19
|
|
19
20
|
gem.files = `git ls-files`.split($\)
|
20
21
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
data/lib/green_onion.rb
CHANGED
@@ -1,9 +1,42 @@
|
|
1
1
|
require "green_onion/version"
|
2
2
|
require "green_onion/screenshot"
|
3
3
|
require "green_onion/compare"
|
4
|
-
|
4
|
+
require "green_onion/configuration"
|
5
5
|
module GreenOnion
|
6
6
|
class << self
|
7
7
|
|
8
|
+
attr_reader :compare, :screenshot
|
9
|
+
|
10
|
+
def configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def configuration
|
15
|
+
@configuration ||= GreenOnion::Configuration.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def skin(url)
|
19
|
+
@screenshot = Screenshot.new(
|
20
|
+
:dir => self.configuration.skins_dir
|
21
|
+
)
|
22
|
+
@compare = GreenOnion::Compare.new
|
23
|
+
|
24
|
+
@screenshot.test_screenshot(url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def skin_percentage(url)
|
28
|
+
self.skin(url)
|
29
|
+
if(@screenshot.paths_hash.length > 1)
|
30
|
+
self.compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def skin_visual(url)
|
35
|
+
self.skin(url)
|
36
|
+
if(@screenshot.paths_hash.length > 1)
|
37
|
+
self.compare.visual_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
8
41
|
end
|
9
42
|
end
|
data/lib/green_onion/compare.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
require "
|
1
|
+
require "oily_png"
|
2
2
|
|
3
3
|
module GreenOnion
|
4
4
|
class Compare
|
5
5
|
|
6
6
|
attr_accessor :percentage_changed, :total_px, :changed_px
|
7
|
+
attr_reader :diffed_image
|
7
8
|
|
8
9
|
# Pulled from Jeff Kreeftmeijer's post here: http://jeffkreeftmeijer.com/2011/comparing-images-and-creating-image-diffs/
|
9
10
|
# Thanks Jeff!
|
@@ -35,10 +36,17 @@ module GreenOnion
|
|
35
36
|
|
36
37
|
def visual_diff(org, fresh)
|
37
38
|
diff_images(org, fresh)
|
38
|
-
x, y = diff.map{ |xy| xy[0] }, diff.map{ |xy| xy[1] }
|
39
|
+
x, y = @diff.map{ |xy| xy[0] }, @diff.map{ |xy| xy[1] }
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
@diffed_image = org.insert(-5, '_diff')
|
42
|
+
|
43
|
+
begin
|
44
|
+
@images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
|
45
|
+
rescue NoMethodError
|
46
|
+
puts "#{org} and #{fresh} skins are the same."
|
47
|
+
end
|
48
|
+
|
49
|
+
@images.last.save(@diffed_image)
|
42
50
|
end
|
43
51
|
|
44
52
|
end
|
@@ -5,11 +5,13 @@ module GreenOnion
|
|
5
5
|
class Screenshot
|
6
6
|
include Capybara::DSL
|
7
7
|
|
8
|
-
attr_accessor :dir
|
8
|
+
attr_accessor :dir
|
9
|
+
attr_reader :paths_hash
|
9
10
|
|
10
11
|
def initialize(params = {})
|
11
12
|
Capybara.default_driver = :selenium
|
12
13
|
@dir = params[:dir]
|
14
|
+
@paths_hash = {}
|
13
15
|
end
|
14
16
|
|
15
17
|
def snap_screenshot(url, path)
|
@@ -19,38 +21,37 @@ module GreenOnion
|
|
19
21
|
|
20
22
|
def test_screenshot(url)
|
21
23
|
url_to_path(url)
|
22
|
-
snap_screenshot(url, @
|
24
|
+
snap_screenshot(url, @shot_path)
|
23
25
|
end
|
24
26
|
|
25
27
|
def url_to_path(url)
|
26
|
-
|
27
|
-
if
|
28
|
-
@
|
28
|
+
get_path(url)
|
29
|
+
if File.exist?(@paths_hash[:original])
|
30
|
+
@paths_hash[:fresh] = @paths_hash[:original].dup.insert(-5, '_fresh')
|
31
|
+
@shot_path = @paths_hash[:fresh]
|
29
32
|
else
|
30
|
-
@
|
31
|
-
@path = "#{@dir}/#{@filename}.png"
|
33
|
+
@shot_path = @paths_hash[:original]
|
32
34
|
end
|
33
|
-
|
34
|
-
|
35
|
-
end
|
35
|
+
return @shot_path
|
36
|
+
end
|
36
37
|
|
37
|
-
def
|
38
|
-
|
39
|
-
|
38
|
+
def get_path(url)
|
39
|
+
@filename = url.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/)[5]
|
40
|
+
if @filename.empty? || @filename == '/'
|
41
|
+
@paths_hash[:original] = "#{@dir}/root.png"
|
40
42
|
else
|
41
|
-
|
43
|
+
@filename = @filename.gsub(/[\/]/, '')
|
44
|
+
@paths_hash[:original] = "#{@dir}/#{@filename}.png"
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
45
48
|
def destroy(url)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
if File.exist?(@path)
|
53
|
-
FileUtils.rm(@path)
|
49
|
+
get_path(url)
|
50
|
+
if File.exist?( @paths_hash[:original] )
|
51
|
+
FileUtils.rm( @paths_hash[:original] )
|
52
|
+
if File.exist?( @paths_hash[:fresh] )
|
53
|
+
FileUtils.rm( @paths_hash[:fresh] )
|
54
|
+
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
data/lib/green_onion/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/unit/compare_spec.rb
CHANGED
@@ -8,6 +8,11 @@ describe GreenOnion::Compare do
|
|
8
8
|
@comparison = GreenOnion::Compare.new
|
9
9
|
@spec_shot1 = './spec/skins/spec_shot.png'
|
10
10
|
@spec_shot2 = './spec/skins/spec_shot_fresh.png'
|
11
|
+
@diff_shot = './spec/skins/spec_shot_diff.png'
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:all) do
|
15
|
+
FileUtils.rm('./spec/skins/spec_shot_diff.png', :force => true)
|
11
16
|
end
|
12
17
|
|
13
18
|
it 'should get a percentage of difference between two shots' do
|
@@ -17,6 +22,7 @@ describe GreenOnion::Compare do
|
|
17
22
|
|
18
23
|
it 'should create a new file with a visual diff between two shots' do
|
19
24
|
@comparison.visual_diff(@spec_shot1, @spec_shot2)
|
25
|
+
File.exist?(@diff_shot).should be_true
|
20
26
|
end
|
21
27
|
end
|
22
28
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GreenOnion do
|
4
|
+
|
5
|
+
describe "Skins" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@tmp_path = './spec/tmp'
|
9
|
+
FileUtils.mkdir(@tmp_path)
|
10
|
+
|
11
|
+
GreenOnion.configure do |c|
|
12
|
+
c.skins_dir = @tmp_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
after(:each) do
|
17
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set/get custom directory" do
|
21
|
+
GreenOnion.configuration.skins_dir.should eq(@tmp_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should get the correct paths_hash" do
|
25
|
+
2.times do
|
26
|
+
GreenOnion.skin('http://www.google.com')
|
27
|
+
end
|
28
|
+
( (GreenOnion.screenshot.paths_hash[:original] == "#{@tmp_path}/root.png") &&
|
29
|
+
(GreenOnion.screenshot.paths_hash[:fresh] == "#{@tmp_path}/root_fresh.png") ).should be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should measure the percentage of diff between skins" do
|
33
|
+
2.times do
|
34
|
+
GreenOnion.skin_percentage('http://www.google.com')
|
35
|
+
end
|
36
|
+
GreenOnion.compare.percentage_changed.should be <(1)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should create visual diff between skins"
|
40
|
+
|
41
|
+
it "should create visual diff between skins (even when there is no change)" do
|
42
|
+
2.times do
|
43
|
+
GreenOnion.skin_visual('http://www.google.com')
|
44
|
+
end
|
45
|
+
GreenOnion.compare.diffed_image.should eq('./spec/tmp/root_diff.png')
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -27,6 +27,10 @@ describe GreenOnion::Screenshot do
|
|
27
27
|
@screenshot.url_to_path('http://www.google.com').should eq("#{@tmp_path}/root.png")
|
28
28
|
end
|
29
29
|
|
30
|
+
it 'should build the path from root (even with trailing slash)' do
|
31
|
+
@screenshot.url_to_path('http://www.google.com/').should eq("#{@tmp_path}/root.png")
|
32
|
+
end
|
33
|
+
|
30
34
|
it 'should snap and save screenshot' do
|
31
35
|
@screenshot.snap_screenshot(@url, @file)
|
32
36
|
File.exist?(@file).should be_true
|
@@ -59,6 +63,10 @@ describe GreenOnion::Screenshot do
|
|
59
63
|
FileUtils.rm_r(@tmp_path, :force => true)
|
60
64
|
end
|
61
65
|
|
66
|
+
it "should create the paths_hash correctly" do
|
67
|
+
( (@screenshot.paths_hash[:original].should eq(@file1)) && (@screenshot.paths_hash[:fresh].should eq(@file2)) ).should be_true
|
68
|
+
end
|
69
|
+
|
62
70
|
it "should snap and save another screenshot if a screenshot already exists" do
|
63
71
|
if File.exist?(@file1)
|
64
72
|
File.exist?(@file2).should be_true
|
@@ -67,7 +75,7 @@ describe GreenOnion::Screenshot do
|
|
67
75
|
|
68
76
|
it "should destroy a set of screenshots" do
|
69
77
|
@screenshot.destroy(@url)
|
70
|
-
File.exist?(@file1).should be_false
|
78
|
+
( File.exist?(@file1) && File.exist?(@file2) ).should be_false
|
71
79
|
end
|
72
80
|
end
|
73
81
|
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.2
|
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-26 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
type: :development
|
58
58
|
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
|
-
name:
|
60
|
+
name: debugger
|
61
61
|
prerelease: false
|
62
62
|
requirement: &id005 !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
- - ">="
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: "0"
|
68
|
-
type: :
|
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
|
@@ -78,6 +78,17 @@ dependencies:
|
|
78
78
|
version: "0"
|
79
79
|
type: :runtime
|
80
80
|
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: oily_png
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :runtime
|
91
|
+
version_requirements: *id007
|
81
92
|
description: UI testing/screenshot diffing tool
|
82
93
|
email:
|
83
94
|
- ted@intridea.com
|
@@ -91,6 +102,7 @@ files:
|
|
91
102
|
- .gitignore
|
92
103
|
- .rspec
|
93
104
|
- .rvmrc
|
105
|
+
- .travis.yml
|
94
106
|
- Gemfile
|
95
107
|
- LICENSE
|
96
108
|
- README.md
|
@@ -98,12 +110,14 @@ files:
|
|
98
110
|
- green_onion.gemspec
|
99
111
|
- lib/green_onion.rb
|
100
112
|
- lib/green_onion/compare.rb
|
113
|
+
- lib/green_onion/configuration.rb
|
101
114
|
- lib/green_onion/screenshot.rb
|
102
115
|
- lib/green_onion/version.rb
|
103
116
|
- spec/skins/spec_shot.png
|
104
117
|
- spec/skins/spec_shot_fresh.png
|
105
118
|
- spec/spec_helper.rb
|
106
119
|
- spec/unit/compare_spec.rb
|
120
|
+
- spec/unit/green_onion_spec.rb
|
107
121
|
- spec/unit/screenshot_spec.rb
|
108
122
|
homepage: ""
|
109
123
|
licenses: []
|
@@ -137,4 +151,5 @@ test_files:
|
|
137
151
|
- spec/skins/spec_shot_fresh.png
|
138
152
|
- spec/spec_helper.rb
|
139
153
|
- spec/unit/compare_spec.rb
|
154
|
+
- spec/unit/green_onion_spec.rb
|
140
155
|
- spec/unit/screenshot_spec.rb
|