green_onion 0.0.3 → 0.0.4

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/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
+ before_install:
5
+ - sudo apt-get install libqt4-dev libqtwebkit-dev
4
6
  before_script:
5
7
  - "export DISPLAY=:99.0"
6
8
  - "sh -e /etc/init.d/xvfb start"
data/README.md CHANGED
@@ -9,17 +9,19 @@ GreenOnion is a testing library for the UI only. It alerts you when the appearan
9
9
 
10
10
  ## Installation
11
11
 
12
+ You'll need to get Qt built in your testing environment. [Follow these steps](https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit) to get it up and running.
13
+
12
14
  Add this line to your application's Gemfile:
13
15
 
14
- `gem 'green_onion'`
16
+ gem 'green_onion'
15
17
 
16
18
  And then execute:
17
19
 
18
- `bundle`
20
+ bundle
19
21
 
20
22
  Or install it yourself as:
21
23
 
22
- `gem install green_onion`
24
+ gem install green_onion
23
25
 
24
26
  ## Usage
25
27
 
@@ -27,19 +29,21 @@ Or install it yourself as:
27
29
 
28
30
  For RSpec, `require 'green_onion'` in your spec_helper.rb file. Place this block in the file also:
29
31
 
30
- `GreenOnion.configure do |c|
31
- c.skins_dir = 'spec/skins'
32
- c.threshold = 20
33
- end`
32
+ GreenOnion.configure do |c|
33
+ c.skins_dir = 'your/path/to/skins'
34
+ c.threshold = 20
35
+ c.dimensions = { :width => 1440, :height => 768 }
36
+ end
34
37
 
35
- * `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
38
+ * `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'
36
39
  * `threshold` is the percentage of acceptable change that the screenshots can take. This number can always be overwritten for an instance.
40
+ * `dimensions` is a hash with the height and width of the browser window. The default dimensions are 1024x768.
37
41
 
38
42
  Then use one of the three methods below in a test...
39
43
 
40
44
  ### Percentage of change
41
45
 
42
- `GreenOnion.skin_percentage(url, threshold {optional})`
46
+ GreenOnion.skin_percentage(url, threshold {optional})
43
47
  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.
44
48
 
45
49
  * `url` is the screen you want tested. Must include http://, example - 'http://yourSite.com'
@@ -47,14 +51,15 @@ The primary feature of GreenOnion is seeing how much (if at all) a view has chan
47
51
 
48
52
  ### Viewing screenshot diffs
49
53
 
50
- `GreenOnion.skin_visual(url)`
54
+ GreenOnion.skin_visual(url)
51
55
  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.
52
56
 
53
57
  * `url` is the screen you want tested. Must include http://, example - 'http://yourSite.com'
54
58
 
55
59
  ### Both viewing screenshot diffs and percentage of change
56
60
 
57
-
61
+ GreenOnion.skin_visual_and_percentage(url, threshold {optional})
62
+ This is just a combination of the two methods above.
58
63
 
59
64
  ## Contributing
60
65
 
@@ -62,14 +67,15 @@ Once you are aware of a issue in the UI, you can also rip open your spec/skins d
62
67
 
63
68
  The best way to run the specs is with...
64
69
 
65
- `bundle exec rake spec`
70
+ bundle exec rake spec
66
71
 
67
72
  ...this way a Sinatra WEBrick server will run concurrently with the test suite, and exit on completion. You can see the Sinatra app in spec/sample_app.
68
73
 
69
74
  ## Roadmap
70
75
 
71
76
  * Screenshots can either be viewed as a visual diff, or overlayed newest over oldest and viewed as an onion-skin with sliding transparency.
72
- * Allow for headless screenshooting
77
+ * Allow for flexibility in picking browsers
78
+ * Run through all paths in a Rails app
73
79
  * More robust tests, especially around the visual diffs themselves
74
80
  * More documentation
75
81
  * More configuration/customizable settings
data/green_onion.gemspec CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
16
16
  gem.add_development_dependency "sinatra"
17
17
 
18
18
  gem.add_dependency "capybara"
19
+ gem.add_dependency "capybara-webkit"
19
20
  gem.add_dependency "oily_png"
20
21
  gem.add_dependency "rainbow"
21
22
 
data/lib/green_onion.rb CHANGED
@@ -21,7 +21,8 @@ module GreenOnion
21
21
  # Bring the Screenshot and Compare classes together to create a skin
22
22
  def skin(url)
