Skip to content

fix: remove ActiveSupport dependency from fail_if_new default#165

Merged
pftg merged 1 commit into
masterfrom
fix/present-without-activesupport
Apr 12, 2026
Merged

fix: remove ActiveSupport dependency from fail_if_new default#165
pftg merged 1 commit into
masterfrom
fix/present-without-activesupport

Conversation

@pftg

@pftg pftg commented Apr 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

ENV["CI"].present? crashes with NoMethodError: undefined method 'present?' for nil when the gem is loaded before ActiveSupport core extensions (e.g., in non-Rails projects or projects that load gems before Rails).

Replace with plain Ruby: !ENV["CI"].nil? && !ENV["CI"].empty?

Found by

Real-world integration testing with jetthoughts.github.io (Hugo static site with Capybara screenshot tests).

Test plan

  • Unit tests pass (175 runs, 0 failures)
  • jetthoughts.github.io tests pass (26 runs, 0 failures)

🤖 Generated with Claude Code

Summary by Sourcery

Bug Fixes:

  • Prevent NoMethodError when loading the gem in environments without ActiveSupport by avoiding use of present? on ENV["CI"].

Summary by CodeRabbit

  • Refactor
    • Updated environment variable detection logic for CI environment compatibility. The change simplifies how the system determines whether to fail on new screenshots, removing dependency on Rails-specific helper methods in favor of explicit standard checks.

ENV["CI"].present? crashes when ActiveSupport core extensions aren't
loaded yet. Discovered when integrating with jetthoughts.github.io
which loads the gem before Rails. Use plain Ruby nil/empty check.

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

sourcery-ai Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replaces the default value of the fail_if_new configuration from an ActiveSupport-dependent ENV["CI"].present? to a plain Ruby check that works without ActiveSupport, avoiding crashes in non-Rails or early-load environments.

Class diagram for Diff configuration attributes change

classDiagram
  class CapybaraScreenshotDiff {
  }

  class Diff {
    <<module>>
    +Boolean delayed
    +Integer area_size_limit
    +Boolean fail_if_new
    +Boolean fail_on_difference
    +Integer color_distance_limit
    +Boolean enabled
  }

  CapybaraScreenshotDiff <|-- Diff

  class FailIfNewDefaultBefore {
    <<value_object>>
    +Boolean value
    +Boolean evaluate()
  }

  class FailIfNewDefaultAfter {
    <<value_object>>
    +Boolean value
    +Boolean evaluate(env_CI)
  }

  Diff --> FailIfNewDefaultBefore : previous_default
  Diff --> FailIfNewDefaultAfter : new_default
Loading

File-Level Changes

Change Details Files
Remove ActiveSupport dependency from the default initialization of the fail_if_new configuration flag.
  • Change the fail_if_new default block from using ENV["CI"].present? to a plain Ruby nil/empty? check on the CI environment variable.
  • Ensure the configuration still defaults to true when ENV["CI"] is a non-empty string and false otherwise, without relying on ActiveSupport core extensions.
lib/capybara_screenshot_diff.rb

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 12, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c33e281-53ca-45e1-b002-45fdae5ae5db

📥 Commits

Reviewing files that changed from the base of the PR and between 861183f and b2ce286.

📒 Files selected for processing (1)
  • lib/capybara_screenshot_diff.rb

📝 Walkthrough

Walkthrough

This change replaces the Rails present? method with an explicit nil and empty-string check for evaluating the CI environment variable. The default value for Capybara::Screenshot::Diff.fail_if_new now uses a direct condition instead of relying on ActiveSupport.

Changes

Cohort / File(s) Summary
Environment Variable Evaluation
lib/capybara_screenshot_diff.rb
Updated default fail_if_new to replace ENV["CI"].present? with !ENV["CI"].nil? && !ENV["CI"].empty?, removing dependency on ActiveSupport's present? method while preserving the same logical behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A single line changed, so lean and so clean,
No Rails' present? here—just logic precise,
CI checks explicit, no magic between,
Simplicity reigns, and that's quite nice!

🚥 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 clearly and accurately summarizes the main change: removing ActiveSupport dependency from the fail_if_new default value by replacing ENV["CI"].present? with plain Ruby equivalents.
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 fix/present-without-activesupport

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 found 1 issue, and left some high level feedback:

  • The fail_if_new default can be simplified and made more idiomatic Ruby by relying on truthiness or to_s, e.g. mattr_accessor(:fail_if_new) { !ENV['CI'].to_s.empty? } or mattr_accessor(:fail_if_new) { ENV['CI'] && !ENV['CI'].empty? }, which avoids the explicit nil check.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `fail_if_new` default can be simplified and made more idiomatic Ruby by relying on truthiness or `to_s`, e.g. `mattr_accessor(:fail_if_new) { !ENV['CI'].to_s.empty? }` or `mattr_accessor(:fail_if_new) { ENV['CI'] && !ENV['CI'].empty? }`, which avoids the explicit nil check.

## Individual Comments

### Comment 1
<location path="lib/capybara_screenshot_diff.rb" line_range="66" />
<code_context>
       mattr_accessor(:delayed) { true }
       mattr_accessor :area_size_limit
-      mattr_accessor(:fail_if_new) { ENV["CI"].present? }
+      mattr_accessor(:fail_if_new) { !ENV["CI"].nil? && !ENV["CI"].empty? }
       mattr_accessor(:fail_on_difference) { true }
       mattr_accessor :color_distance_limit
</code_context>
<issue_to_address>
**issue:** Whitespace-only CI values now count as "present", which slightly changes previous behavior.

This now treats whitespace-only values (e.g., `" "`) as truthy, whereas `ENV["CI"].present?` did not. If that’s not intended, you could mimic the old behavior with something like `ENV["CI"].to_s.strip != ""`. If it is intended, consider confirming that no CI setup relies on `CI` being set to whitespace-only values.
</issue_to_address>

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.

Comment thread lib/capybara_screenshot_diff.rb
@pftg pftg merged commit a960612 into master Apr 12, 2026
7 checks passed
@pftg pftg deleted the fix/present-without-activesupport branch April 12, 2026 02:07
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