rspec-visual 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a003cdbec4d7284cec1419b7f6b4bca7c516bb62
4
+ data.tar.gz: 75a4ee1e612612454829ec7677aa340c4810112b
5
+ SHA512:
6
+ metadata.gz: e7756763e7f83749b41ca5e9e2755138785cd6af2990bee75c47c4452afab6f9fae1effe5bb10b7dc0393c31dd9ea6a16f6dd5707faa18de486c3a4deb683aad
7
+ data.tar.gz: 8141f2ab42372d477dbbf5d8f48f9da262c449ce9639d38bf630faa79e1440a823bd78f62f43de8cd25f90517bc3f4583c5a411afc55db0a1a88ecf85af3b2dc
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-visual.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Simon Bagreev
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # Rspec::Visual
2
+
3
+ RSpec plugin for writing "visual" tests: tests that look for changes in the
4
+ applications's look by comparing screenshots on current branch to the latest
5
+ 'stable' screenshots
6
+
7
+ ## Installation and Usage
8
+
9
+ ### Step 1 - Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rspec-visual'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rspec-visual
24
+
25
+ ### Step 2 - Configuration
26
+
27
+ Configure `rspec-visual` with the folder for _"stable"_ screenshots (they will
28
+ be persisted in version control), folder for temporary screenshots, and run `capybara` setup:
29
+
30
+ ```ruby
31
+ # spec/support/rspec-visual.rb
32
+ Rspec::Visual::Configuration.configure do |config|
33
+ config.screenshot_folder = Rails.root.join('tmp')
34
+ config.stable_screenshot_folder = Rails.root.join('docs/visual')
35
+ config.configure_capybara
36
+ end
37
+ ```
38
+
39
+ ### Step 3 - Writing tests
40
+
41
+ Write some visual tests (**make sure to tag them with `visual: true`**)
42
+ using following steps:
43
+
44
+ - in your test, visit the page that you want to check
45
+ - take the screenshot using `take_screenshot` helper and passing it page and example
46
+ - use `look_like` matcher for assertion
47
+
48
+ ```ruby
49
+ # spec/features/visual/home_page_spec.rb
50
+ require 'rails_helper'
51
+
52
+ describe 'home page', type: :feature, visual: true do
53
+ it 'home_page' do |example|
54
+ visit '/'
55
+ take_screenshot(page, example)
56
+ should look_like example.description
57
+ end
58
+ end
59
+ ```
60
+
61
+ ### Step 4 - Checking the result
62
+
63
+ #### First run
64
+
65
+ No failures will occur. Screenshots will be saved in the "stable" folder that you
66
+ defined in "Configure" step.
67
+
68
+ #### Consequent runs
69
+
70
+ Screenshots from all "visual" tests will be matched against ones in "stable" folder.
71
+
72
+ In case there is a difference, like so:
73
+
74
+ #### "Stable" screenshot
75
+ ![Original](/../screenshots-do-not-delete/sample1.jpg?raw=true "Original")
76
+
77
+ #### Screenshot with changes (banner missing)
78
+ ![Actual](/../screenshots-do-not-delete/sample2.jpg?raw=true "Actual")
79
+
80
+ #### Diff file (diff area is highlighted in red)
81
+ ![Diff](/../screenshots-do-not-delete/sample_diff.jpg?raw=true "Diff")
82
+
83
+ The test will fail and difference file will be generated in
84
+ `Rspec::Visual::Configuration.screenshot_folder`:
85
+
86
+ Also, failure message will say:
87
+
88
+ ```shell
89
+ Failures:
90
+
91
+ 1) home page home_page
92
+ Failure/Error: should look_like example.description
93
+ expected /path/to/tmp/home_page.png to look like /path/to/docs/visual/home_page.png
94
+ If you intended home_page to look diffrently, please copy over /path/to/tmp/home_page.png into /path/to/docs/visual
95
+ # ./spec/features/visual/home_page_visual_spec.rb:10:in `block (2 levels) in <top (required)>'
96
+ ```
97
+ _**Please read the failure message carefully, and if you indeed wanted the page to change
98
+ than manually copy now-correct screenshot to the "stable" folder in order for specs to pass**_
99
+
100
+ ## GOTCHAS
101
+
102
+ 1. depends on `rspec, capybara, poltergeist, phantomJS` and _**imagemagick**_
103
+ 2. May conflict with `VCR`, to overcome use:
104
+ ```ruby
105
+ VCR.configure do |c|
106
+ c.ignore_localhost = true
107
+ end
108
+ ```
109
+ 3. If you want to check the app that is NOT _localhost_, use Capybara config like so:
110
+
111
+ ```ruby
112
+ RSpec.configure do |config|
113
+ default = Capybara.server_port
114
+ config.before(:example, :visual => :true) do
115
+ Capybara.run_server = false
116
+ Capybara.server_port = 80
117
+ Capybara.app_host = 'http://stage.myapp.com'
118
+ end
119
+
120
+ config.after(:example, :visual => :true) do
121
+ Capybara.run_server = true
122
+ Capybara.server_port = default
123
+ end
124
+ end
125
+ ```
126
+
127
+ ## Contributing
128
+
129
+ ### TODO
130
+
131
+ - add ability to take screenshots in different browsers
132
+ - add ability to take screenshots in different viewports
133
+ - add ability to configure 'similarity' percentage
134
+ - add ability to test certain areas of the page
135
+ - add test coverage
136
+ - expand beyond `poltergeist`, try `selenium-webkit`
137
+
138
+ 1. Fork it ( https://github.com/[my-github-username]/rspec-visual/fork )
139
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
140
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
141
+ 4. Push to the branch (`git push origin my-new-feature`)
142
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,34 @@
1
+ require 'singleton'
2
+
3
+ module Rspec
4
+ module Visual
5
+ class Configuration
6
+ include Singleton
7
+
8
+ class << self
9
+ attr_accessor :screenshot_folder, :stable_screenshot_folder
10
+
11
+ def configure
12
+ yield self
13
+ end
14
+
15
+ def configure_capybara
16
+ Capybara.register_driver :poltergeist do |app|
17
+ Capybara::Poltergeist::Driver.new(app, js_errors: false)
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.before(:example, :visual => :true) do
22
+ config.include ScreenshotHelper
23
+ Capybara.current_driver = :poltergeist
24
+ end
25
+
26
+ config.after(:example, :visual => :true) do
27
+ Capybara.use_default_driver
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec/visual/configuration'
2
+ module ScreenshotHelper
3
+ def take_screenshot(page, example)
4
+ file_path = File.join(Rspec::Visual::Configuration.screenshot_folder, "#{example.description}.png")
5
+ page.save_screenshot(file_path, full: true)
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ require 'rspec'
2
+ require 'rspec/expectations'
3
+
4
+ RSpec::Matchers.define :look_like do |expected|
5
+ expected_image_file_path = File.join(Rspec::Visual::Configuration.stable_screenshot_folder, "#{expected}.png")
6
+ actual_image_file_path = File.join(Rspec::Visual::Configuration.screenshot_folder, "#{expected}.png")
7
+
8
+ match do |actual|
9
+ unless File.exists?(expected_image_file_path)
10
+ File.cp(actual_image_file_path, expected_image_file_path) and return true
11
+ end
12
+
13
+ diff_file_path = File.join(Rspec::Visual::Configuration.screenshot_folder, "#{expected}_diff.png")
14
+ system "compare -metric PAE -subimage-search -dissimilarity-threshold 1 \
15
+ #{expected_image_file_path} #{actual_image_file_path} #{diff_file_path}"
16
+ end
17
+
18
+ failure_message do |actual|
19
+ "expected #{actual_image_file_path} to look like #{expected_image_file_path}\n"\
20
+ "If you intended #{expected} to look diffrently, please copy over "\
21
+ "#{actual_image_file_path} into #{Rspec::Visual::Configuration.stable_screenshot_folder}"
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module Visual
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec/visual/version'
2
+ require 'rspec/visual/configuration'
3
+ require 'rspec/visual/helpers/screenshot_helper'
4
+ require 'rspec/visual/matchers/look_like_matcher'
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/visual/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-visual"
8
+ spec.version = Rspec::Visual::VERSION
9
+ spec.authors = ["Simon Bagreev"]
10
+ spec.email = ["sbagreev@gmail.com"]
11
+ spec.summary = %Q{ Visual testing with rspec via screenshot comparison. }
12
+ spec.description = %Q{ Adds 'visual' specs and matchers that take screenshots
13
+ of the app and compare them to find regressions in
14
+ frontend. Must have imagemagick installed! Depends on
15
+ rspec, capybara, poltergeist }
16
+ spec.homepage = ""
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "rspec", "~> 3.0"
25
+ spec.add_dependency "capybara", "~> 2.4"
26
+ spec.add_dependency "poltergeist", "~> 1.6"
27
+ spec.add_development_dependency "bundler", "~> 1.7"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-visual
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Simon Bagreev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capybara
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: poltergeist
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: " Adds 'visual' specs and matchers that take screenshots\n of
84
+ the app and compare them to find regressions in\n frontend.
85
+ Must have imagemagick installed! Depends on\n rspec, capybara,
86
+ poltergeist "
87
+ email:
88
+ - sbagreev@gmail.com
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/rspec/visual.rb
99
+ - lib/rspec/visual/configuration.rb
100
+ - lib/rspec/visual/helpers/screenshot_helper.rb
101
+ - lib/rspec/visual/matchers/look_like_matcher.rb
102
+ - lib/rspec/visual/version.rb
103
+ - rspec-visual.gemspec
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.8
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Visual testing with rspec via screenshot comparison.
128
+ test_files: []
129
+ has_rdoc: