Class: SnapDiff::ScreenshotMatcher
- Inherits:
-
Object
- Object
- SnapDiff::ScreenshotMatcher
- Defined in:
- lib/snap_diff/screenshot_matcher.rb
Instance Attribute Summary collapse
-
#driver_options ⇒ Object
readonly
Returns the value of attribute driver_options.
-
#record_mode ⇒ Object
readonly
Returns the value of attribute record_mode.
-
#screenshot_format ⇒ Object
readonly
Returns the value of attribute screenshot_format.
-
#screenshot_full_name ⇒ Object
readonly
Returns the value of attribute screenshot_full_name.
Instance Method Summary collapse
- #build_screenshot_assertion(skip_stack_frames: 0) ⇒ Object
-
#capture ⇒ Object
Captures a screenshot without comparing it to a baseline.
-
#initialize(screenshot_full_name, options = {}) ⇒ ScreenshotMatcher
constructor
A new instance of ScreenshotMatcher.
Constructor Details
#initialize(screenshot_full_name, options = {}) ⇒ ScreenshotMatcher
Returns a new instance of ScreenshotMatcher.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 17 def initialize(screenshot_full_name, = {}) @screenshot_full_name = screenshot_full_name # BEFORE the merge below -- see SnapDiff.compare. Afterwards `:driver` # is present for every caller and proves nothing. Removal.warn_once(:driver_setting, Removal::DRIVER_REMOVED) if .key?(:driver) @driver_options = SnapDiff.config..merge() # `record:` is a workflow mode, not a capture or comparison option, so # it is carved out here rather than added to Comparison::KNOWN_OPTIONS # -- a key that hash accepts and nothing downstream reads is the # silent no-op ADR-010 forbids. Deleted before anything else touches # the hash, so no later split has to know about it. @record_mode = resolve_record_mode(@driver_options.delete(:record)) @screenshot_format = @driver_options[:screenshot_format] @snapshot = SnapDiff::SnapManager.snapshot(screenshot_full_name, @screenshot_format) end |
Instance Attribute Details
#driver_options ⇒ Object (readonly)
Returns the value of attribute driver_options.
15 16 17 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 15 def @driver_options end |
#record_mode ⇒ Object (readonly)
Returns the value of attribute record_mode.
15 16 17 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 15 def record_mode @record_mode end |
#screenshot_format ⇒ Object (readonly)
Returns the value of attribute screenshot_format.
15 16 17 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 15 def screenshot_format @screenshot_format end |
#screenshot_full_name ⇒ Object (readonly)
Returns the value of attribute screenshot_full_name.
15 16 17 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 15 def screenshot_full_name @screenshot_full_name end |
Instance Method Details
#build_screenshot_assertion(skip_stack_frames: 0) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 35 def build_screenshot_assertion(skip_stack_frames: 0) # Here rather than in #initialize, so it covers exactly the path where # `:all` means anything. #capture never compares against a baseline, so # the mode has nothing to say about it and refusing there would be a # failure invented out of a setting that changes nothing. refuse_bulk_record_under_ci! if record_mode == :all Capture::Viewport.prepare!(SnapDiff.config.window_size) check_base_screenshot , = () capture_screenshot(, ) # AFTER the capture, so the path the message tells the user to # `git add` is one that exists by the time they read it (#260). fail_if_new_screenshot # Pre-computation: No need to compare without base screenshot # NOTE: Consider to return PreValid Assertion Value Object with hard coded valid result unless need_to_compare? record_uncompared_screenshot return end create_screenshot_assertion(skip_stack_frames + 1, ) end |
#capture ⇒ Object
Captures a screenshot without comparing it to a baseline.
65 66 67 68 69 70 71 72 73 |
# File 'lib/snap_diff/screenshot_matcher.rb', line 65 def capture Capture::Viewport.prepare!(SnapDiff.config.window_size) , = () @snapshot.manager.create_output_directory_for(@snapshot.path) capture_screenshot(, ) end |