Skip to content

Commit 3878825

Browse files
justin808claude
andcommitted
Fix specs and add verbose option for pack generation
Fixes: - Add ReactOnRails::Dev module requires to main react_on_rails.rb to fix spec loading - Fix $CHILD_STATUS mocking issues by using system return values directly - Add comprehensive mocking for all pgrep patterns in kill_processes specs Enhancements: - Add --verbose/-v flag to bin/dev for detailed pack generation output - Default pack generation now shows concise "📦 Generating packs... ✅" output - Verbose mode shows full rake output for debugging - Update help documentation to include verbose option - Remove duplicate pack generation in production mode (assets:precompile handles it) Technical improvements: - Add verbose parameter to PackGenerator.generate method - Thread verbose option through ServerManager.start and run_* methods - Update all spec expectations to handle verbose parameter - Fix rubocop string concatenation warnings with interpolation - Fix unused method argument warning by prefixing with underscore 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 6d46ff1 commit 3878825

File tree

8 files changed

+69
-42
lines changed

8 files changed

+69
-42
lines changed

lib/generators/react_on_rails/base_generator.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ def append_to_spec_rails_helper
262262
else
263263
GeneratorMessages.add_info(
264264
<<-MSG.strip_heredoc
265-
266265
We did not find a spec/rails_helper.rb or spec/spec_helper.rb to add
267266
the React on Rails Test helper, which ensures that if we are running
268267
js tests, then we are using latest webpack assets. You can later add

lib/generators/react_on_rails/bin/dev

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,24 @@ rescue LoadError
2727
require_relative "../../../react_on_rails/dev"
2828
end
2929

30+
# Check for verbose flag
31+
verbose = ARGV.include?("--verbose") || ARGV.include?("-v")
32+
3033
# Main execution
3134
case ARGV[0]
3235
when "production-assets", "prod"
33-
ReactOnRails::Dev::ServerManager.start(:production_like)
36+
ReactOnRails::Dev::ServerManager.start(:production_like, verbose: verbose)
3437
when "static"
35-
ReactOnRails::Dev::ServerManager.start(:static, "Procfile.dev-static-assets")
38+
ReactOnRails::Dev::ServerManager.start(:static, "Procfile.dev-static-assets", verbose: verbose)
3639
when "kill"
3740
ReactOnRails::Dev::ServerManager.kill_processes
3841
when "help", "--help", "-h"
3942
ReactOnRails::Dev::ServerManager.show_help
4043
when "hmr", nil
41-
ReactOnRails::Dev::ServerManager.start(:development, "Procfile.dev")
44+
ReactOnRails::Dev::ServerManager.start(:development, "Procfile.dev", verbose: verbose)
45+
when "--verbose", "-v"
46+
# Handle the case where verbose is the only argument
47+
ReactOnRails::Dev::ServerManager.start(:development, "Procfile.dev", verbose: true)
4248
else
4349
puts "Unknown argument: #{ARGV[0]}"
4450
puts "Run 'bin/dev help' for usage information"

lib/react_on_rails.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@
2626
require "react_on_rails/locales/base"
2727
require "react_on_rails/locales/to_js"
2828
require "react_on_rails/locales/to_json"
29+
require "react_on_rails/dev/server_manager"
30+
require "react_on_rails/dev/process_manager"
31+
require "react_on_rails/dev/pack_generator"
32+
require "react_on_rails/dev/file_manager"

lib/react_on_rails/dev/pack_generator.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ module ReactOnRails
66
module Dev
77
class PackGenerator
88
class << self
9-
def generate
10-
puts "📦 Generating React on Rails packs..."
11-
system "bundle exec rake react_on_rails:generate_packs"
9+
def generate(verbose: false)
10+
if verbose
11+
puts "📦 Generating React on Rails packs..."
12+
success = system "bundle exec rake react_on_rails:generate_packs"
13+
else
14+
print "📦 Generating packs... "
15+
success = system "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1"
16+
puts success ? "✅" : "❌"
17+
end
1218

13-
return if $CHILD_STATUS.success?
19+
return if success
1420

1521
puts "❌ Pack generation failed"
1622
exit 1

lib/react_on_rails/dev/server_manager.rb

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ module ReactOnRails
66
module Dev
77
class ServerManager
88
class << self
9-
def start(mode = :development, procfile = nil)
9+
def start(mode = :development, procfile = nil, verbose: false)
1010
case mode
1111
when :production_like
12-
run_production_like
12+
run_production_like(_verbose: verbose)
1313
when :static
1414
procfile ||= "Procfile.dev-static-assets"
15-
run_static_development(procfile)
15+
run_static_development(procfile, verbose: verbose)
1616
when :development, :hmr
1717
procfile ||= "Procfile.dev"
18-
run_development(procfile)
18+
run_development(procfile, verbose: verbose)
1919
else
2020
raise ArgumentError, "Unknown mode: #{mode}"
2121
end
@@ -81,7 +81,7 @@ def kill_processes
8181

8282
def show_help
8383
puts <<~HELP
84-
Usage: bin/dev [command]
84+
Usage: bin/dev [command] [options]
8585
8686
Commands and their Procfiles:
8787
(none) / hmr Start development server with HMR (default)
@@ -96,6 +96,9 @@ def show_help
9696
9797
kill Kill all development processes for a clean start
9898
help Show this help message
99+
100+
Options:
101+
--verbose, -v Enable verbose output for pack generation
99102
#{' '}
100103
🔧 CUSTOMIZATION:
101104
Each mode uses a specific Procfile that you can customize for your application:
@@ -137,7 +140,7 @@ def show_help
137140

138141
private
139142

140-
def run_production_like
143+
def run_production_like(_verbose: false)
141144
procfile = "Procfile.dev-prod-assets"
142145

143146
print_procfile_info(procfile)
@@ -153,13 +156,11 @@ def run_production_like
153156
3001
154157
)
155158

