Skip to content

feat: add Diff.configure helper, CI defaults, and Quick Setup docs#158

Merged
pftg merged 4 commits into
masterfrom
feature/configure-helper-and-docs
Apr 11, 2026
Merged

feat: add Diff.configure helper, CI defaults, and Quick Setup docs#158
pftg merged 4 commits into
masterfrom
feature/configure-helper-and-docs

Conversation

@pftg

@pftg pftg commented Apr 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add Capybara::Screenshot::Diff.configure block helper — replaces 50-line setup files with a clean 10-line block
  • Default fail_if_new to ENV['CI'].present? — zero-config CI behavior matching every downstream project's pattern
  • Add Quick Setup guide to README with configure example
  • Add recommended tolerance values table (VIPS vs ChunkyPNG per use case)
  • Document that enabled = false is sufficient (no need for no-op monkey-patching)

Usage

Capybara::Screenshot::Diff.configure do |screenshot, diff|
  screenshot.window_size = [1280, 1024]
  screenshot.stability_time_limit = 1
  screenshot.blur_active_element = true
  diff.driver = :vips
  diff.tolerance = 0.0005
  diff.color_distance_limit = 15
end

Test plan

  • Unit tests pass (158 runs, 0 failures)
  • Full suite passes (184 runs, 0 failures)
  • Configure helper verified with manual integration test
  • No breaking changes — all existing mattr_accessor API still works

🤖 Generated with Claude Code

Summary by Sourcery

Introduce a top-level configuration helper for Capybara::Screenshot::Diff and document recommended defaults for common visual testing setups.

New Features:

  • Add Capybara::Screenshot::Diff.configure helper to centralize screenshot and diff configuration.

Enhancements:

  • Change the default fail_if_new behavior to enable failures automatically in CI environments based on ENV['CI'].

Documentation:

  • Add a Quick Setup section to the README showing the new configure helper and typical settings.
  • Document recommended tolerance and stability values for common use cases and clarify how to fully disable screenshots.

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added Quick Setup section with configuration examples and recommended tolerance values table for common use cases.
  • New Features

    • Added configure method for centralized configuration of screenshot and diff settings.
    • Enabled "fail if new" behavior automatically in CI environments.

pftg and others added 3 commits April 12, 2026 00:24
New screenshots are now automatically rejected in CI (when ENV['CI']
is present), matching the pattern every downstream project uses.
Can still be overridden with explicit `fail_if_new = false`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replaces 50-line setup files with a clean block:

  Capybara::Screenshot::Diff.configure do |screenshot, diff|
    screenshot.window_size = [1280, 1024]
    diff.driver = :vips
    diff.tolerance = 0.0005
  end

