Skip to content

Conversation

@arielj
Copy link

@arielj arielj commented Jan 5, 2026

This PR has a small change to allow using a different Rails environment for the server started by Cypress.

The reason for this is that it's common to have some things disabled for unit tests when running in the test environment and we don't want to disable them for the e2e tests. I know something could be achieved in some cases using the ENV["CYPRESS"] env variable, but that would only apply for code that runs after that env variable is set. If we want to add some gem only when running e2e tests and not for other tests we can't do this currently.

With this change we could have gems in an e2e group when needed, and then run RAILS_ENV=e2e rails cypress:run.

More context:

I found this issue with this sample app https://github.com/fastruby/coverage-with-cypress-sample-app. I'm using Coverband to calculate the Ruby code coverage after running the Cypress tests, but since it runs in the test environment, Coverband is also initialized for the rails test Minitest test suite and an error shows up at the end:

E, [2026-01-02T16:29:34.221521 #322239] ERROR -- : coverage failed to store
E, [2026-01-02T16:29:34.221579 #322239] ERROR -- : Coverband Error: #<RuntimeError: coverage measurement is not enabled> coverage measurement is not enabled

With the change of this PR, I can add the coverband gem in an e2e group so it works properly without being loaded for minitest.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed server initialization to respect pre-existing RAILS_ENV configuration instead of unconditionally overriding it, allowing users to specify their preferred environment settings during startup.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 5, 2026

Walkthrough

The initialization of the RAILS_ENV environment variable in the Cypress on Rails server was modified from unconditional assignment to conditional assignment using the ||= operator, preserving any pre-existing RAILS_ENV configuration.

Changes

Cohort / File(s) Summary
Environment Variable Initialization
lib/cypress_on_rails/server.rb
Changed ENV['RAILS_ENV'] = 'test' to `ENV['RAILS_ENV']

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A tiny hop, a conditional change,
No more overrides that feel so strange!
With ||= the Rails env stays true,
Just set to 'test' when it's not in view,
One line of care for consistency's sake! 🌱

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main change: preventing RAILS_ENV override when already defined, which is the primary objective of the PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba1ba4 and b2f8ef8.

📒 Files selected for processing (1)
  • lib/cypress_on_rails/server.rb
🔇 Additional comments (1)
lib/cypress_on_rails/server.rb (1)

72-72: Use ||= to allow custom Rails environments.

The change correctly implements conditional assignment: defaults to 'test' when not set, but respects any pre-existing RAILS_ENV value (e.g., RAILS_ENV=e2e rails cypress:run). The Rails server spawned at line 101 will honor this configuration. No conflicts with other code paths.


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.

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