green_onion 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +18 -4
- data/green_onion.gemspec +1 -3
- data/lib/green_onion.rb +2 -1
- data/lib/green_onion/configuration.rb +17 -0
- data/lib/green_onion/screenshot.rb +11 -4
- data/lib/green_onion/version.rb +1 -1
- data/spec/sample_app/sample_app.rb +4 -0
- data/spec/unit/green_onion_spec.rb +36 -0
- data/spec/unit/screenshot_spec.rb +64 -2
- metadata +16 -38
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
[<img src="https://secure.travis-ci.org/
|
2
|
+
[<img src="https://secure.travis-ci.org/intridea/green_onion.png" />](http://travis-ci.org/#!/intridea/green_onion) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/intridea/green_onion)
|
3
3
|
|
4
4
|
# GreenOnion
|
5
5
|
|
@@ -60,13 +60,27 @@ For adding GreenOnion to your integration tests in RSpec, add `require 'green_on
|
|
60
60
|
|
61
61
|
GreenOnion.configure do |c|
|
62
62
|
c.skins_dir = 'your/path/to/skins'
|
63
|
+
c.skin_name = {
|
64
|
+
:match => /[\/]/,
|
65
|
+
:replace => "_",
|
66
|
+
:prefix => nil,
|
67
|
+
:root => "root"
|
68
|
+
}
|
69
|
+
c.dimensions = {
|
70
|
+
:width => 1440,
|
71
|
+
:height => 768
|
72
|
+
}
|
63
73
|
c.threshold = 20
|
64
|
-
c.dimensions = { :width => 1440, :height => 768 }
|
65
74
|
end
|
66
75
|
|
67
76
|
* `skins_dir` is the directory that GreenOnion will store all skins. The namespace for skins is {URI name}.png (original), {URI name}_fresh.png (testing), and {URI name}_diff.png. The default directory will be './spec/skins'
|
68
|
-
* `
|
77
|
+
* `skin_name` is a hash that defines the skin namespace. The options include:
|
78
|
+
* `:match` - a regex pattern that will replace characters from the URI. The default pattern will match to all "/" in a URI.
|
79
|
+
* `:replace` - the string that replaces what is matched. These options are just abstractions of String.gsub in GreenOnion::Screenshot.
|
80
|
+
* `:prefix` - a value that will be concatenated to the front of the filename. A good example would be if you wanted to add a timestamp: `:prefix => Time.now.strftime("%m_%Y_")`.
|
81
|
+
* `:root` - the string that will be used to name the root of a domain.
|
69
82
|
* `dimensions` is a hash with the height and width of the browser window. The default dimensions are 1024x768.
|
83
|
+
* `threshold` is the percentage of acceptable change that the screenshots can take. This number can always be overwritten for an instance.
|
70
84
|
|
71
85
|
Then use one of the three methods below in a test...
|
72
86
|
|
@@ -105,7 +119,7 @@ The best way to run the specs is with...
|
|
105
119
|
* Screenshots can either be viewed as a visual diff, or overlayed newest over oldest and viewed as an onion-skin with sliding transparency.
|
106
120
|
* Allow for flexibility in picking browsers
|
107
121
|
* Skinner generator needs love <3
|
108
|
-
|
122
|
+
* Should allow for testing using fixtures/factories
|
109
123
|
* More robust tests, especially around the visual diffs themselves
|
110
124
|
* More documentation
|
111
125
|
* More configuration/customizable settings
|
data/green_onion.gemspec
CHANGED
@@ -6,12 +6,10 @@ Gem::Specification.new do |gem|
|
|
6
6
|
gem.email = ["ted@intridea.com"]
|
7
7
|
gem.description = %q{UI testing/screenshot diffing tool}
|
8
8
|
gem.summary = %q{Regressions in the view making you cry? Have more confidence with GreenOnion.}
|
9
|
-
gem.homepage = ""
|
9
|
+
gem.homepage = "http://intridea.github.com/green_onion"
|
10
10
|
|
11
11
|
gem.add_development_dependency "rake"
|
12
12
|
gem.add_development_dependency "rspec"
|
13
|
-
gem.add_development_dependency "pry"
|
14
|
-
gem.add_development_dependency "debugger"
|
15
13
|
gem.add_development_dependency "sinatra"
|
16
14
|
|
17
15
|
gem.add_dependency "capybara", "1.1.2"
|
data/lib/green_onion.rb
CHANGED
@@ -23,7 +23,8 @@ module GreenOnion
|
|
23
23
|
def skin(url)
|
24
24
|
@screenshot = Screenshot.new(
|
25
25
|
:dir => @configuration.skins_dir,
|
26
|
-
:dimensions => @configuration.dimensions
|
26
|
+
:dimensions => @configuration.dimensions,
|
27
|
+
:skin_name => @configuration.skin_name
|
27
28
|
)
|
28
29
|
@compare = GreenOnion::Compare.new
|
29
30
|
|
@@ -19,5 +19,22 @@ module GreenOnion
|
|
19
19
|
@skins_dir ||= './spec/skins'
|
20
20
|
end
|
21
21
|
|
22
|
+
def skin_name=(options)
|
23
|
+
@skin_name = skin_namespace_hash(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def skin_name
|
27
|
+
@skin_name ||= skin_namespace_hash
|
28
|
+
end
|
29
|
+
|
30
|
+
def skin_namespace_hash(options = {})
|
31
|
+
{
|
32
|
+
:match => options[:match] ? options[:match] : /[\/]/,
|
33
|
+
:replace => options[:replace] ? options[:replace] : "_",
|
34
|
+
:prefix => options[:prefix] ? options[:prefix] : nil,
|
35
|
+
:root => options[:root] ? options[:root] : "root"
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
22
39
|
end
|
23
40
|
end
|
@@ -6,13 +6,14 @@ module GreenOnion
|
|
6
6
|
class Screenshot
|
7
7
|
include Capybara::DSL
|
8
8
|
|
9
|
-
attr_accessor :dir, :dimensions
|
9
|
+
attr_accessor :dir, :dimensions, :skin_name
|
10
10
|
attr_reader :paths_hash
|
11
11
|
|
12
12
|
def initialize(params = {})
|
13
13
|
Capybara.default_driver = :webkit
|
14
14
|
@dimensions = params[:dimensions]
|
15
15
|
@dir = params[:dir]
|
16
|
+
@skin_name = params[:skin_name]
|
16
17
|
@paths_hash = {}
|
17
18
|
end
|
18
19
|
|
@@ -45,13 +46,19 @@ module GreenOnion
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
def file_namer
|
50
|
+
@filename.slice!(/^\//) # remove the beginning "/" if there is one
|
51
|
+
@filename = @filename.gsub(@skin_name[:match], @skin_name[:replace]) # by default, all "/" in a URI string will be replaced with "_"
|
52
|
+
@filename = @skin_name[:prefix] + @filename if @skin_name[:prefix] # add on a prefix defined in the configuration block
|
53
|
+
@paths_hash[:original] = "#{@dir}/#{@filename}.png"
|
54
|
+
end
|
55
|
+
|
48
56
|
def get_path(url)
|
49
57
|
url_matcher(url)
|
50
58
|
if @filename.empty? || @filename == '/'
|
51
|
-
@paths_hash[:original] = "#{@dir}
|
59
|
+
@paths_hash[:original] = "#{@dir}/#{@skin_name[:root]}.png"
|
52
60
|
else
|
53
|
-
|
54
|
-
@paths_hash[:original] = "#{@dir}/#{@filename}.png"
|
61
|
+
file_namer
|
55
62
|
end
|
56
63
|
end
|
57
64
|
|
data/lib/green_onion/version.rb
CHANGED
@@ -118,6 +118,42 @@ describe GreenOnion do
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
describe "Skins with custom file namespace" do
|
122
|
+
|
123
|
+
after(:each) do
|
124
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should allow custom file namespacing" do
|
128
|
+
GreenOnion.configure do |c|
|
129
|
+
c.skins_dir = @tmp_path
|
130
|
+
c.skin_name = {
|
131
|
+
:match => /[\/a-z]/,
|
132
|
+
:replace => "-",
|
133
|
+
:prefix => "start",
|
134
|
+
:root => "first"
|
135
|
+
}
|
136
|
+
end
|
137
|
+
( (GreenOnion.configuration.skin_name[:match] == /[\/a-z]/) &&
|
138
|
+
(GreenOnion.configuration.skin_name[:replace] == "-") &&
|
139
|
+
(GreenOnion.configuration.skin_name[:prefix] == "start") &&
|
140
|
+
(GreenOnion.configuration.skin_name[:root] == "first") ).should be_true
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should allow incomplete setting of skin_name hash" do
|
144
|
+
GreenOnion.configure do |c|
|
145
|
+
c.skins_dir = @tmp_path
|
146
|
+
c.skin_name = {
|
147
|
+
:replace => "o"
|
148
|
+
}
|
149
|
+
end
|
150
|
+
( (GreenOnion.configuration.skin_name[:match] == /[\/]/) &&
|
151
|
+
(GreenOnion.configuration.skin_name[:replace] == "o") &&
|
152
|
+
(GreenOnion.configuration.skin_name[:prefix] == nil) &&
|
153
|
+
(GreenOnion.configuration.skin_name[:root] == "root") ).should be_true
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
121
157
|
describe "Errors" do
|
122
158
|
before(:each) do
|
123
159
|
GreenOnion.configure do |c|
|
@@ -14,7 +14,13 @@ describe GreenOnion::Screenshot do
|
|
14
14
|
before(:each) do
|
15
15
|
@screenshot = GreenOnion::Screenshot.new(
|
16
16
|
:dir => @tmp_path,
|
17
|
-
:dimensions => @dimensions
|
17
|
+
:dimensions => @dimensions,
|
18
|
+
:skin_name => {
|
19
|
+
:match => /[\/]/,
|
20
|
+
:replace => "",
|
21
|
+
:prefix => nil,
|
22
|
+
:root => "root"
|
23
|
+
}
|
18
24
|
)
|
19
25
|
@file = "#{@tmp_path}/fake_uri.png"
|
20
26
|
end
|
@@ -51,7 +57,13 @@ describe GreenOnion::Screenshot do
|
|
51
57
|
before(:each) do
|
52
58
|
@screenshot = GreenOnion::Screenshot.new(
|
53
59
|
:dir => @tmp_path,
|
54
|
-
:dimensions => @dimensions
|
60
|
+
:dimensions => @dimensions,
|
61
|
+
:skin_name => {
|
62
|
+
:match => /[\/]/,
|
63
|
+
:replace => "",
|
64
|
+
:prefix => nil,
|
65
|
+
:root => "root"
|
66
|
+
}
|
55
67
|
)
|
56
68
|
@file1 = "#{@tmp_path}/fake_uri.png"
|
57
69
|
@file2 = "#{@tmp_path}/fake_uri_fresh.png"
|
@@ -79,4 +91,54 @@ describe GreenOnion::Screenshot do
|
|
79
91
|
( File.exist?(@file1) && File.exist?(@file2) ).should be_false
|
80
92
|
end
|
81
93
|
end
|
94
|
+
|
95
|
+
describe "Custom filenaming" do
|
96
|
+
|
97
|
+
after(:each) do
|
98
|
+
FileUtils.rm_r(@tmp_path, :force => true)
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should allow users to create a naming convention" do
|
102
|
+
@screenshot = GreenOnion::Screenshot.new(
|
103
|
+
:dir => @tmp_path,
|
104
|
+
:skin_name => {
|
105
|
+
:match => /[\/]/,
|
106
|
+
:replace => "#",
|
107
|
+
:prefix => nil,
|
108
|
+
:root => "root"
|
109
|
+
}
|
110
|
+
)
|
111
|
+
@screenshot.get_path("#{@url}/another/uri/string")
|
112
|
+
@screenshot.paths_hash[:original].should eq("#{@tmp_path}/another#uri#string.png")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should allow filenames to have a timestamp" do
|
116
|
+
this_month = Time.now.strftime("%m_%Y_")
|
117
|
+
@screenshot = GreenOnion::Screenshot.new(
|
118
|
+
:dir => @tmp_path,
|
119
|
+
:skin_name => {
|
120
|
+
:match => /[\/]/,
|
121
|
+
:replace => "-",
|
122
|
+
:prefix => this_month,
|
123
|
+
:root => "root"
|
124
|
+
}
|
125
|
+
)
|
126
|
+
@screenshot.get_path("#{@url}/another/uri/string")
|
127
|
+
@screenshot.paths_hash[:original].should eq("#{@tmp_path}/#{this_month}another-uri-string.png")
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should allow renaming for root skins" do
|
131
|
+
@screenshot = GreenOnion::Screenshot.new(
|
132
|
+
:dir => @tmp_path,
|
133
|
+
:skin_name => {
|
134
|
+
:match => /[\/]/,
|
135
|
+
:replace => "-",
|
136
|
+
:prefix => nil,
|
137
|
+
:root => "first"
|
138
|
+
}
|
139
|
+
)
|
140
|
+
@screenshot.get_path(@url)
|
141
|
+
@screenshot.paths_hash[:original].should eq("#{@tmp_path}/first.png")
|
142
|
+
end
|
143
|
+
end
|
82
144
|
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.1.
|
5
|
+
version: 0.1.3
|
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-08-
|
13
|
+
date: 2012-08-08 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: sinatra
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id003 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -45,94 +45,72 @@ dependencies:
|
|
45
45
|
version: "0"
|
46
46
|
type: :development
|
47
47
|
version_requirements: *id003
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: debugger
|
50
|
-
prerelease: false
|
51
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
|
-
requirements:
|
54
|
-
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
version: "0"
|
57
|
-
type: :development
|
58
|
-
version_requirements: *id004
|
59
|
-
- !ruby/object:Gem::Dependency
|
60
|
-
name: sinatra
|
61
|
-
prerelease: false
|
62
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
-
none: false
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: "0"
|
68
|
-
type: :development
|
69
|
-
version_requirements: *id005
|
70
48
|
- !ruby/object:Gem::Dependency
|
71
49
|
name: capybara
|
72
50
|
prerelease: false
|
73
|
-
requirement: &
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
52
|
none: false
|
75
53
|
requirements:
|
76
54
|
- - "="
|
77
55
|
- !ruby/object:Gem::Version
|
78
56
|
version: 1.1.2
|
79
57
|
type: :runtime
|
80
|
-
version_requirements: *
|
58
|
+
version_requirements: *id004
|
81
59
|
- !ruby/object:Gem::Dependency
|
82
60
|
name: capybara-webkit
|
83
61
|
prerelease: false
|
84
|
-
requirement: &
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
63
|
none: false
|
86
64
|
requirements:
|
87
65
|
- - "="
|
88
66
|
- !ruby/object:Gem::Version
|
89
67
|
version: 0.12.1
|
90
68
|
type: :runtime
|
91
|
-
version_requirements: *
|
69
|
+
version_requirements: *id005
|
92
70
|
- !ruby/object:Gem::Dependency
|
93
71
|
name: oily_png
|
94
72
|
prerelease: false
|
95
|
-
requirement: &
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
74
|
none: false
|
97
75
|
requirements:
|
98
76
|
- - "="
|
99
77
|
- !ruby/object:Gem::Version
|
100
78
|
version: 1.0.2
|
101
79
|
type: :runtime
|
102
|
-
version_requirements: *
|
80
|
+
version_requirements: *id006
|
103
81
|
- !ruby/object:Gem::Dependency
|
104
82
|
name: rainbow
|
105
83
|
prerelease: false
|
106
|
-
requirement: &
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
107
85
|
none: false
|
108
86
|
requirements:
|
109
87
|
- - "="
|
110
88
|
- !ruby/object:Gem::Version
|
111
89
|
version: 1.1.4
|
112
90
|
type: :runtime
|
113
|
-
version_requirements: *
|
91
|
+
version_requirements: *id007
|
114
92
|
- !ruby/object:Gem::Dependency
|
115
93
|
name: fileutils
|
116
94
|
prerelease: false
|
117
|
-
requirement: &
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
118
96
|
none: false
|
119
97
|
requirements:
|
120
98
|
- - "="
|
121
99
|
- !ruby/object:Gem::Version
|
122
100
|
version: "0.7"
|
123
101
|
type: :runtime
|
124
|
-
version_requirements: *
|
102
|
+
version_requirements: *id008
|
125
103
|
- !ruby/object:Gem::Dependency
|
126
104
|
name: thor
|
127
105
|
prerelease: false
|
128
|
-
requirement: &
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
129
107
|
none: false
|
130
108
|
requirements:
|
131
109
|
- - "="
|
132
110
|
- !ruby/object:Gem::Version
|
133
111
|
version: 0.15.4
|
134
112
|
type: :runtime
|
135
|
-
version_requirements: *
|
113
|
+
version_requirements: *id009
|
136
114
|
description: UI testing/screenshot diffing tool
|
137
115
|
email:
|
138
116
|
- ted@intridea.com
|
@@ -170,7 +148,7 @@ files:
|
|
170
148
|
- spec/unit/compare_spec.rb
|
171
149
|
- spec/unit/green_onion_spec.rb
|
172
150
|
- spec/unit/screenshot_spec.rb
|
173
|
-
homepage:
|
151
|
+
homepage: http://intridea.github.com/green_onion
|
174
152
|
licenses: []
|
175
153
|
|
176
154
|
post_install_message:
|