green_onion 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  # GreenOnion
5
5
 
6
- Regression issues make you cry.
6
+ Regression issues in the view make you cry.
7
7
 
8
8
  GreenOnion is a testing library for the UI only. It alerts you when the appearance of a view has changed, let's you know the percentage of total change, and allows you to visualize the areas that have been changed. It fits right into your test suite, and is dependent on familiar tools like Capybara.
9
9
 
@@ -25,9 +25,34 @@ Or install it yourself as:
25
25
 
26
26
  ## Usage
27
27
 
28
- ### RSpec
28
+ ### Command Line Interface
29
29
 
30
- For RSpec, `require 'green_onion'` in your spec_helper.rb file. Place this block in the file also:
30
+ #### Skinning
31
+
32
+ To just run a comparison between skins in your shell, you can use the command below:
33
+
34
+ green_onion skin <url> [options]
35
+
36
+ Options
37
+ * `<url>` - is the screen you want tested. Must include http://, example - 'http://yourSite.com'
38
+ * `--dir=DIR` - 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'
39
+ * `--method=[p, v, vp]` - the method in which you'd like to compare the skins. `p` is for percentage, `v` is for visual. The default is visual and percentage.
40
+ * `--threshold=[1-100]` is the percentage of acceptable change that the screenshots can take. This number can always be overwritten for an instance.
41
+ * `--width=[number]` is the width of the browser window. The default width is 1024.
42
+ * `--height=[number]` is the height of the browser window. The default height is 768.
43
+
44
+ #### Generating skinner file
45
+
46
+ To generate a "skinner" file, which will test a Rails application with the routes without params included (this is an area that could be worked on a lot more :) ); use the command below:
47
+
48
+ green_onion generate [options]
49
+
50
+ * `--url=URL` - the domain that you will be testing your Rails app. The default is "http://localhost:3000".
51
+ * `--dir=DIR` - the directory in which you would like to generate the skinner. The default is "spec/skinner.rb"
52
+
53
+ ### Adding GreenOnion to integration tests with RSpec
54
+
55
+ For adding GreenOnion to your integration tests in RSpec, add `require 'green_onion'` to your spec_helper.rb file. Place this block in the file also:
31
56
 
32
57
  GreenOnion.configure do |c|
33
58
  c.skins_dir = 'your/path/to/skins'
@@ -41,22 +66,22 @@ For RSpec, `require 'green_onion'` in your spec_helper.rb file. Place this block
41
66
 
42
67
  Then use one of the three methods below in a test...
43
68
 
44
- ### Percentage of change
69
+ #### Percentage of change
45
70
 
46
- GreenOnion.skin_percentage(url, threshold {optional})
71
+ GreenOnion.skin_percentage(url, threshold [optional])
47
72
  The primary feature of GreenOnion is seeing how much (if at all) a view has changed from one instance to the next, and being alerted when a view has surpassed into an unacceptable threshold.
48
73
 
49
74
  * `url` is the screen you want tested. Must include http://, example - 'http://yourSite.com'
50
75
  * `threshold` can be overwritten here, or if not given in the configure block – it will default to a threshold of 100%
51
76
 
52
- ### Viewing screenshot diffs
77
+ #### Viewing screenshot diffs
53
78
 
54
79
  GreenOnion.skin_visual(url)
55
80
  Once you are aware of a issue in the UI, you can also rip open your spec/skins directory and manually see what the differences are from one screenshot to the next.
56
81
 
57
82
  * `url` is the screen you want tested. Must include http://, example - 'http://yourSite.com'
58
83
 
59
- ### Both viewing screenshot diffs and percentage of change
84
+ #### Both viewing screenshot diffs and percentage of change
60
85
 
61
86
  GreenOnion.skin_visual_and_percentage(url, threshold {optional})
62
87
  This is just a combination of the two methods above.
@@ -75,7 +100,7 @@ The best way to run the specs is with...
75
100
 
76
101
  * Screenshots can either be viewed as a visual diff, or overlayed newest over oldest and viewed as an onion-skin with sliding transparency.
77
102
  * Allow for flexibility in picking browsers
78
- * Run through all paths in a Rails app
103
+ * Skinner generator needs love <3
79
104
  * More robust tests, especially around the visual diffs themselves
80
105
  * More documentation
81
106
  * More configuration/customizable settings
@@ -90,5 +115,5 @@ This is the post that got the wheels in motion: http://jeffkreeftmeijer.com/2011
90
115
  ### Compatriot
91
116
  Carol Nichols saw the same post, and worked on an excellent gem for cross-browser testing. That gem greatly influenced design decisions with GreenOnion.
92
117
 
93
- ### Capybara and ChunkyPNG
118
+ ### Capybara, ChunkyPNG, Thor, and OilyPNG
94
119
  The land on which we sow our bulbs.
data/bin/green_onion ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require "green_onion/cli"
3
+
4
+ GreenOnion::CLI.start
data/green_onion.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency "oily_png", "1.0.2"
20
20
  gem.add_dependency "rainbow", "1.1.4"
