Class: NoRegrets
- Inherits:
-
Object
- Object
- NoRegrets
- Defined in:
- lib/no_regrets.rb,
lib/no_regrets/image_diff.rb
Defined Under Namespace
Classes: ImageDiff, ScreenshotMismatchError
Class Method Summary collapse
Instance Method Summary collapse
- #check_screenshot_for_regressions ⇒ Object
-
#initialize(screenshot_name) ⇒ NoRegrets
constructor
A new instance of NoRegrets.
Constructor Details
#initialize(screenshot_name) ⇒ NoRegrets
Returns a new instance of NoRegrets.
36 37 38 |
# File 'lib/no_regrets.rb', line 36 def initialize(screenshot_name) @screenshot_name = screenshot_name end |
Class Method Details
.check_screenshot_for_regressions(screenshot_name) ⇒ Object
11 12 13 |
# File 'lib/no_regrets.rb', line 11 def self.check_screenshot_for_regressions(screenshot_name) new(screenshot_name).check_screenshot_for_regressions end |
Instance Method Details
#check_screenshot_for_regressions ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/no_regrets.rb', line 15 def check_screenshot_for_regressions path = Capybara.current_session.save_screenshot("#{screenshot_name}.png") sha1 = Digest::SHA1.hexdigest(File.read(path)) if !File.exists?(cache_file_path(sha1)) FileUtils.mkdir_p(cache_dir) FileUtils.cp(path, cache_file_path(sha1)) end if old_sha1 && old_sha1 != sha1 raise_error(path, sha1) end FileUtils.rm(path) if !fingerprints[screenshot_name] puts "Saving a new screenshot fingerprint for \"#{screenshot_name}\" in #{fingerprint_file_path}" end fingerprints[screenshot_name] = sha1 write_fingerprints_file(fingerprints) end |