Skip to content

Commit 23708a4

Browse files
justin808claude
andcommitted
Fix critical missing StringIO require and test stubbing issues
This commit addresses critical issues identified in code review: 1. **Add missing StringIO require** (BLOCKER) - Added `require "stringio"` at line 4 - Required for capture_output method at line 91 - Without this, code fails at runtime in silent mode with: NameError: uninitialized constant StringIO 2. **Fix inconsistent system call stubbing in tests** - Updated "when not in Bundler context" tests to match actual implementation - Changed from string form: `system("bundle exec rake...")` - To array form: `system("bundle", "exec", "rake", ...)` - Silent mode now correctly stubs with File::NULL options - This matches the actual implementation at lines 116-121 3. **Fix Rails fallback test stubbing** - Updated "when Rails is not available" test - Now uses correct array form system call signature All tests pass (10 examples, 0 failures) RuboCop passes with no offenses 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d3fd6cb commit 23708a4

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/react_on_rails/dev/pack_generator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "English"
4+
require "stringio"
45

56
module ReactOnRails
67
module Dev

spec/react_on_rails/dev/pack_generator_spec.rb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,28 +110,36 @@
110110
end
111111

112112
it "runs pack generation successfully in verbose mode using bundle exec" do
113-
command = "bundle exec rake react_on_rails:generate_packs"
114-
allow(described_class).to receive(:system).with(command).and_return(true)
113+
allow(described_class).to receive(:system)
114+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
115+
.and_return(true)
115116

116117
expect { described_class.generate(verbose: true) }
117118
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
118119

119-
expect(described_class).to have_received(:system).with(command)
120+
expect(described_class).to have_received(:system)
121+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
120122
end
121123

122124
it "runs pack generation successfully in quiet mode using bundle exec" do
123-
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
124-
allow(described_class).to receive(:system).with(command).and_return(true)
125+
allow(described_class).to receive(:system)
126+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs",
127+
out: File::NULL, err: File::NULL)
128+
.and_return(true)
125129

126130
expect { described_class.generate(verbose: false) }
127131
.to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process
128132

129-
expect(described_class).to have_received(:system).with(command)
133+
expect(described_class).to have_received(:system)
134+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs",
135+
out: File::NULL, err: File::NULL)
130136
end
131137

132138
it "exits with error when pack generation fails" do
133-
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
134-
allow(described_class).to receive(:system).with(command).and_return(false)
139+
allow(described_class).to receive(:system)
140+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs",
141+
out: File::NULL, err: File::NULL)
142+
.and_return(false)
135143

136144
expect { described_class.generate(verbose: false) }.to raise_error(SystemExit)
137145
end
@@ -148,13 +156,15 @@
148156
end
149157

150158
it "falls back to bundle exec when Rails is not defined" do
151-
command = "bundle exec rake react_on_rails:generate_packs"
152-
allow(described_class).to receive(:system).with(command).and_return(true)
159+
allow(described_class).to receive(:system)
160+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
161+
.and_return(true)
153162

154163
expect { described_class.generate(verbose: true) }
155164
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
156165

157-
expect(described_class).to have_received(:system).with(command)
166+
expect(described_class).to have_received(:system)
167+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
158168
end
159169
end
160170
end

0 commit comments

Comments
 (0)