Skip to content

Commit 41fed56

Browse files
justin808claude
andcommitted
Update generator tests for new Shakapacker installation implementation
- Fix test expectations to match bundle add + bundle exec rails shakapacker:install - Update message expectations to match new multi-line messaging - Add tests for new failure scenarios (bundle add failure vs install failure) - Verify boolean return values from ensure_shakapacker_installed method Tests now accurately reflect the improved Shakapacker auto-installation flow. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 50f012d commit 41fed56

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

spec/react_on_rails/generators/install_generator_spec.rb

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,25 +130,55 @@
130130
specify "when Shakapacker is already installed" do
131131
allow(install_generator).to receive(:shakapacker_installed?).and_return(true)
132132
expect(install_generator).not_to receive(:system)
133-
install_generator.send(:ensure_shakapacker_installed)
133+
result = install_generator.send(:ensure_shakapacker_installed)
134+
expect(result).to be true
134135
end
135136

136137
specify "when Shakapacker is not installed and install succeeds" do
137138
allow(install_generator).to receive(:shakapacker_installed?).and_return(false)
138-
allow(install_generator).to receive(:system).with("rails shakapacker:install").and_return(true)
139-
expect(GeneratorMessages).to receive(:add_info).with("Shakapacker not detected. Installing Shakapacker...")
139+
allow(install_generator).to receive(:system).with("bundle", "add", "shakapacker").and_return(true)
140+
allow(install_generator).to receive(:system).with("bundle", "exec", "rails", "shakapacker:install").and_return(true)
141+
expect(GeneratorMessages).to receive(:add_info).with(<<~MSG.strip)
142+
Shakapacker gem not found in your Gemfile.
143+
React on Rails requires Shakapacker for webpack integration.
144+
Adding 'shakapacker' gem to your Gemfile and running installation...
145+
MSG
140146
expect(GeneratorMessages).to receive(:add_info).with("Shakapacker installed successfully!")
141-
install_generator.send(:ensure_shakapacker_installed)
147+
result = install_generator.send(:ensure_shakapacker_installed)
148+
expect(result).to be true
142149
end
143150

144-
specify "when Shakapacker is not installed and install fails" do
151+
specify "when Shakapacker is not installed and bundle add fails" do
145152
allow(install_generator).to receive(:shakapacker_installed?).and_return(false)
146-
allow(install_generator).to receive(:system).with("rails shakapacker:install").and_return(false)
147-
expect(GeneratorMessages).to receive(:add_info).with("Shakapacker not detected. Installing Shakapacker...")
148-
expect(GeneratorMessages).to receive(:add_error)
149-
.with("Failed to install Shakapacker automatically. " \
150-
"Please run 'rails shakapacker:install' manually.")
151-
install_generator.send(:ensure_shakapacker_installed)
153+
allow(install_generator).to receive(:system).with("bundle", "add", "shakapacker").and_return(false)
154+
expect(GeneratorMessages).to receive(:add_info).with(<<~MSG.strip)
155+
Shakapacker gem not found in your Gemfile.
156+
React on Rails requires Shakapacker for webpack integration.
157+
Adding 'shakapacker' gem to your Gemfile and running installation...
158+
MSG
159+
expect(GeneratorMessages).to receive(:add_error).with(<<~MSG.strip)
160+
Failed to add Shakapacker to your Gemfile.
161+
Please run 'bundle add shakapacker' manually and re-run the generator.
162+
MSG
163+
result = install_generator.send(:ensure_shakapacker_installed)
164+
expect(result).to be false
165+
end
166+
167+
specify "when Shakapacker is not installed and shakapacker:install fails" do
168+
allow(install_generator).to receive(:shakapacker_installed?).and_return(false)
169+
allow(install_generator).to receive(:system).with("bundle", "add", "shakapacker").and_return(true)
170+
allow(install_generator).to receive(:system).with("bundle", "exec", "rails", "shakapacker:install").and_return(false)
171+
expect(GeneratorMessages).to receive(:add_info).with(<<~MSG.strip)
172+
Shakapacker gem not found in your Gemfile.
173+
React on Rails requires Shakapacker for webpack integration.
174+
Adding 'shakapacker' gem to your Gemfile and running installation...
175+
MSG
176+
expect(GeneratorMessages).to receive(:add_error).with(<<~MSG.strip)
177+
Failed to install Shakapacker automatically.
178+
Please run 'bundle exec rails shakapacker:install' manually.
179+
MSG
180+
result = install_generator.send(:ensure_shakapacker_installed)
181+
expect(result).to be false
152182
end
153183
end
154184
end

0 commit comments

Comments
 (0)