compatriot 0.1.2 → 0.1.3
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +2 -0
- data/compatriot.gemspec +2 -0
- data/lib/compatriot.rb +2 -1
- data/lib/compatriot/assertions.rb +5 -0
- data/lib/compatriot/image_differ/color_differ.rb +3 -17
- data/lib/compatriot/image_differ/image_differ.rb +2 -2
- data/lib/compatriot/minitest_report_driver.rb +36 -0
- data/lib/compatriot/report_template.html.haml +45 -0
- data/lib/compatriot/reporter.rb +19 -0
- data/lib/compatriot/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/compatriot_spec.rb +1 -1
- data/spec/unit/image_differ/color_differ_spec.rb +3 -11
- data/spec/unit/image_differ/image_differ_spec.rb +1 -2
- metadata +39 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52335a1370e7cf3da50555a02c667e6dc8389b33
|
4
|
+
data.tar.gz: da7bef0b5be93ebb60ddf4a4f7f22236190c2561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b11a74741daac8e3e2589ea78a54a72c7e7045cb9cb47bae5f9050d029ffaf3d263f09e180572b7eacc4bf8303fdc6744de42931cc312b2e852fe43d51486445
|
7
|
+
data.tar.gz: 8476a55fda6ed11afc4be69a994254f67b37c5ca685389d06971159819fc01ff235157f7939fc91acf29736ac121149934065fa49448d8990ee44a9a6855921b
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,8 @@ How To Use
|
|
47
47
|
|
48
48
|
class IntegrationTest
|
49
49
|
include Compatriot::Assertions
|
50
|
+
|
51
|
+
Minitest::Reporters.use! Compatriot::MinitestReportDriver.new # Optional: if you want html output. See MinitestReporters for more info
|
50
52
|
|
51
53
|
Compatriot.configure do |config|
|
52
54
|
screenshot_directory =
|
data/compatriot.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.licenses = "MIT"
|
21
21
|
|
22
22
|
gem.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.2'
|
23
|
+
gem.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.8'
|
23
24
|
gem.add_development_dependency 'sinatra', '~> 1.4', '>= 1.4.6'
|
24
25
|
gem.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
|
25
26
|
gem.add_development_dependency 'pry'
|
@@ -29,4 +30,5 @@ Gem::Specification.new do |gem|
|
|
29
30
|
gem.add_runtime_dependency 'rake', '~> 10.4', '>= 10.4.2'
|
30
31
|
gem.add_runtime_dependency 'chunky_png', '~> 1.3', '>= 1.3.5'
|
31
32
|
gem.add_runtime_dependency 'oily_png', '~> 1.2.0'
|
33
|
+
gem.add_runtime_dependency 'haml', '~> 4.0.7'
|
32
34
|
end
|
data/lib/compatriot.rb
CHANGED
@@ -4,6 +4,7 @@ require "compatriot/runner"
|
|
4
4
|
require "compatriot/browser"
|
5
5
|
require "compatriot/results_presenter"
|
6
6
|
require "compatriot/image_differ/image_differ"
|
7
|
+
require "compatriot/minitest_report_driver"
|
7
8
|
|
8
9
|
module Compatriot
|
9
10
|
class << self
|
@@ -34,7 +35,7 @@ module Compatriot
|
|
34
35
|
def percentage_changed(test, description = '')
|
35
36
|
variable_img_path = take_screenshot(test, description)
|
36
37
|
control_img_path = filepath_for_screenshot('control', filename_for_test(test, description))
|
37
|
-
diff = Compatriot::ColorDiffer.diff(variable_img_path, control_img_path
|
38
|
+
diff = Compatriot::ColorDiffer.diff(variable_img_path, control_img_path)
|
38
39
|
variable_image = ChunkyPNG::Image.from_file(variable_img_path)
|
39
40
|
Compatriot::ColorDiffer.color_difference_percentage(variable_image, diff)
|
40
41
|
end
|
@@ -3,6 +3,11 @@ require 'compatriot'
|
|
3
3
|
module Compatriot
|
4
4
|
module Assertions
|
5
5
|
def assert_no_ui_changes(title = '')
|
6
|
+
class << self
|
7
|
+
attr_accessor :compatriot_assertion_titles
|
8
|
+
end
|
9
|
+
self.compatriot_assertion_titles ||= []
|
10
|
+
self.compatriot_assertion_titles << title
|
6
11
|
diff = Compatriot.percentage_changed(self, title)
|
7
12
|
diff_file = Compatriot.filepath_for_screenshot('diffs', Compatriot.filename_for_test(self, title))
|
8
13
|
puts "% diff is #{diff}. #{diff_file}" if Compatriot.show_diffs
|
@@ -23,10 +23,9 @@ module Compatriot
|
|
23
23
|
output.save(output_filename)
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.diff(filename1, filename2
|
26
|
+
def self.diff(filename1, filename2)
|
27
27
|
image1 = ChunkyPNG::Image.from_file(filename1)
|
28
28
|
image2 = ChunkyPNG::Image.from_file(filename2)
|
29
|
-
@results_directory = results_directory
|
30
29
|
|
31
30
|
output = ChunkyPNG::Image.new(image1.width, image1.height, WHITE)
|
32
31
|
diff = []
|
@@ -40,21 +39,15 @@ module Compatriot
|
|
40
39
|
end
|
41
40
|
end
|
42
41
|
|
43
|
-
save_diff_image(output, filename1, filename2)
|
42
|
+
save_diff_image(output, File.basename(filename1), File.basename(filename2))
|
44
43
|
|
45
44
|
diff
|
46
45
|
end
|
47
46
|
|
48
47
|
def self.save_diff_image(output, filename1, filename2)
|
49
|
-
|
50
|
-
path = File.join(
|
51
|
-
@results_directory,
|
52
|
-
"diffs",
|
53
|
-
filename
|
54
|
-
)
|
48
|
+
path = Compatriot.filepath_for_screenshot('diffs', filename1)
|
55
49
|
create_directory_if_necessary(path)
|
56
50
|
output.save(path)
|
57
|
-
File.join("diffs", filename)
|
58
51
|
end
|
59
52
|
|
60
53
|
def self.create_directory_if_necessary(file)
|
@@ -62,13 +55,6 @@ module Compatriot
|
|
62
55
|
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
63
56
|
end
|
64
57
|
|
65
|
-
def self.diff_name(image1, image2)
|
66
|
-
browser1 = File.basename(File.dirname(image1))
|
67
|
-
browser2 = File.basename(File.dirname(image2))
|
68
|
-
|
69
|
-
"color_#{browser1}_vs_#{browser2}_#{File.basename(image1)}"
|
70
|
-
end
|
71
|
-
|
72
58
|
def self.color_difference_of_pixels(pixel1, pixel2)
|
73
59
|
score = Math.sqrt(
|
74
60
|
(r(pixel2) - r(pixel1)) ** 2 +
|
@@ -25,7 +25,7 @@ module Compatriot
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def diff(results)
|
28
|
-
@strategy.diff(results.first, results.last
|
28
|
+
@strategy.diff(results.first, results.last)
|
29
29
|
end
|
30
30
|
|
31
31
|
def diffs_path
|
@@ -38,4 +38,4 @@ module Compatriot
|
|
38
38
|
FileUtils.mkdir_p(diffs_path)
|
39
39
|
end
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'minitest'
|
2
|
+
require 'compatriot/reporter'
|
3
|
+
|
4
|
+
module Compatriot
|
5
|
+
class MinitestReportDriver < Minitest::StatisticsReporter
|
6
|
+
attr_accessor :tests
|
7
|
+
|
8
|
+
def initialize(options={})
|
9
|
+
super($stdout, options)
|
10
|
+
self.tests = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def before_test(test)
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_test(test)
|
17
|
+
end
|
18
|
+
|
19
|
+
def before_suite(suite)
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_suite(suite)
|
23
|
+
end
|
24
|
+
|
25
|
+
def record(test)
|
26
|
+
super
|
27
|
+
tests << test
|
28
|
+
end
|
29
|
+
|
30
|
+
def report
|
31
|
+
super
|
32
|
+
Compatriot::Reporter.new(tests).run
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
%style
|
2
|
+
:plain
|
3
|
+
img {
|
4
|
+
width: 100%;
|
5
|
+
height: auto;
|
6
|
+
}
|
7
|
+
label.bold{
|
8
|
+
font-weight: bold;
|
9
|
+
}
|
10
|
+
label.collapse{
|
11
|
+
cursor: pointer;
|
12
|
+
display: block;
|
13
|
+
background: green;
|
14
|
+
}
|
15
|
+
label.collapse.failed{
|
16
|
+
background: red;
|
17
|
+
}
|
18
|
+
label.collapse + input{
|
19
|
+
display: none; /* hide the checkboxes */
|
20
|
+
}
|
21
|
+
label.collapse + input + div{
|
22
|
+
display:none;
|
23
|
+
}
|
24
|
+
label.collapse + input:checked + div{
|
25
|
+
display:block;
|
26
|
+
}
|
27
|
+
|
28
|
+
%h1 Compatriot Test Report
|
29
|
+
- $tests.each_with_index do |test,i|
|
30
|
+
- test.compatriot_assertion_titles.each_with_index do |title,j|
|
31
|
+
%label.collapse{ for: "_#{i}.#{j}", class: ("failed" unless test.passed?) }= test.location + ":" + title
|
32
|
+
%input{id: "_#{i}.#{j}", type: "checkbox"}
|
33
|
+
%div
|
34
|
+
%table
|
35
|
+
%tbody
|
36
|
+
%tr
|
37
|
+
%td
|
38
|
+
%label.bold Control
|
39
|
+
%img{src: Compatriot.filepath_for_screenshot('control', Compatriot.filename_for_test(test, title))}
|
40
|
+
%td
|
41
|
+
%label.bold Variable
|
42
|
+
%img{src: Compatriot.filepath_for_screenshot('variable', Compatriot.filename_for_test(test, title))}
|
43
|
+
%td
|
44
|
+
%label.bold Diff
|
45
|
+
%img{src: Compatriot.filepath_for_screenshot('diffs', Compatriot.filename_for_test(test, title))}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'haml'
|
2
|
+
|
3
|
+
module Compatriot
|
4
|
+
class Reporter
|
5
|
+
attr_accessor :tests
|
6
|
+
|
7
|
+
def initialize(tests)
|
8
|
+
@tests = tests
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
$tests = tests.sort_by {|t| (t.passed? ? 1 : 0) }
|
13
|
+
file_path = File.expand_path('../report_template.html.haml', __FILE__)
|
14
|
+
template = File.read(file_path)
|
15
|
+
engine = Haml::Engine.new(template)
|
16
|
+
File.write 'compatriot_report.html',engine.render
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/compatriot/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -10,7 +10,7 @@ describe Compatriot do
|
|
10
10
|
CONTROL_IMG = "#{SCREENSHOTS_DIR}/control/#{CONTROL_IMG_FILENAME}"
|
11
11
|
CONTROL_IMG2 = "#{SCREENSHOTS_DIR}/control/important_test_will_do_something_important_another.png"
|
12
12
|
VARIABLE_IMG = "#{SCREENSHOTS_DIR}/variable/important_test_will_do_something_important_and_has_a_description.png"
|
13
|
-
DIFF_IMG = "#{SCREENSHOTS_DIR}/diffs/
|
13
|
+
DIFF_IMG = "#{SCREENSHOTS_DIR}/diffs/important_test_will_do_something_important_and_has_a_description.png"
|
14
14
|
|
15
15
|
def setup_control_image
|
16
16
|
Page.new.save_screenshot CONTROL_IMG
|
@@ -9,7 +9,7 @@ describe Compatriot::ColorDiffer do
|
|
9
9
|
ChunkyPNG::Image.expects(:from_file).with("file_two").returns(image2)
|
10
10
|
Compatriot::ColorDiffer.stubs(:save_diff_image)
|
11
11
|
|
12
|
-
Compatriot::ColorDiffer.diff("file_one", "file_two"
|
12
|
+
Compatriot::ColorDiffer.diff("file_one", "file_two")
|
13
13
|
end
|
14
14
|
|
15
15
|
it "starts a new white image with the same dimensions" do
|
@@ -26,14 +26,6 @@ describe Compatriot::ColorDiffer do
|
|
26
26
|
ChunkyPNG::Image.stubs(:from_file).returns(image1, image2)
|
27
27
|
Compatriot::ColorDiffer.stubs(:save_diff_image)
|
28
28
|
|
29
|
-
|
29
|
+
Compatriot::ColorDiffer.diff("/some/file/path.png", "/some/file/path.png")
|
30
30
|
end
|
31
|
-
|
32
|
-
it "names the image based on the strategy and the browsers" do
|
33
|
-
name = Compatriot::ColorDiffer.diff_name(
|
34
|
-
"/something/firefox/1.png",
|
35
|
-
"/something/chrome/1.png"
|
36
|
-
)
|
37
|
-
name.must_equal("color_firefox_vs_chrome_1.png")
|
38
|
-
end
|
39
|
-
end
|
31
|
+
end
|
@@ -53,7 +53,6 @@ describe Compatriot::ImageDiffer do
|
|
53
53
|
strategy.expects(:diff).with(
|
54
54
|
file_one,
|
55
55
|
file_two,
|
56
|
-
"something"
|
57
56
|
).returns("diff_filename.png")
|
58
57
|
|
59
58
|
c = Compatriot::ImageDiffer.new(
|
@@ -64,4 +63,4 @@ describe Compatriot::ImageDiffer do
|
|
64
63
|
c.diff([file_one, file_two]).must_equal("diff_filename.png")
|
65
64
|
end
|
66
65
|
end
|
67
|
-
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compatriot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carol (Nichols || Goulding)
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -31,6 +31,26 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 5.8.2
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: minitest-reporters
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.1'
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.1.8
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.1'
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.1.8
|
34
54
|
- !ruby/object:Gem::Dependency
|
35
55
|
name: sinatra
|
36
56
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +199,20 @@ dependencies:
|
|
179
199
|
- - "~>"
|
180
200
|
- !ruby/object:Gem::Version
|
181
201
|
version: 1.2.0
|
202
|
+
- !ruby/object:Gem::Dependency
|
203
|
+
name: haml
|
204
|
+
requirement: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 4.0.7
|
209
|
+
type: :runtime
|
210
|
+
prerelease: false
|
211
|
+
version_requirements: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 4.0.7
|
182
216
|
description: Compare screenshots in your tests!
|
183
217
|
email:
|
184
218
|
- carol.nichols@gmail.com
|
@@ -204,6 +238,9 @@ files:
|
|
204
238
|
- lib/compatriot/browser.rb
|
205
239
|
- lib/compatriot/image_differ/color_differ.rb
|
206
240
|
- lib/compatriot/image_differ/image_differ.rb
|
241
|
+
- lib/compatriot/minitest_report_driver.rb
|
242
|
+
- lib/compatriot/report_template.html.haml
|
243
|
+
- lib/compatriot/reporter.rb
|
207
244
|
- lib/compatriot/results_presenter.rb
|
208
245
|
- lib/compatriot/runner.rb
|
209
246
|
- lib/compatriot/version.rb
|