21
21
  gem.add_dependency "fileutils", "0.7"
22
+ gem.add_dependency "thor", "0.15.4"
22
23
 
23
24
  gem.files = `git ls-files`.split($\)
24
25
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
data/lib/green_onion.rb CHANGED
@@ -69,9 +69,9 @@ module GreenOnion
69
69
  # This is used in skin_percentage to better alert if a set of skins are ok or not
70
70
  def threshold_alert(actual, threshold)
71
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}"
72
+ $stderr.puts "#{actual - threshold}% above threshold set @ #{threshold}%".color(:red)
73
+ $stderr.puts "pixels changed (%): #{@compare.percentage_changed}%"
74
+ $stderr.puts "pixels changed/total: #{@compare.changed_px}/#{@compare.total_px}"
75
75
  else
76
76
  puts "pixels changed/total: #{@compare.changed_px}/#{@compare.total_px}"
77
77
  end
@@ -0,0 +1,41 @@
1
+ require "thor"
2
+ require "green_onion"
3
+
4
+ module GreenOnion
5
+ class CLI < Thor
6
+ include Thor::Actions
7
+
8
+ self.source_root("lib/green_onion/generators")
9
+
10
+ class_option :dir, :aliases => "-d", :type => :string
11
+
12
+ desc "skin <url>", "Creates skins from <url> and compares them"
13
+ method_option :method, :aliases => "-m", :type => :string
14
+ method_option :threshold, :aliases => "-t", :type => :numeric
15
+ method_option :width, :aliases => "-w", :type => :numeric
16
+ method_option :height, :aliases => "-h", :type => :numeric
17
+ def skin(url)
18
+ GreenOnion.configure do |c|
19
+ c.skins_dir = options[:dir] if options[:dir]
20
+ c.threshold = options[:threshold] if options[:threshold]
21
+ c.dimensions = { :width => options[:width], :height => options[:height] } if options[:width] && options[:height]
22
+ end
23
+ case options[:method]
24
+ when "v"
25
+ GreenOnion.skin_visual(url)
26
+ when "p"
27
+ GreenOnion.skin_percentage(url)
28
+ else
29
+ GreenOnion.skin_visual_and_percentage(url)
30
+ end
31
+ end
32
+
33
+ desc "generate", "Generates a 'skinner' file to test a Rails app at <url> with routes without params"
34
+ method_option :url, :aliases => "-u", :type => :string
35
+ def generate_skinner
36
+ options[:dir] ? dir = options[:dir] : dir = "spec"
37
+ options[:url] ? url = options[:url] : url = "http://localhost:3000"
38
+ template('skinner.erb', "#{dir}/skinner.rb")
39
+ end
40
+ end
41
+ end
@@ -16,7 +16,14 @@ module GreenOnion
16
16
  ]
17
17
 
18
18
  @diff_index = []
19
+ begin
20
+ diff_iterator
21
+ rescue ChunkyPNG::OutOfBounds
22
+ puts "Skins are different sizes. Please delete #{org} and/or #{fresh}.".color(:yellow)
23
+ end
24
+ end
19
25
 
26
+ def diff_iterator
20
27
  @images.first.height.times do |y|
21
28
  @images.first.row(y).each_with_index do |pixel, x|
22
29
  unless pixel == @images.last[x,y]
@@ -4,7 +4,7 @@ module GreenOnion
4
4
  attr_writer :threshold, :skins_dir
5
5
 
6
6
  def dimensions=(options)
7
- @dimensions = { :width => options[:width], :height => options[:height] }
7
+ @dimensions = options
8
8
  end
9
9
 
10
10
  def dimensions
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'green_onion'
5
+
6
+ ENV["RAILS_ENV"] ||= 'test'
7
+ require File.expand_path("../../config/environment", __FILE__)
8
+
9
+ GreenOnion.configure do |c|
10
+ # You can use and customize these configuration options
11
+ # c.skins_dir = "#{::Rails.root}/spec/skins"
12
+ # c.threshold = 100
13
+ # c.dimensions = { :width => 1024, :height => 768 }
14
+ end
15
+
16
+ all_routes = Rails.application.routes.routes
17
+ routes = all_routes.collect { |r| r.path.spec.to_s.gsub(/\/*(\(\.)*:(\w*)(\))*\/*/, "") }.delete_if(&:empty?)
18
+
19
+ routes.each do |route|
20
+ GreenOnion.skin_percentage(url + route)
21
+ end
@@ -48,10 +48,14 @@ module GreenOnion
48
48
 
49
49
  def destroy(url)
50
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] )
51
+ destroy_files(@paths_hash[:original], @paths_hash[:fresh])
52
+ end
53
+
54
+ def destroy_files(org, fresh)
55
+ if File.exist?(org)
56
+ FileUtils.rm(org)
57
+ if File.exist?(fresh)
58
+ FileUtils.rm(fresh)
55
59
  end
56
60
  end
57
61
  end
