Skip to content

Commit 91f2e16

Browse files
authored
Fix main generator pretend spec isolation (#4147)
## Why The default branch is currently failing `Rspec test for gem` on `main` in the generator shard: - Run: https://github.com/shakacode/react_on_rails/actions/runs/27869267839 - Failed jobs: `rspec-package-tests (4.0, latest, generators)` and `rspec-package-tests (3.3, minimum, generators)` - Failed example: `spec/react_on_rails/generators/install_generator_spec.rb:3717` The failure was not caused by the most recent Pro streaming PR. The same generator failure appears on the prior pushed commit and traces back to the custom Shakapacker-root generator work in #4130. A focused ordered repro showed the issue: ```bash cd react_on_rails && bundle exec rspec \ spec/react_on_rails/generators/install_generator_spec.rb:564 \ spec/react_on_rails/generators/install_generator_spec.rb:590 \ spec/react_on_rails/generators/install_generator_spec.rb:3717 ``` Before this patch, that sequence failed because earlier examples left `config/shakapacker.yml` in the shared generator destination. The pretend-mode example used `expect(File).not_to receive(:read)`, which accidentally forbade the legitimate config read used to resolve Shakapacker paths. The behavior the test meant to protect is narrower: pretend mode must not read the copied Redux Tailwind client entry, because pretend mode does not create that file. ## What changed - Adds an explicit `config/shakapacker.yml` fixture to the pretend-mode example. - Allows normal `File.read` calls while asserting the generated Redux client entry is not read. - Keeps the production generator code unchanged. ## Validation - `git diff --check` -> passed. - `cd react_on_rails && bundle exec rspec spec/react_on_rails/generators/install_generator_spec.rb:564 spec/react_on_rails/generators/install_generator_spec.rb:590 spec/react_on_rails/generators/install_generator_spec.rb:3717` -> 4 examples, 0 failures. - `cd react_on_rails && BUNDLE_GEMFILE=../Gemfile bundle exec rubocop spec/react_on_rails/generators/install_generator_spec.rb` -> 1 file inspected, no offenses. - `codex review --uncommitted` -> no actionable correctness issues. - Pre-commit hook -> trailing-newlines, Ruby autofix/RuboCop passed for the changed spec. - Pre-push hook -> branch Ruby RuboCop and markdown-links passed. ## Process triage Process Gap Disposition: `checklist+replay`. - Motivating miss: #4130 recorded focused validation for `install_generator_spec.rb:3717`, but the default-branch failure required replaying that example after earlier custom-root generator examples that leave `config/shakapacker.yml` in the shared destination. - Replay evidence: the ordered repro above failed on `main` before this patch and passed after this patch. - Non-goal: do not add a broad prose-only rule or a full generator-suite requirement for every small generator PR. Merge queue would reduce stale-base/concurrency merges, but it would not have caught this exact issue unless the queue runs the same generator shard before landing. The actionable process improvement is to include ordered replay when adding generator examples that share `dummy-for-generators`, especially when new examples leave Shakapacker config or other shared files behind. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only change to generator spec isolation; no production generator behavior modified. > > **Overview** > Fixes flaky generator CI by tightening the **pretend-mode Redux + Tailwind** example in `install_generator_spec.rb`, without changing generator code. > > The example now seeds its own `config/shakapacker.yml` so Shakapacker path resolution does not depend on leftovers from earlier examples in the shared `dummy-for-generators` destination. It stubs `File.read` with `and_call_original` and only forbids reading the Redux Tailwind client entry (`HelloWorldApp.client.jsx`), which matches the real behavior: pretend mode may read config but must not read the copied client file to inject the stylesheet import. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ace8804. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 19a01db commit 91f2e16

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

react_on_rails/spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3717,12 +3717,20 @@ class ActiveSupport::TestCase
37173717
it "does not read the copied Redux Tailwind entry in pretend mode" do
37183718
redux_generator = redux_generator_fixture(pretend: true, tailwind: true)
37193719
client_entry = "app/javascript/src/HelloWorldApp/ror_components/HelloWorldApp.client.jsx"
3720+
simulate_existing_file("config/shakapacker.yml", <<~YAML)
3721+
default: &default
3722+
source_path: app/javascript
3723+
3724+
development:
3725+
<<: *default
3726+
YAML
37203727

37213728
allow(redux_generator).to receive(:copy_file)
37223729
allow(redux_generator).to receive(:gsub_file)
37233730
allow(redux_generator).to receive(:prepend_to_file)
3731+
allow(File).to receive(:read).and_call_original
37243732

3725-
expect(File).not_to receive(:read)
3733+
expect(File).not_to receive(:read).with(File.join(destination_root, client_entry))
37263734
expect(redux_generator).to receive(:say_status)
37273735
.with(:pretend, "Would add Tailwind stylesheet import to #{client_entry}", :yellow)
37283736

0 commit comments

Comments
 (0)