|
206 | 206 | .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
207 | 207 | end |
208 | 208 | end |
| 209 | + |
| 210 | + context "when calling bundle exec from within Bundler context" do |
| 211 | + before do |
| 212 | + # Ensure we're not in Rails context to trigger bundle exec path |
| 213 | + hide_const("Rails") if defined?(Rails) |
| 214 | + allow(ReactOnRails::PackerUtils).to receive(:shakapacker_precompile_hook_configured?).and_return(false) |
| 215 | + end |
| 216 | + |
| 217 | + it "unwraps the Bundler context before executing with with_unbundled_env" do |
| 218 | + bundler_module = Module.new do |
| 219 | + def self.respond_to?(method, *) |
| 220 | + method == :with_unbundled_env |
| 221 | + end |
| 222 | + |
| 223 | + def self.with_unbundled_env |
| 224 | + yield |
| 225 | + end |
| 226 | + end |
| 227 | + stub_const("Bundler", bundler_module) |
| 228 | + |
| 229 | + allow(bundler_module).to receive(:with_unbundled_env).and_yield |
| 230 | + allow(described_class).to receive(:system) |
| 231 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 232 | + .and_return(true) |
| 233 | + |
| 234 | + described_class.generate(verbose: true) |
| 235 | + |
| 236 | + expect(bundler_module).to have_received(:with_unbundled_env) |
| 237 | + end |
| 238 | + |
| 239 | + it "falls back to with_clean_env when with_unbundled_env is not available" do |
| 240 | + bundler_module = Module.new do |
| 241 | + def self.respond_to?(method, *) |
| 242 | + method == :with_clean_env |
| 243 | + end |
| 244 | + |
| 245 | + def self.with_clean_env |
| 246 | + yield |
| 247 | + end |
| 248 | + end |
| 249 | + stub_const("Bundler", bundler_module) |
| 250 | + |
| 251 | + allow(bundler_module).to receive(:with_clean_env).and_yield |
| 252 | + allow(described_class).to receive(:system) |
| 253 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 254 | + .and_return(true) |
| 255 | + |
| 256 | + described_class.generate(verbose: true) |
| 257 | + |
| 258 | + expect(bundler_module).to have_received(:with_clean_env) |
| 259 | + end |
| 260 | + |
| 261 | + it "executes directly when neither with_unbundled_env nor with_clean_env are available" do |
| 262 | + bundler_module = Module.new do |
| 263 | + def self.respond_to?(_method, *) |
| 264 | + false |
| 265 | + end |
| 266 | + end |
| 267 | + stub_const("Bundler", bundler_module) |
| 268 | + |
| 269 | + allow(described_class).to receive(:system) |
| 270 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 271 | + .and_return(true) |
| 272 | + |
| 273 | + expect { described_class.generate(verbose: true) } |
| 274 | + .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 275 | + |
| 276 | + expect(described_class).to have_received(:system) |
| 277 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 278 | + end |
| 279 | + |
| 280 | + it "executes directly when Bundler is not defined" do |
| 281 | + hide_const("Bundler") if defined?(Bundler) |
| 282 | + |
| 283 | + allow(described_class).to receive(:system) |
| 284 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 285 | + .and_return(true) |
| 286 | + |
| 287 | + expect { described_class.generate(verbose: true) } |
| 288 | + .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 289 | + |
| 290 | + expect(described_class).to have_received(:system) |
| 291 | + .with("bundle", "exec", "rake", "react_on_rails:generate_packs") |
| 292 | + end |
| 293 | + end |
209 | 294 | end |
210 | 295 | end |
0 commit comments