23
23
  @screenshot = Screenshot.new(
24
- :dir => @configuration.skins_dir
24
+ :dir => @configuration.skins_dir,
25
+ :dimensions => @configuration.dimensions
25
26
  )
26
27
  @compare = GreenOnion::Compare.new
27
28
 
@@ -31,12 +32,13 @@ module GreenOnion
31
32
  # Finds the percentage of change between skins
32
33
  # Threshold can be set in configuration, or as an argument itself, and can be specific to an instance
33
34
  def skin_percentage(url, threshold=@configuration.threshold)
34
- threshold ||= 100
35
35
  skin(url)
36
36
  if(@screenshot.paths_hash.length > 1)
37
37
  puts "\n" + url.color(:cyan)
38
38
  @compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
39
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)
40
42
  end
41
43
  end
42
44
 
@@ -46,6 +48,8 @@ module GreenOnion
46
48
  if(@screenshot.paths_hash.length > 1)
47
49
  puts "\n" + url.color(:cyan)
48
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)
49
53
  end
50
54
  end
51
55
 
@@ -57,6 +61,8 @@ module GreenOnion
57
61
  @compare.percentage_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
58
62
  @compare.visual_diff(@screenshot.paths_hash[:original], @screenshot.paths_hash[:fresh])
59
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)
60
66
  end
61
67
  end
62
68
 
@@ -51,7 +51,7 @@ module GreenOnion
51
51
  begin
52
52
  @images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
53
53
  rescue NoMethodError
54
- puts "#{org} and #{fresh} skins are the same.".color(:yellow)
54
+ puts "Both skins are the same.".color(:yellow)
55
55
  end
56
56
 
57
57
  @images.last.save(@diffed_image)
@@ -1,7 +1,23 @@
1
1
  module GreenOnion
2
2
  class Configuration
3
-
4
- attr_accessor :skins_dir, :threshold
3
+
4
+ attr_writer :threshold, :skins_dir
5
+
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
13
+
14
+ def threshold
15
+ @threshold ||= 100
16
+ end
17
+
18
+ def skins_dir
19
+ @skins_dir ||= './spec/skins'
20
+ end
5
21
 
6
22
  end
7
23
  end
@@ -1,22 +1,25 @@
1
1
  require 'capybara/dsl'
2
+ require 'capybara-webkit'
2
3
  require "fileutils"
4
+ require "debugger"
3
5
 
4
6
  module GreenOnion
5
7
  class Screenshot
6
8
  include Capybara::DSL
7
9
 
8
- attr_accessor :dir
10
+ attr_accessor :dir, :dimensions
9
11
  attr_reader :paths_hash
10
12
 
11
13
  def initialize(params = {})
12
- Capybara.default_driver = :selenium
14
+ Capybara.default_driver = :webkit
15
+ @dimensions = params[:dimensions]
13
16
  @dir = params[:dir]
14
17
  @paths_hash = {}
15
18
  end
16
19
 
17
20
  def snap_screenshot(url, path)
18
21
  visit url
19
- Capybara.page.driver.browser.save_screenshot(path)
22
+ Capybara.page.driver.render(path, @dimensions)
20
23
  end
21
24
 
22
25
  def test_screenshot(url)
@@ -32,7 +35,6 @@ module GreenOnion
32
35
  else
33
36
  @shot_path = @paths_hash[:original]
34
37
  end
35
- return @shot_path
36
38
  end
37
39
 
38
40
  def get_path(url)
@@ -1,3 +1,3 @@
1
1
  module GreenOnion
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,17 +2,18 @@ require "spec_helper"
2
2
 
3
3
  describe GreenOnion do
4
4
 
5
+ before(:all) do
6
+ @tmp_path = './spec/tmp'
7
+ @url = 'http://localhost:8070'
8
+ @url_w_uri = @url + '/fake_uri'
9
+ end
10
+
5
11
  describe "Skins" do
6
-
7
12
  before(:each) do
8
- @tmp_path = './spec/tmp'
9
- @url = 'http://localhost:8070'
10
- @url_w_uri = @url + '/fake_uri'
11
13
  FileUtils.mkdir(@tmp_path)
12
14
 
13
15
  GreenOnion.configure do |c|
14
16
  c.skins_dir = @tmp_path
15
- c.threshold = 1
16
17
  end
17
18
  end
18
19
 
@@ -20,6 +21,11 @@ describe GreenOnion do
20
21
  FileUtils.rm_r(@tmp_path, :force => true)
21
22
  end
