Skip to content

Commit 8646f7a

Browse files
committed
ci: correct rubocop offenses
1 parent f729db1 commit 8646f7a

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

lib/generators/react_on_rails/bin/dev

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ end
1010
def generate_packs
1111
puts "Generating React on Rails packs..."
1212
system "bundle exec rake react_on_rails:generate_packs"
13-
14-
unless $?.success?
15-
puts "Pack generation failed"
16-
exit 1
17-
end
13+
14+
return if $CHILD_STATUS.success?
15+
16+
puts "Pack generation failed"
17+
exit 1
1818
end
1919

2020
def run_production_like
@@ -27,22 +27,22 @@ def run_production_like
2727
puts ""
2828
puts "Access at: http://localhost:3001"
2929
puts ""
30-
30+
3131
# Generate React on Rails packs first
3232
generate_packs
33-
33+
3434
# Precompile assets in production mode
3535
puts "Precompiling assets..."
3636
system "RAILS_ENV=production NODE_ENV=production bundle exec rails assets:precompile"
37-
38-
if $?.success?
37+
38+
if $CHILD_STATUS.success?
3939
puts "Assets precompiled successfully"
4040
puts "Starting Rails server in production mode..."
4141
puts ""
4242
puts "Press Ctrl+C to stop the server"
4343
puts "To clean up: rm -rf public/packs && bin/dev"
4444
puts ""
45-
45+
4646
# Start Rails in production mode
4747
system "RAILS_ENV=production bundle exec rails server -p 3001"
4848
else
@@ -61,10 +61,10 @@ def run_static_development
6161
puts ""
6262
puts "Access at: http://localhost:3000"
6363
puts ""
64-
64+
6565
# Generate React on Rails packs first
6666
generate_packs
67-
67+
6868
if installed? "overmind"
6969
system "overmind start -f Procfile.dev-static"
7070
elsif installed? "foreman"
@@ -86,7 +86,7 @@ end
8686

8787
def run_development(process)
8888
generate_packs
89-
89+
9090
system "#{process} start -f Procfile.dev"
9191
rescue Errno::ENOENT
9292
warn <<~MSG
@@ -104,30 +104,30 @@ elsif ARGV[0] == "static"
104104
elsif ARGV[0] == "help" || ARGV[0] == "--help" || ARGV[0] == "-h"
105105
puts <<~HELP
106106
Usage: bin/dev [command]
107-
107+
108108
Commands:
109109
(none) / hmr Start development server with HMR (default)
110110
static Start development server with static assets (no HMR, no FOUC)
111111
production-assets Start with production-optimized assets (no HMR)
112112
prod Alias for production-assets
113113
help Show this help message
114-
114+
#{' '}
115115
HMR Development mode (default):
116116
- Hot Module Replacement (HMR) enabled
117117
- Automatic React on Rails pack generation
118118
- Source maps for debugging
119119
- May have Flash of Unstyled Content (FOUC)
120120
- Fast recompilation
121121
- Access at: http://localhost:3000
122-
122+
123123
Static development mode:
124124
- No HMR (static assets with auto-recompilation)
125125
- Automatic React on Rails pack generation
126126
- CSS extracted to separate files (no FOUC)
127127
- Development environment (faster builds than production)
128128
- Source maps for debugging
129129
- Access at: http://localhost:3000
130-
130+
131131
Production-like mode:
132132
- Automatic React on Rails pack generation
133133
- Optimized, minified bundles

lib/generators/react_on_rails/install_generator.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ def ensure_shakapacker_installed
102102
return if shakapacker_installed?
103103

104104
GeneratorMessages.add_info("Shakapacker not detected. Installing Shakapacker...")
105-
105+
106106
result = system("rails shakapacker:install")
107107
unless result
108-
GeneratorMessages.add_error("Failed to install Shakapacker automatically. Please run 'rails shakapacker:install' manually.")
108+
GeneratorMessages.add_error("Failed to install Shakapacker automatically. " \
109+
"Please run 'rails shakapacker:install' manually.")
109110
return
110111
end
111112