156-
PackGenerator.generate
157-
158-
# Precompile assets in production mode
159+
# Precompile assets in production mode (includes pack generation automatically)
159160
puts "🔨 Precompiling assets..."
160-
system "RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile"
161+
success = system "RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile"
161162

162-
if $CHILD_STATUS.success?
163+
if success
163164
puts "✅ Assets precompiled successfully"
164165
ProcessManager.ensure_procfile(procfile)
165166
ProcessManager.run_with_process_manager(procfile)
@@ -169,7 +170,7 @@ def run_production_like
169170
end
170171
end
171172

172-
def run_static_development(procfile)
173+
def run_static_development(procfile, verbose: false)
173174
print_procfile_info(procfile)
174175
print_server_info(
175176
"⚡ Starting development server with static assets...",
@@ -182,14 +183,14 @@ def run_static_development(procfile)
182183
]
183184
)
184185

185-
PackGenerator.generate
186+
PackGenerator.generate(verbose: verbose)
186187
ProcessManager.ensure_procfile(procfile)
187188
ProcessManager.run_with_process_manager(procfile)
188189
end
189190

190-
def run_development(procfile)
191+
def run_development(procfile, verbose: false)
191192
print_procfile_info(procfile)
192-
PackGenerator.generate
193+
PackGenerator.generate(verbose: verbose)
193194
ProcessManager.ensure_procfile(procfile)
194195
ProcessManager.run_with_process_manager(procfile)
195196
end
@@ -207,22 +208,22 @@ def print_procfile_info(procfile)
207208
port = procfile == "Procfile.dev-prod-assets" ? 3001 : 3000
208209

209210
box_width = 60
210-
border = "┌" + ("─" * (box_width - 2)) + "┐"
211-
bottom = "└" + ("─" * (box_width - 2)) + "┘"
211+
border = "┌#{'─' * (box_width - 2)}┐"
212+
bottom = "└#{'─' * (box_width - 2)}┘"
212213

213214
procfile_line = "│ 📋 Using Procfile: #{procfile}"
214215
padding = box_width - procfile_line.length - 2
215-
procfile_line += (" " * padding) + "│"
216+
procfile_line += "#{' ' * padding}│"
216217

217218
access_line = "│ 💡 Access at: http://localhost:#{port}"
218219
padding = box_width - access_line.length - 2
219-
access_line += (" " * padding) + "│"
220+
access_line += "#{' ' * padding}│"
220221

221222
customize_line = "│ 🔧 Customize this file for your app's needs"
222223
padding = box_width - customize_line.length - 2
223-
customize_line += (" " * padding) + "│"
224+
customize_line += "#{' ' * padding}│"
224225

225-
empty_line = "│" + (" " * (box_width - 2)) + "│"
226+
empty_line = "│#{' ' * (box_width - 2)}│"
226227

227228
puts ""
228229
puts border

