Skip to content

Commit 5ec7f8c

Browse files
justin808claude
andcommitted
Address PR #1907 code review feedback
Fix two critical issues identified in code review: 1. Add missing StringIO require to prevent runtime errors in Ruby 3.0+ - StringIO is not auto-loaded in Ruby 3.0+ and was being used in capture_output method without being explicitly required - This could cause NameError when running in silent mode 2. Update test suite to handle both execution paths - Previous tests only stubbed system calls but didn't account for the new Bundler context detection logic - Split tests into two contexts: Bundler context (direct Rake) and non-Bundler context (bundle exec) - Each context now properly stubs the appropriate execution method All tests pass and RuboCop shows no violations. Related to: #1907 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2849a87 commit 5ec7f8c

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
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: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,65 @@
55

66
RSpec.describe ReactOnRails::Dev::PackGenerator do
77
describe ".generate" do
8-
it "runs pack generation successfully in verbose mode" do
9-
command = "bundle exec rake react_on_rails:generate_packs"
10-
allow(described_class).to receive(:system).with(command).and_return(true)
8+
context "when in Bundler context with Rails available" do
9+
before do
10+
stub_const("Bundler", Module.new)
11+
allow(ENV).to receive(:[]).and_call_original
12+
allow(ENV).to receive(:[]).with("BUNDLE_GEMFILE").and_return("/path/to/Gemfile")
13+
allow(described_class).to receive(:rails_available?).and_return(true)
14+
end
1115

12-
expect { described_class.generate(verbose: true) }
13-
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
14-
end
16+
it "runs pack generation successfully in verbose mode using direct rake execution" do
17+
allow(described_class).to receive(:run_rake_task_directly).and_return(true)
18+
19+
expect { described_class.generate(verbose: true) }
20+
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
21+
expect(described_class).to have_received(:run_rake_task_directly)
22+
end
23+
24+
it "runs pack generation successfully in quiet mode using direct rake execution" do
25+
allow(described_class).to receive(:run_rake_task_directly).and_return(true)
1526

16-
it "runs pack generation successfully in quiet mode" do
17-
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
18-
allow(described_class).to receive(:system).with(command).and_return(true)
27+
expect { described_class.generate(verbose: false) }
28+
.to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process
29+
expect(described_class).to have_received(:run_rake_task_directly)
30+
end
1931

20-
expect { described_class.generate(verbose: false) }
21-
.to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process
32+
it "exits with error when pack generation fails" do
33+
allow(described_class).to receive(:run_rake_task_directly).and_return(false)
34+
35+
expect { described_class.generate(verbose: false) }.to raise_error(SystemExit)
36+
end
2237
end
2338

24-
it "exits with error when pack generation fails" do
25-
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
26-
allow(described_class).to receive(:system).with(command).and_return(false)
39+
context "when not in Bundler context" do
40+
before do
41+
stub_const("Bundler", nil) unless defined?(Bundler)
42+
allow(described_class).to receive(:should_run_directly?).and_return(false)
43+
end
44+
45+
it "runs pack generation successfully in verbose mode using bundle exec" do
46+
command = "bundle exec rake react_on_rails:generate_packs"
47+
allow(described_class).to receive(:system).with(command).and_return(true)
48+
49+
expect { described_class.generate(verbose: true) }
50+
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
51+
end
52+
53+
it "runs pack generation successfully in quiet mode using bundle exec" do
54+
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
55+
allow(described_class).to receive(:system).with(command).and_return(true)
56+
57+
expect { described_class.generate(verbose: false) }
58+
.to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process
59+
end
60+
61+
it "exits with error when pack generation fails" do
62+
command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
63+
allow(described_class).to receive(:system).with(command).and_return(false)
2764

28-
expect { described_class.generate(verbose: false) }.to raise_error(SystemExit)
65+
expect { described_class.generate(verbose: false) }.to raise_error(SystemExit)
66+
end
2967
end
3068
end
3169
end

0 commit comments

Comments
 (0)