fix: remove ActiveSupport dependency from fail_if_new default#165
Conversation
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>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideReplaces the default value of the Class diagram for Diff configuration attributes changeclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis change replaces the Rails Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
fail_if_newdefault can be simplified and made more idiomatic Ruby by relying on truthiness orto_s, e.g.mattr_accessor(:fail_if_new) { !ENV['CI'].to_s.empty? }ormattr_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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Summary
ENV["CI"].present?crashes withNoMethodError: undefined method 'present?' for nilwhen 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
🤖 Generated with Claude Code
Summary by Sourcery
Bug Fixes:
Summary by CodeRabbit