compatriot 0.1.5 → 0.1.6
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/lib/compatriot/assertions.rb +3 -0
- data/lib/compatriot/report_template.html.haml +15 -17
- data/lib/compatriot/reporter.rb +20 -1
- data/lib/compatriot/version.rb +1 -1
- data/spec/spec_helper.rb +11 -5
- data/spec/unit/assertions_spec.rb +0 -5
- data/spec/unit/compatriot_spec.rb +2 -7
- data/spec/unit/report_spec.rb +94 -43
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75b88eb52e8a954c774264cd033b8a9c65b62de0
|
4
|
+
data.tar.gz: 960e215f8c4cdba3a3f83a4e6b5cba92aab7b609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a0fd9c05af9f7501304a813c47bd5e11ec4fcad796e83ee2ccd561bd4cf51ea17e13604baea659f2cf4367d00373dce599b75ee2dae4d53d83f5f3acd385ded
|
7
|
+
data.tar.gz: a33bd9cac462ebbea97adf7a09b8d4eecd6d0d642ea9ba5d73244755916f15d2990ff3b98d41de0bbcc335527a32c9db4e699d6f54c43ee4dfadecb2ff78d2c2
|
@@ -5,10 +5,13 @@ module Compatriot
|
|
5
5
|
def assert_no_ui_changes(title = '')
|
6
6
|
class << self
|
7
7
|
attr_accessor :compatriot_assertion_titles
|
8
|
+
attr_accessor :compatriot_percentages_changed
|
8
9
|
end
|
9
10
|
self.compatriot_assertion_titles ||= []
|
10
11
|
self.compatriot_assertion_titles << title
|
12
|
+
self.compatriot_percentages_changed ||= []
|
11
13
|
diff = Compatriot.percentage_changed(self, title)
|
14
|
+
self.compatriot_percentages_changed << diff
|
12
15
|
diff_file = Compatriot.filepath_for_screenshot('diffs', Compatriot.filename_for_test(self, title))
|
13
16
|
puts "% diff is #{diff}. #{diff_file}" if Compatriot.show_diffs
|
14
17
|
pass = diff <= Compatriot.ui_difference_threshold
|
@@ -27,20 +27,18 @@
|
|
27
27
|
|
28
28
|
%h1 Compatriot Test Report
|
29
29
|
- $tests.each_with_index do |test,i|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
%
|
35
|
-
%
|
36
|
-
%
|
37
|
-
%
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
%label.bold Diff
|
46
|
-
%img{src: Compatriot.filepath_for_screenshot('diffs', Compatriot.filename_for_test(test, title))}
|
30
|
+
%label.collapse{ for: "_#{i}", class: test[:status] }= test[:label]
|
31
|
+
%input{id: "_#{i}", type: "checkbox"}
|
32
|
+
%div
|
33
|
+
%table
|
34
|
+
%tbody
|
35
|
+
%tr
|
36
|
+
%td
|
37
|
+
%label.bold Control
|
38
|
+
%img{src: test[:control_image_path]}
|
39
|
+
%td
|
40
|
+
%label.bold Variable
|
41
|
+
%img{src: test[:variable_image_path]}
|
42
|
+
%td
|
43
|
+
%label.bold Diff
|
44
|
+
%img{src: test[:diff_image_path]}
|
data/lib/compatriot/reporter.rb
CHANGED
@@ -9,11 +9,30 @@ module Compatriot
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run
|
12
|
-
$tests = tests
|
12
|
+
$tests = format(tests)
|
13
13
|
file_path = File.expand_path('../report_template.html.haml', __FILE__)
|
14
14
|
template = File.read(file_path)
|
15
15
|
engine = Haml::Engine.new(template)
|
16
16
|
File.write 'compatriot_report.html',engine.render
|
17
17
|
end
|
18
|
+
|
19
|
+
def format(tests)
|
20
|
+
formated_tests = []
|
21
|
+
tests.each do |test|
|
22
|
+
next unless test.respond_to? :compatriot_assertion_titles
|
23
|
+
test.compatriot_assertion_titles.each_with_index do |title,j|
|
24
|
+
formated_test = {
|
25
|
+
label: test.location + ':' + title + ':' + test.compatriot_percentages_changed[j].to_s + "% difference",
|
26
|
+
percentage_changed: test.compatriot_percentages_changed[j],
|
27
|
+
status: test.passed? ? "passed" : "failed",
|
28
|
+
control_image_path: Compatriot.filepath_for_screenshot('control', Compatriot.filename_for_test(test, title)),
|
29
|
+
variable_image_path: Compatriot.filepath_for_screenshot('variable', Compatriot.filename_for_test(test, title)),
|
30
|
+
diff_image_path: Compatriot.filepath_for_screenshot('diffs', Compatriot.filename_for_test(test, title)),
|
31
|
+
}
|
32
|
+
formated_tests << formated_test
|
33
|
+
end
|
34
|
+
end
|
35
|
+
formated_tests.sort_by { |k| k[:percentage_changed] }.reverse
|
36
|
+
end
|
18
37
|
end
|
19
38
|
end
|
data/lib/compatriot/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,8 @@ require 'compatriot'
|
|
8
8
|
|
9
9
|
require_relative "sample_app/sample_app"
|
10
10
|
|
11
|
+
SCREENSHOTS_DIR = './tmp/test/screenshots'
|
12
|
+
|
11
13
|
# A custom runner to enable before_suite and after_suite setup/teardown.
|
12
14
|
# http://bfts.rubyforge.org/minitest/index.html
|
13
15
|
# Only using it to delete the screenshots that result from running the tests
|
@@ -21,11 +23,6 @@ module TestRunner
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
class Minitest::Spec
|
25
|
-
include TestRunner
|
26
|
-
include Compatriot::Assertions
|
27
|
-
end
|
28
|
-
|
29
26
|
module FakeCapybara
|
30
27
|
def self.current_session
|
31
28
|
Page.new
|
@@ -43,3 +40,12 @@ class Page
|
|
43
40
|
filepath
|
44
41
|
end
|
45
42
|
end
|
43
|
+
|
44
|
+
class Minitest::Spec
|
45
|
+
include TestRunner
|
46
|
+
include Compatriot::Assertions
|
47
|
+
Compatriot.configure do |config|
|
48
|
+
config.screenshot_directory = SCREENSHOTS_DIR
|
49
|
+
config.framework = FakeCapybara
|
50
|
+
end
|
51
|
+
end
|
@@ -3,7 +3,6 @@ require_relative '../spec_helper'
|
|
3
3
|
describe Compatriot::Assertions do
|
4
4
|
let(:page) { Page.new }
|
5
5
|
|
6
|
-
SCREENSHOTS_DIR = './tmp/test/screenshots'
|
7
6
|
CONTROL_IMG_FILENAME = 'important_test_will_do_something_important_and_has_a_description.png'
|
8
7
|
CONTROL_IMG = "#{SCREENSHOTS_DIR}/control/#{CONTROL_IMG_FILENAME}"
|
9
8
|
CONTROL_IMG2 = "#{SCREENSHOTS_DIR}/control/important_test_will_do_something_important_another.png"
|
@@ -16,10 +15,6 @@ describe Compatriot::Assertions do
|
|
16
15
|
|
17
16
|
before do
|
18
17
|
FileUtils.remove_dir(SCREENSHOTS_DIR) if File.directory?(SCREENSHOTS_DIR)
|
19
|
-
Compatriot.configure do |config|
|
20
|
-
config.screenshot_directory = SCREENSHOTS_DIR
|
21
|
-
config.framework = FakeCapybara
|
22
|
-
end
|
23
18
|
end
|
24
19
|
|
25
20
|
it 'can assert on assert_no_ui_changes' do
|
@@ -5,7 +5,6 @@ describe Compatriot do
|
|
5
5
|
let(:stubbed_test) { stub_everything('test', name: 'test_001_will do something important', class: class_stub) }
|
6
6
|
let(:page) { Page.new }
|
7
7
|
|
8
|
-
SCREENSHOTS_DIR = './tmp/test/screenshots'
|
9
8
|
CONTROL_IMG_FILENAME = 'important_test_will_do_something_important_and_has_a_description.png'
|
10
9
|
CONTROL_IMG = "#{SCREENSHOTS_DIR}/control/#{CONTROL_IMG_FILENAME}"
|
11
10
|
CONTROL_IMG2 = "#{SCREENSHOTS_DIR}/control/important_test_will_do_something_important_another.png"
|
@@ -63,12 +62,8 @@ describe Compatriot do
|
|
63
62
|
|
64
63
|
describe 'configuration' do
|
65
64
|
before do
|
66
|
-
@
|
67
|
-
|
68
|
-
Compatriot.configure do |config|
|
69
|
-
config.screenshot_directory = @screenshot_directory
|
70
|
-
end
|
71
|
-
FileUtils.remove_dir(@screenshot_directory) if File.directory?(SCREENSHOTS_DIR)
|
65
|
+
@control_file = SCREENSHOTS_DIR + '/control/' + CONTROL_IMG_FILENAME
|
66
|
+
FileUtils.remove_dir(SCREENSHOTS_DIR) if File.directory?(SCREENSHOTS_DIR)
|
72
67
|
end
|
73
68
|
|
74
69
|
it 'can set the screenshot directory' do
|
data/spec/unit/report_spec.rb
CHANGED
@@ -1,52 +1,103 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Compatriot::Reporter do
|
4
|
-
|
5
|
-
before do
|
6
|
-
FileUtils.rm(REPORT_FILENAME) if File.exists?(REPORT_FILENAME)
|
7
|
-
end
|
4
|
+
describe 'tests format' do
|
8
5
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 2
|
27
|
-
end
|
6
|
+
it 'sorts the tests by percentage changed' do
|
7
|
+
test1 = stub_everything('test',
|
8
|
+
name: 'test_1_viewing_a_specific_report',
|
9
|
+
location: 'Some description',
|
10
|
+
compatriot_assertion_titles: [ 'did stuff','moar' ],
|
11
|
+
compatriot_percentages_changed: [ 0.02 , 0.04 ],
|
12
|
+
passed?: true)
|
13
|
+
test2 = stub_everything('test',
|
14
|
+
name: 'test_2_viewing_a_specific_report_with_a_filter',
|
15
|
+
location: 'Another description',
|
16
|
+
compatriot_assertion_titles: [ 'did other stuff', 'moar other stuff' ],
|
17
|
+
compatriot_percentages_changed: [ 0.03, 0.8 ],
|
18
|
+
passed?: false)
|
19
|
+
tests = [test1, test2]
|
20
|
+
formated_tests = Compatriot::Reporter.new(tests).format(tests)
|
21
|
+
formated_tests.map { |t| t[:percentage_changed] }.must_equal [ 0.8, 0.04, 0.03, 0.02 ]
|
22
|
+
end
|
28
23
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
24
|
+
it 'labels the tests names' do
|
25
|
+
tests = [stub_everything('test',
|
26
|
+
name: 'test_1_viewing_a_specific_report',
|
27
|
+
location: 'Some description',
|
28
|
+
compatriot_assertion_titles: [ 'did stuff','moar' ],
|
29
|
+
compatriot_percentages_changed: [ 0.02 , 0.04 ],
|
30
|
+
passed?: true)]
|
31
|
+
formated_tests = Compatriot::Reporter.new(tests).format(tests)
|
32
|
+
labels = formated_tests.map { |t| t[:label] }
|
33
|
+
labels.must_equal ["Some description:moar:0.04% difference","Some description:did stuff:0.02% difference"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'image paths are relative' do
|
37
|
+
tests = [stub_everything('test',
|
38
|
+
name: 'test_1_viewing_a_specific_report',
|
39
|
+
location: 'Some description',
|
40
|
+
compatriot_assertion_titles: [ 'did stuff' ],
|
41
|
+
compatriot_percentages_changed: [ 0.02 ],
|
42
|
+
passed?: true)]
|
43
|
+
formated_test = Compatriot::Reporter.new(tests).format(tests)[0]
|
44
|
+
formated_test[:control_image_path].must_equal "./tmp/test/screenshots/control/mocha::mock_viewing_a_specific_report_did_stuff.png"
|
45
|
+
formated_test[:variable_image_path].must_equal "./tmp/test/screenshots/variable/mocha::mock_viewing_a_specific_report_did_stuff.png"
|
46
|
+
formated_test[:diff_image_path].must_equal "./tmp/test/screenshots/diffs/mocha::mock_viewing_a_specific_report_did_stuff.png"
|
47
|
+
end
|
39
48
|
end
|
40
49
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
50
|
+
describe 'html file' do
|
51
|
+
REPORT_FILENAME = 'compatriot_report.html'
|
52
|
+
before do
|
53
|
+
FileUtils.rm(REPORT_FILENAME) if File.exists?(REPORT_FILENAME)
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'generates an html file' do
|
57
|
+
test1 = stub_everything('test',
|
58
|
+
name: 'test_1_viewing_a_specific_report',
|
59
|
+
location: 'Some description',
|
60
|
+
compatriot_assertion_titles: [ 'did stuff' ],
|
61
|
+
compatriot_percentages_changed: [ 0.02 ],
|
62
|
+
passed?: true)
|
63
|
+
test2 = stub_everything('test',
|
64
|
+
name: 'test_2_viewing_a_specific_report_with_a_filter',
|
65
|
+
location: 'Another description',
|
66
|
+
compatriot_assertion_titles: [ 'did other stuff' ],
|
67
|
+
compatriot_percentages_changed: [ 0.8 ],
|
68
|
+
passed?: false)
|
69
|
+
tests = [test1, test2]
|
70
|
+
Compatriot::Reporter.new(tests).run
|
71
|
+
|
72
|
+
assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
|
73
|
+
File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 2
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'generates a report even if there were not any assertions made' do
|
77
|
+
tests = [stub_everything('test',
|
78
|
+
name: 'test_1_viewing_a_specific_report',
|
79
|
+
location: 'Some description',
|
80
|
+
compatriot_assertion_titles: [ ],
|
81
|
+
compatriot_percentages_changed: [ 0.02 ],
|
82
|
+
passed?: true)
|
83
|
+
]
|
84
|
+
Compatriot::Reporter.new(tests).run
|
85
|
+
assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
|
86
|
+
File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 0
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'handles multiple assertions in one test' do
|
90
|
+
tests = [stub_everything('test',
|
91
|
+
name: 'test_1_viewing_a_specific_report',
|
92
|
+
location: 'Some description',
|
93
|
+
compatriot_assertion_titles: [ 'first assertion', 'second assertion' ],
|
94
|
+
compatriot_percentages_changed: [ 0.02 , 0.01 ],
|
95
|
+
passed?: true)
|
96
|
+
]
|
97
|
+
Compatriot::Reporter.new(tests).run
|
98
|
+
assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
|
99
|
+
File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 2
|
100
|
+
end
|
51
101
|
end
|
102
|
+
|
52
103
|
end
|