spec/react_on_rails/binstubs/dev_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def setup_script_execution
2020
# Mock ARGV to simulate no arguments (default HMR mode)
2121
stub_const("ARGV", [])
2222
# Mock pack generation
23-
allow_any_instance_of(Kernel).to receive(:system).with("bundle exec rake react_on_rails:generate_packs").and_return(true)
23+
allow_any_instance_of(Kernel).to receive(:system)
24+
.with("bundle exec rake react_on_rails:generate_packs").and_return(true)
2425
end
2526

2627
it "includes pack generation function" do
@@ -51,7 +52,7 @@ def setup_script_execution
5152
it "with Overmind installed, uses Overmind" do
5253
setup_script_execution
5354
allow(IO).to receive(:popen).with("overmind -v").and_return("Some truthy result")
54-
expect_any_instance_of(Kernel).to receive(:system).with("overmind start -f Procfile.dev").and_return(true)
55+
expect_any_instance_of(Kernel).to receive(:system).with("overmind start -f Procfile.dev")
5556

5657
load script_path
5758
end
@@ -60,7 +61,7 @@ def setup_script_execution
6061
setup_script_execution
6162
allow(IO).to receive(:popen).with("overmind -v").and_raise(Errno::ENOENT)
6263
allow(IO).to receive(:popen).with("foreman -v").and_return("Some truthy result")
63-
expect_any_instance_of(Kernel).to receive(:system).with("foreman start -f Procfile.dev").and_return(true)
64+
expect_any_instance_of(Kernel).to receive(:system).with("foreman start -f Procfile.dev")
6465

6566
load script_path
6667
end

spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,23 @@
134134
context "when detecting Shakapacker installation" do
135135
let(:install_generator) { described_class.new }
136136

137-
context "shakapacker_installed?" do
137+
context "when testing shakapacker_installed?" do
138138
specify "when Shakapacker gem is installed" do
139-
mock_gem = double("gem_spec", version: double("version", segments: [7, 0, 0]))
139+
mock_version = instance_double(Gem::Version, segments: [7, 0, 0])
140+
mock_gem = instance_double(Gem::Specification, version: mock_version)
140141
allow(Gem::Specification).to receive(:find_by_name).with("shakapacker").and_return(mock_gem)
141142
expect(install_generator.send(:shakapacker_installed?)).to be true
142143
end
143144

144145
specify "when Shakapacker gem is not installed" do
145-
allow(Gem::Specification).to receive(:find_by_name).with("shakapacker").and_raise(Gem::MissingSpecError.new("gem", "spec"))
146+
allow(Gem::Specification).to receive(:find_by_name).with("shakapacker").and_raise(Gem::MissingSpecError.new(
147+
"gem", "spec"
148+
))
146149
expect(install_generator.send(:shakapacker_installed?)).to be false
147150
end
148151
end
149152

150-
context "ensure_shakapacker_installed" do
153+
context "when testing ensure_shakapacker_installed" do
151154
specify "when Shakapacker is already installed" do
152155
allow(install_generator).to receive(:shakapacker_installed?).and_return(true)
153156
expect(install_generator).not_to receive(:system)
@@ -166,7 +169,9 @@
166169
allow(install_generator).to receive(:shakapacker_installed?).and_return(false)
167170
allow(install_generator).to receive(:system).with("rails shakapacker:install").and_return(false)
168171
expect(GeneratorMessages).to receive(:add_info).with("Shakapacker not detected. Installing Shakapacker...")
169-
expect(GeneratorMessages).to receive(:add_error).with("Failed to install Shakapacker automatically. Please run 'rails shakapacker:install' manually.")
172+
expect(GeneratorMessages).to receive(:add_error)
173+
.with("Failed to install Shakapacker automatically. " \
174+
"Please run 'rails shakapacker:install' manually.")
170175
install_generator.send(:ensure_shakapacker_installed)
171176
end
172177
end

0 commit comments

Comments
 (0)