Module: SnapDiff::Minitest::Assertions
- Includes:
- DSL
- Defined in:
- lib/snap_diff/integrations/minitest.rb
Instance Method Summary collapse
- #after_teardown ⇒ Object
-
#assert_matches_screenshot(*args, skip_stack_frames: 0, **opts) ⇒ Object
The
ifis the whole point (issue #270). - #before_teardown ⇒ Object
- #setup ⇒ Object
Methods included from DSL
#assert_no_screenshot_changes, #capture_screenshot, #screenshot, #screenshot_group, #screenshot_section
Instance Method Details
#after_teardown ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/snap_diff/integrations/minitest.rb', line 75 def after_teardown super # Never mask a real failure (from `verify` above or from the user's # own `teardown`) with a pending marker. if failures.empty? && (msg = @capybara_screenshot_diff_pending_message) skip(msg) end end |
#assert_matches_screenshot(*args, skip_stack_frames: 0, **opts) ⇒ Object
The if is the whole point (issue #270). super returns false
immediately when screenshots are disabled -- nothing captured,
nothing compared -- so counting unconditionally reported
1 runs, 1 assertions, 0 failures over a test that asserted
nothing at all.
Getting the count right hands the alarm to Rails for free: it
prepends ActiveSupport::Testing::TestsWithoutAssertions into every
ActiveSupport::TestCase (test_case.rb:205), which warns
"Test is missing assertions: test_x" on exactly the tests whose
sole assertion was a disabled screenshot -- and stays quiet for
tests that assert something else.
46 47 48 49 50 51 52 |
# File 'lib/snap_diff/integrations/minitest.rb', line 46 def assert_matches_screenshot(*args, skip_stack_frames: 0, **opts) self.assertions += 1 if SnapDiff.config.active? super(*args, skip_stack_frames: skip_stack_frames + 1, **opts) rescue ::SnapDiff::ExpectationNotMet => e raise ::Minitest::Assertion, e. end |
#before_teardown ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/snap_diff/integrations/minitest.rb', line 59 def before_teardown super SnapDiff.session.verify # Computed here (before teardown/reset), but the actual `skip` is # deferred to `after_teardown` so a real error raised by the user's # `teardown` isn't masked by a pending skip recorded before it ran. @capybara_screenshot_diff_pending_message = SnapDiff. rescue SnapDiff::ExpectationNotMet => e assertion = ::Minitest::Assertion.new(e) assertion.set_backtrace(e.backtrace) failures << assertion ensure SnapDiff.reset end |
#setup ⇒ Object
54 55 56 57 |
# File 'lib/snap_diff/integrations/minitest.rb', line 54 def setup super ::SnapDiff::BrowserHelpers.resize_window_if_needed end |