|
130 | 130 | specify "when Shakapacker is already installed" do |
131 | 131 | allow(install_generator).to receive(:shakapacker_installed?).and_return(true) |
132 | 132 | 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 |
134 | 135 | end |
135 | 136 |
|
136 | 137 | specify "when Shakapacker is not installed and install succeeds" do |
137 | 138 | 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 |
140 | 146 | 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 |
142 | 149 | end |
143 | 150 |
|
144 | | - specify "when Shakapacker is not installed and install fails" do |
| 151 | + specify "when Shakapacker is not installed and bundle add fails" do |
145 | 152 | 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 |
152 | 182 | end |
153 | 183 | end |
154 | 184 | end |
|
0 commit comments