@@ -1,3 +1,3 @@
1
1
  module GreenOnion
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
Binary file
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe "bin/green_onion" do
4
+
5
+ before(:all) do
6
+ @tmp_path = './spec/tmp'
7
+ @url = 'http://localhost:8070'
8
+ @file1 = "#{@tmp_path}/root.png"
9
+ @skinner_file = "#{@tmp_path}/skinner.rb"
10
+ end
11
+
12
+ describe "Skin Utility" do
13
+
14
+ before(:each) do
15
+ FileUtils.mkdir(@tmp_path)
16
+ end
17
+
18
+ after(:each) do
19
+ FileUtils.rm_r(@tmp_path, :force => true)
20
+ end
21
+
22
+ it "should run the skin task w/o any flags (need the --dir flag to keep spec directory clean)" do
23
+ `bin/green_onion skin #{@url} -d=#{@tmp_path}`
24
+ File.exist?(@file1).should be_true
25
+ end
26
+
27
+ end
28
+
29
+ describe "Generator" do
30
+
31
+ before(:each) do
32
+ FileUtils.mkdir(@tmp_path)
33
+ end
34
+
35
+ after(:each) do
36
+ FileUtils.rm_r(@tmp_path, :force => true)
37
+ end
38
+
39
+ it "should build the skinner file" do
40
+ `bin/green_onion generate --url=#{@url} --dir=#{@tmp_path}`
41
+ File.exist?(@skinner_file).should be_true
42
+ end
43
+
44
+ end
45
+ end
@@ -8,6 +8,7 @@ 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
+ @spec_shot_resize = './spec/skins/spec_shot_resize.png'
11
12
  @diff_shot = './spec/skins/spec_shot_diff.png'
12
13
  end
13
14
 
@@ -24,5 +25,10 @@ describe GreenOnion::Compare do
24
25
  @comparison.visual_diff(@spec_shot1, @spec_shot2)
25
26
  File.exist?(@diff_shot).should be_true
26
27
  end
28
+
29
+ it "should not throw error when dimensions are off" do
30
+ expect { @comparison.visual_diff(@spec_shot1, @spec_shot_resize) }.to_not raise_error
31
+ end
32
+
27
33
  end
28
34
  end
@@ -117,7 +117,7 @@ describe GreenOnion do
117
117
  end
118
118
 
119
119
  it "should alert when diff percentage threshold is surpassed" do
120
- $stdout.should_receive(:puts).exactly(5).times
120
+ $stderr.should_receive(:puts).exactly(3).times
121
121
  2.times do
122
122
  GreenOnion.skin_percentage(@url)
123
123
  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
5
+ version: 0.1.0
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-31 00:00:00 Z
13
+ date: 2012-08-02 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -122,11 +122,22 @@ dependencies:
122
122
  version: "0.7"
123
123
  type: :runtime
124
124
  version_requirements: *id010
125
+ - !ruby/object:Gem::Dependency
126
+ name: thor
127
+ prerelease: false
128
+ requirement: &id011 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - "="
132
+ - !ruby/object:Gem::Version
133
+ version: 0.15.4
134
+ type: :runtime
135
+ version_requirements: *id011
125
136
  description: UI testing/screenshot diffing tool
126
137
  email:
127
138
  - ted@intridea.com
128
- executables: []
129
-
139
+ executables:
140
+ - green_onion
130
141
  extensions: []
131
142
 
132
143
  extra_rdoc_files: []
@@ -140,16 +151,21 @@ files:
140
151
  - LICENSE
141
152
  - README.md
142
153
  - Rakefile
154
+ - bin/green_onion
143
155
  - green_onion.gemspec
144
156
  - lib/green_onion.rb
157
+ - lib/green_onion/cli.rb
145
158
  - lib/green_onion/compare.rb
146
159
  - lib/green_onion/configuration.rb
160
+ - lib/green_onion/generators/skinner.erb
147
161
  - lib/green_onion/screenshot.rb
148
162
  - lib/green_onion/version.rb
149
163
  - spec/sample_app/sample_app.rb
150
164
  - spec/skins/spec_shot.png
151
165
  - spec/skins/spec_shot_fresh.png
166
+ - spec/skins/spec_shot_resize.png
152
167
  - spec/spec_helper.rb
168
+ - spec/unit/cli_spec.rb
153
169
  - spec/unit/compare_spec.rb
154
170
  - spec/unit/green_onion_spec.rb
155
171
  - spec/unit/screenshot_spec.rb
@@ -184,7 +200,9 @@ test_files:
184
200
  - spec/sample_app/sample_app.rb
185
201
  - spec/skins/spec_shot.png
186
202
  - spec/skins/spec_shot_fresh.png
203
+ - spec/skins/spec_shot_resize.png
187
204
  - spec/spec_helper.rb
205
+ - spec/unit/cli_spec.rb
188
206
  - spec/unit/compare_spec.rb
189
207
  - spec/unit/green_onion_spec.rb
190
208
  - spec/unit/screenshot_spec.rb