Yields Screenshot and Diff modules directly — no new config object,
no breaking changes, works with all existing mattr_accessors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Document Diff.configure block helper with full example
- Add recommended tolerance values table per driver and use case
- Note that fail_if_new auto-detects CI environments
- Clarify that enabled=false is sufficient (no no-op monkey-patching needed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduces a new Capybara::Screenshot::Diff.configure helper for centralized configuration, changes the default fail_if_new behavior to depend on the CI environment variable, and updates the README with a Quick Setup section and recommended tolerance settings documentation.

Sequence diagram for CI-dependent fail_if_new behavior during visual diff

sequenceDiagram
  title Visual diff run with CI dependent fail_if_new
  actor Developer
  participant TestRunner
  participant Capybara_Screenshot_Diff as Capybara_Screenshot_Diff
  participant Env as ENV

  Developer->>TestRunner: run test suite
  TestRunner->>Capybara_Screenshot_Diff: initialize configuration
  Capybara_Screenshot_Diff->>Env: read CI
  alt CI set
    Env-->>Capybara_Screenshot_Diff: CI=present
    Capybara_Screenshot_Diff-->>Capybara_Screenshot_Diff: fail_if_new = true
  else CI not set
    Env-->>Capybara_Screenshot_Diff: CI=nil
    Capybara_Screenshot_Diff-->>Capybara_Screenshot_Diff: fail_if_new = false
  end
  TestRunner->>Capybara_Screenshot_Diff: compare screenshot
  alt new screenshot created
    Capybara_Screenshot_Diff-->>TestRunner: raise failure if fail_if_new
  else existing screenshot
    Capybara_Screenshot_Diff-->>TestRunner: proceed normally
  end
Loading

Class diagram for Capybara::Screenshot::Diff configure helper and fail_if_new default

classDiagram
  class Capybara
  class Capybara_Screenshot
  class Capybara_Screenshot_Diff {
    <<module>>
    +Boolean delayed
    +Integer area_size_limit
    +Boolean fail_if_new
    +Boolean fail_on_difference
    +Integer color_distance_limit
    +Boolean enabled
    +Symbol driver
    +Float tolerance
    +Hash default_options()
    +void configure(screenshot, diff)
  }
  class Capybara_Screenshot_Screenshot {
    <<module>>
    +Array window_size
    +Integer stability_time_limit
    +Boolean blur_active_element
    +Boolean hide_caret
  }

  Capybara o-- Capybara_Screenshot
  Capybara_Screenshot o-- Capybara_Screenshot_Diff
  Capybara_Screenshot o-- Capybara_Screenshot_Screenshot

  %% configure yields these two modules
  Capybara_Screenshot_Diff ..> Capybara_Screenshot_Screenshot : yields_in_configure
Loading

File-Level Changes

Change Details Files
Add Capybara::Screenshot::Diff.configure helper for centralized configuration of screenshot and diff settings.
  • Introduce a configure class method on Capybara::Screenshot::Diff that yields Screenshot and Diff to a block
  • Document the configure helper usage with an example configuration block
  • Encapsulate existing mattr_accessor-based configuration into a cleaner, single entry point API
lib/capybara_screenshot_diff.rb
README.md
Default fail_if_new to true in CI environments based on ENV['CI'].
  • Change the fail_if_new mattr_accessor default from false to ENV['CI'].present? to align behavior with CI expectations
  • Document the new fail_if_new CI default behavior in the README Quick Setup section
lib/capybara_screenshot_diff.rb
README.md
Improve documentation with Quick Setup instructions and recommended tolerance values.
  • Add a Quick Setup section showing how to configure common settings via the new configure helper
  • Add notes clarifying CI behavior for new screenshots and how to fully disable screenshots using enabled = false
  • Add a recommended tolerance values table comparing VIPS and ChunkyPNG settings for common use cases
README.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Apr 11, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The pull request enhances configuration capabilities and CI-aware behavior for the Capybara screenshot diff library. It introduces a new configure method for grouped configuration of screenshot and diff settings, changes the default fail_if_new behavior to be CI-aware (enabled when ENV["CI"] is present), adds documentation for the new configuration patterns, and updates test infrastructure to properly manage the fail_if_new flag during test execution.

Changes

Cohort / File(s) Summary
Configuration & Documentation
README.md, lib/capybara_screenshot_diff.rb
Added "Quick Setup" documentation with configuration options and tolerance recommendations. Introduced new public Capybara::Screenshot::Diff.configure method for grouped configuration. Changed fail_if_new default from false to ENV["CI"].present? to enable CI-aware behavior.
Test Infrastructure
test/test_helper.rb
Added setup and teardown hooks to ActiveSupport::TestCase that save/disable and restore the fail_if_new flag during test execution, preventing test failures from missing baseline screenshots.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A config method hops into view,
Where Screenshot and Diff both debut,
CI knows when to fail,
Tests won't derail,
New baselines? That's all for you! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: a new Diff.configure helper method, CI-aware defaults for fail_if_new, and documentation updates to the README with setup guidance.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/configure-helper-and-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Tests create new screenshots without baselines, so fail_if_new must
be false during test runs. The new CI-aware default (ENV['CI']) would
otherwise break all tests that capture new screenshots.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pftg pftg force-pushed the feature/configure-helper-and-docs branch from db9f5bd to 923d1f6 Compare April 11, 2026 22:33
@pftg pftg merged commit 5e4f8b1 into master Apr 11, 2026
6 of 7 checks passed
@pftg pftg deleted the feature/configure-helper-and-docs branch April 11, 2026 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant