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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03a6a30cd248410ffde17ee0a7b100d6c11dff32
4
- data.tar.gz: e2e408ce4c75e59a63ab44d753ac66ab67e896f9
3
+ metadata.gz: 75b88eb52e8a954c774264cd033b8a9c65b62de0
4
+ data.tar.gz: 960e215f8c4cdba3a3f83a4e6b5cba92aab7b609
5
5
  SHA512:
6
- metadata.gz: 3d95580e8525e8149df37e6060fe84444d5f29e90eaf88974c546dede2c81b3896343e63b3c25e78c51cf19a52944e31f37accaf60a11b6b0f1e62764feafaa6
7
- data.tar.gz: d5f798d603913260cbe8f235d7b795903598b3e8bca3eb20c14e92ec20c744debc80c5ec4913a5a1a76f096e11abe32ad2c55a0aec8b1dfa5ba3d88c0584e3f4
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
- - if test.respond_to? :compatriot_assertion_titles
31
- - test.compatriot_assertion_titles.each_with_index do |title,j|
32
- %label.collapse{ for: "_#{i}.#{j}", class: ("failed" unless test.passed?) }= test.location + ":" + title
33
- %input{id: "_#{i}.#{j}", type: "checkbox"}
34
- %div
35
- %table
36
- %tbody
37
- %tr
38
- %td
39
- %label.bold Control
40
- %img{src: Compatriot.filepath_for_screenshot('control', Compatriot.filename_for_test(test, title))}
41
- %td
42
- %label.bold Variable
43
- %img{src: Compatriot.filepath_for_screenshot('variable', Compatriot.filename_for_test(test, title))}
44
- %td
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]}
@@ -9,11 +9,30 @@ module Compatriot
9
9
  end
10
10
 
11
11
  def run
12
- $tests = tests.sort_by {|t| (t.passed? ? 1 : 0) }
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
@@ -1,3 +1,3 @@
1
1
  module Compatriot
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -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
- @screenshot_directory = 'tmp/test_configuration'
67
- @control_file = @screenshot_directory + '/control/' + CONTROL_IMG_FILENAME
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
@@ -1,52 +1,103 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  describe Compatriot::Reporter do
4
- REPORT_FILENAME = 'compatriot_report.html'
5
- before do
6
- FileUtils.rm(REPORT_FILENAME) if File.exists?(REPORT_FILENAME)
7
- end
4
+ describe 'tests format' do
8
5
 
9
- it 'generates an html file' do
10
- test1 = stub_everything('test',
11
- name: 'test_1_viewing_a_specific_report',
12
- location: 'Some description',
13
- compatriot_assertion_titles: [ 'did stuff' ],
14
- passed?: true)
15
- test2 = stub_everything('test',
16
- name: 'test_2_viewing_a_specific_report_with_a_filter',
17
- location: 'Another description',
18
- compatriot_assertion_titles: [ 'did other stuff' ],
19
- passed?: false)
20
- tests = [
21
- test1, test2
22
- ]
23
- Compatriot::Reporter.new(tests).run
24
-
25
- assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
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
- it 'generates a report even if there were not any assertions made' do
30
- tests = [stub_everything('test',
31
- name: 'test_1_viewing_a_specific_report',
32
- location: 'Some description',
33
- compatriot_assertion_titles: [ ],
34
- passed?: true)
35
- ]
36
- Compatriot::Reporter.new(tests).run
37
- assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
38
- File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 0
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
- it 'handles multiple assertions in one test' do
42
- tests = [stub_everything('test',
43
- name: 'test_1_viewing_a_specific_report',
44
- location: 'Some description',
45
- compatriot_assertion_titles: [ 'first assertion', 'second assertion' ],
46
- passed?: true)
47
- ]
48
- Compatriot::Reporter.new(tests).run
49
- assert File.exist?(REPORT_FILENAME), "#{REPORT_FILENAME} not found"
50
- File.readlines(REPORT_FILENAME).grep(/label class='collapse/).count.must_equal 2
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
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.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carol (Nichols || Goulding)