vulture 1.0.0 → 1.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/vulture.rb +16 -10
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef0cee7a5f14b0945b3889703b56e31eb4a8e6e958559fdc3a98cca393f1ed2f
4
- data.tar.gz: 48098329b18e07d78e76a57988024181532e38c1e785f4f361680903d2eb8b17
3
+ metadata.gz: ab1c0b8ef4cae9c39fcf0cca526d0259f6a9a85b778ff02bc6857fd556d60322
4
+ data.tar.gz: a0775c686deea416155d117b4bbad1f586ef64b540611a5879defddd8a175e67
5
5
  SHA512:
6
- metadata.gz: 53cd4a2af7dfbd5aefde0681a7d553de4337a770033cdd2db18cce5f288bf2d53972b370183d5e6bc17ed8041c73ca95155164427c3dd9613d22fc208c2c7597
7
- data.tar.gz: 88b016e1691a808aa2ca65b4e382c87ccbe0d8d061298e2c41c3dd194eaa325c64075bab837566cfce2a43abb85972072940ee79580907ae5c61e424c2559310
6
+ metadata.gz: 13673f540c542c56503e249ae14febdb26c2010a5b31e8c64566458d375cd0b1c154cc2153c3a5e3deb84d5f56d1ff65adaf2a3e163d16c1fd5cf97c3b9d652f
7
+ data.tar.gz: 94994cc6a6138848cebbd3024c00208227f74035a0a5253fc8a6a708acd8e416988f5549ef31c607f5a9b3bdd98a4acef97ca15986a1bfecdc9120cbc1f1f37a
data/vulture.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'capybara'
3
4
  require 'capybara/dsl'
4
5
  require 'selenium-webdriver'
@@ -25,6 +26,9 @@ end
25
26
  def compare_images(img1_path, img2_path, diff_output_path, threshold)
26
27
  img1 = ChunkyPNG::Image.from_file(img1_path)
27
28
  img2 = ChunkyPNG::Image.from_file(img2_path)
29
+
30
+ raise 'Images are not the same size!' unless img1.dimension == img2.dimension
31
+
28
32
  diff = ChunkyPNG::Image.new(img1.width, img1.height, ChunkyPNG::Color::TRANSPARENT)
29
33
  diff_count = 0
30
34
 
@@ -38,7 +42,7 @@ def compare_images(img1_path, img2_path, diff_output_path, threshold)
38
42
  end
39
43
 
40
44
  diff.save(diff_output_path)
41
- diff_percentage = (diff_count.to_f / (img1.width * img1.height)) * 100
45
+ diff_percentage = (diff_count.to_f / (img1.pixels.length)) * 100
42
46
 
43
47
  puts "Comparison complete: #{diff_count} pixels differ (#{diff_percentage.round(2)}%)."
44
48
  exit(1) if diff_percentage > threshold
@@ -50,25 +54,27 @@ def generate_report(diffs)
50
54
  File.open('report.html', 'w') { |file| file.write(renderer.result(binding)) }
51
55
  end
52
56
 
57
+ def formatted_path(base, resolution, url)
58
+ "#{base}/#{resolution}_#{url.gsub(%r{https?://}, '').gsub('/', '_')}.png"
59
+ end
60
+
53
61
  if ARGV.length != 2
54
62
  puts "Usage: vulture <url1> <url2>"
55
- exit
63
+ exit(1)
56
64
  end
57
65
 
58
- url1 = ARGV[0]
59
- url2 = ARGV[1]
66
+ url1, url2 = ARGV
60
67
 
61
- diffs = []
62
- config['resolutions'].each do |resolution|
63
- baseline_path = "screenshots/baseline/#{resolution}_#{url1.gsub(%r{https?://}, '').gsub('/', '_')}.png"
64
- latest_path = "screenshots/latest/#{resolution}_#{url2.gsub(%r{https?://}, '').gsub('/', '_')}.png"
65
- diff_path = "screenshots/diff/#{resolution}_#{url1.gsub(%r{https?://}, '').gsub('/', '_')}_diff.png"
68
+ diffs = config['resolutions'].map do |resolution|
69
+ baseline_path = formatted_path('screenshots/baseline', resolution, url1)
70
+ latest_path = formatted_path('screenshots/latest', resolution, url2)
71
+ diff_path = formatted_path('screenshots/diff', resolution, "#{url1}_diff")
66
72
 
67
73
  capture_screenshot(url1, resolution, baseline_path)
68
74
  capture_screenshot(url2, resolution, latest_path)
69
75
 
70
76
  compare_images(baseline_path, latest_path, diff_path, config['threshold'])
71
- diffs << { url: url1, resolution: resolution, diff_path: diff_path }
77
+ { url: url1, resolution: resolution, diff_path: diff_path }
72
78
  end
73
79
 
74
80
  generate_report(diffs)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vulture
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - zeusssz
@@ -107,7 +107,8 @@ files:
107
107
  - templates/report_template.html.erb
108
108
  - vulture.rb
109
109
  homepage:
110
- licenses: []
110
+ licenses:
111
+ - MIT
111
112
  metadata: {}
112
113
  post_install_message:
113
114
  rdoc_options: []