22
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
+
23
29
  it "should set/get custom directory" do
24
30
  GreenOnion.configuration.skins_dir.should eq(@tmp_path)
25
31
  end
@@ -46,15 +52,8 @@ describe GreenOnion do
46
52
  GreenOnion.compare.percentage_changed.should be == 0
47
53
  end
48
54
 
49
- it "should alert when diff percentage threshold is surpassed" do
50
- $stdout.should_receive(:puts).exactly(4).times
51
- 2.times do
52
- GreenOnion.skin_percentage(@url)
53
- end
54
- end
55
-
56
55
  it "should print just URL and changed/total when diff percentage threshold has not been surpassed" do
57
- $stdout.should_receive(:puts).exactly(2).times
56
+ $stdout.should_receive(:puts).exactly(3).times
58
57
  2.times do
59
58
  GreenOnion.skin_percentage(@url, 6)
60
59
  end
@@ -67,7 +66,6 @@ describe GreenOnion do
67
66
  GreenOnion.compare.diffed_image.should eq("#{@tmp_path}/root_diff.png")
68
67
  end
69
68
 
70
-
71
69
  it "should create visual diff between skins (even when there is no change)" do
72
70
  2.times do
73
71
  GreenOnion.skin_visual(@url_w_uri)
@@ -82,6 +80,47 @@ describe GreenOnion do
82
80
  ( (GreenOnion.compare.diffed_image.should eq("#{@tmp_path}/root_diff.png")) &&
83
81
  (GreenOnion.compare.percentage_changed.should be > 0) ).should be_true
84
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)
85
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
86
125
  end
87
126
  end
@@ -5,16 +5,18 @@ describe GreenOnion::Screenshot do
5
5
  before(:all) do
6
6
  @url = 'http://localhost:8070'
7
7
  @url_w_uri = @url + '/fake_uri'
8
+ @tmp_path = './spec/tmp'
9
+ @dimensions = { :width => 1024, :height => 768 }
8
10
  end
9
11
 
10
12
  describe 'Snap single screenshot' do
11
13
 
12
14
  before(:each) do
13
- @tmp_path = './spec/tmp'
14
15
  FileUtils.mkdir(@tmp_path)
15
16
 
16
17
  @screenshot = GreenOnion::Screenshot.new(
17
- :dir => @tmp_path
18
+ :dir => @tmp_path,
19
+ :dimensions => @dimensions
18
20
  )
19
21
  @file = "#{@tmp_path}/fake_uri.png"
20
22
  end
@@ -49,11 +51,11 @@ describe GreenOnion::Screenshot do
49
51
  describe 'Snap two screenshots' do
50
52
 
51
53
  before(:each) do
52
- @tmp_path = './spec/tmp'
53
54
  FileUtils.mkdir(@tmp_path)
54
55
 
55
56
  @screenshot = GreenOnion::Screenshot.new(
56
- :dir => @tmp_path
57
+ :dir => @tmp_path,
58
+ :dimensions => @dimensions
57
59
  )
58
60
  @file1 = "#{@tmp_path}/fake_uri.png"
59
61
  @file2 = "#{@tmp_path}/fake_uri_fresh.png"
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.3
5
+ version: 0.0.4
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-27 00:00:00 Z
13
+ date: 2012-07-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -90,7 +90,7 @@ dependencies:
90
90
  type: :runtime
91
91
  version_requirements: *id007
92
92
  - !ruby/object:Gem::Dependency
93
- name: oily_png
93
+ name: capybara-webkit
94
94
  prerelease: false
95
95
  requirement: &id008 !ruby/object:Gem::Requirement
96
96
  none: false
@@ -101,7 +101,7 @@ dependencies:
101
101
  type: :runtime
102
102
  version_requirements: *id008
103
103
  - !ruby/object:Gem::Dependency
104
- name: rainbow
104
+ name: oily_png
105
105
  prerelease: false
106
106
  requirement: &id009 !ruby/object:Gem::Requirement
107
107
  none: false
@@ -111,6 +111,17 @@ dependencies:
111
111
  version: "0"
112
112
  type: :runtime
113
113
  version_requirements: *id009
114
+ - !ruby/object:Gem::Dependency
115
+ name: rainbow
116
+ prerelease: false
117
+ requirement: &id010 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: "0"
123
+ type: :runtime
124
+ version_requirements: *id010
114
125
  description: UI testing/screenshot diffing tool
115
126
  email:
116
127
  - ted@intridea.com