spec/react_on_rails/dev/pack_generator_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@
1717
end
1818

1919
describe ".generate" do
20-
it "runs pack generation successfully" do
20+
it "runs pack generation successfully in verbose mode" do
2121
allow_any_instance_of(Kernel).to receive(:system).with("bundle exec rake react_on_rails:generate_packs").and_return(true)
22-
allow($CHILD_STATUS).to receive(:success?).and_return(true)
2322

24-
expect { described_class.generate }.not_to raise_error
23+
expect { described_class.generate(verbose: true) }.not_to raise_error
24+
end
25+
26+
it "runs pack generation successfully in quiet mode" do
27+
allow_any_instance_of(Kernel).to receive(:system).with("bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1").and_return(true)
28+
29+
expect { described_class.generate(verbose: false) }.not_to raise_error
2530
end
2631

2732
it "exits with error when pack generation fails" do
28-
allow_any_instance_of(Kernel).to receive(:system).with("bundle exec rake react_on_rails:generate_packs").and_return(false)
29-
allow($CHILD_STATUS).to receive(:success?).and_return(false)
33+
allow_any_instance_of(Kernel).to receive(:system).with("bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1").and_return(false)
3034
expect_any_instance_of(Kernel).to receive(:exit).with(1)
3135

32-
described_class.generate
36+
described_class.generate(verbose: false)
3337
end
3438
end
3539
end

spec/react_on_rails/dev/process_manager_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
describe ".installed?" do
2020
it "returns true when process is available" do
2121
allow(IO).to receive(:popen).with("overmind -v").and_return("Some version info")
22-
expect(described_class.installed?("overmind")).to be_truthy
22+
expect(described_class).to be_installed("overmind")
2323
end
2424

2525
it "returns false when process is not available" do

spec/react_on_rails/dev/server_manager_spec.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
end
1818

1919
def mock_system_calls
20-
allow(ReactOnRails::Dev::PackGenerator).to receive(:generate)
20+
allow(ReactOnRails::Dev::PackGenerator).to receive(:generate).with(any_args)
2121
allow_any_instance_of(Kernel).to receive(:system).and_return(true)
2222
allow_any_instance_of(Kernel).to receive(:exit)
2323
allow(ReactOnRails::Dev::ProcessManager).to receive(:ensure_procfile)
@@ -52,10 +52,9 @@ def mock_system_calls
5252
end
5353

5454
it "starts production-like mode" do
55-
expect(ReactOnRails::Dev::PackGenerator).to receive(:generate)
56-
expect_any_instance_of(Kernel).to receive(:system).with("RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile")
57-
allow($CHILD_STATUS).to receive(:success?).and_return(true)
58-
expect_any_instance_of(Kernel).to receive(:system).with("RAILS_ENV=production bundle exec rails server -p 3001")
55+
expect_any_instance_of(Kernel).to receive(:system).with("RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile").and_return(true)
56+
expect(ReactOnRails::Dev::ProcessManager).to receive(:ensure_procfile).with("Procfile.dev-prod-assets")
57+
expect(ReactOnRails::Dev::ProcessManager).to receive(:run_with_process_manager).with("Procfile.dev-prod-assets")
5958

6059
described_class.start(:production_like)
6160
end
@@ -72,11 +71,19 @@ def mock_system_calls
7271
end
7372

7473
it "attempts to kill development processes" do
75-
# Mock some running processes
74+
# Mock all the pgrep patterns used in kill_processes
7675
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"rails\" 2>/dev/null").and_return("1234\n5678")
76+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"node.*react[-_]on[-_]rails\" 2>/dev/null").and_return("2345")
77+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"overmind\" 2>/dev/null").and_return("")
78+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"foreman\" 2>/dev/null").and_return("")
79+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"ruby.*puma\" 2>/dev/null").and_return("")
80+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"webpack-dev-server\" 2>/dev/null").and_return("")
81+
allow_any_instance_of(Kernel).to receive(:`).with("pgrep -f \"bin/shakapacker-dev-server\" 2>/dev/null").and_return("")
82+
7783
allow(Process).to receive(:pid).and_return(9999) # Current process PID
7884
expect(Process).to receive(:kill).with("TERM", 1234)
7985
expect(Process).to receive(:kill).with("TERM", 5678)
86+
expect(Process).to receive(:kill).with("TERM", 2345)
8087

8188
described_class.kill_processes
8289
end

0 commit comments

Comments
 (0)