|
5 | 5 |
|
6 | 6 | RSpec.describe ReactOnRails::Dev::PackGenerator do |
7 | 7 | describe ".generate" do |
8 | | - it "runs pack generation successfully in verbose mode" do |
9 | | - command = "bundle exec rake react_on_rails:generate_packs" |
10 | | - allow(described_class).to receive(:system).with(command).and_return(true) |
| 8 | + context "when in Bundler context with Rails available" do |
| 9 | + before do |
| 10 | + stub_const("Bundler", Module.new) |
| 11 | + allow(ENV).to receive(:[]).and_call_original |
| 12 | + allow(ENV).to receive(:[]).with("BUNDLE_GEMFILE").and_return("/path/to/Gemfile") |
| 13 | + allow(described_class).to receive(:rails_available?).and_return(true) |
| 14 | + end |
11 | 15 |
|
12 | | - expect { described_class.generate(verbose: true) } |
13 | | - .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
14 | | - end |
| 16 | + it "runs pack generation successfully in verbose mode using direct rake execution" do |
| 17 | + allow(described_class).to receive(:run_rake_task_directly).and_return(true) |
| 18 | + |
| 19 | + expect { described_class.generate(verbose: true) } |
| 20 | + .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 21 | + expect(described_class).to have_received(:run_rake_task_directly) |
| 22 | + end |
| 23 | + |
| 24 | + it "runs pack generation successfully in quiet mode using direct rake execution" do |
| 25 | + allow(described_class).to receive(:run_rake_task_directly).and_return(true) |
15 | 26 |
|
16 | | - it "runs pack generation successfully in quiet mode" do |
17 | | - command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
18 | | - allow(described_class).to receive(:system).with(command).and_return(true) |
| 27 | + expect { described_class.generate(verbose: false) } |
| 28 | + .to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process |
| 29 | + expect(described_class).to have_received(:run_rake_task_directly) |
| 30 | + end |
19 | 31 |
|
20 | | - expect { described_class.generate(verbose: false) } |
21 | | - .to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process |
| 32 | + it "exits with error when pack generation fails" do |
| 33 | + allow(described_class).to receive(:run_rake_task_directly).and_return(false) |
| 34 | + |
| 35 | + expect { described_class.generate(verbose: false) }.to raise_error(SystemExit) |
| 36 | + end |
22 | 37 | end |
23 | 38 |
|
24 | | - it "exits with error when pack generation fails" do |
25 | | - command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
26 | | - allow(described_class).to receive(:system).with(command).and_return(false) |
| 39 | + context "when not in Bundler context" do |
| 40 | + before do |
| 41 | + stub_const("Bundler", nil) unless defined?(Bundler) |
| 42 | + allow(described_class).to receive(:should_run_directly?).and_return(false) |
| 43 | + end |
| 44 | + |
| 45 | + it "runs pack generation successfully in verbose mode using bundle exec" do |
| 46 | + command = "bundle exec rake react_on_rails:generate_packs" |
| 47 | + allow(described_class).to receive(:system).with(command).and_return(true) |
| 48 | + |
| 49 | + expect { described_class.generate(verbose: true) } |
| 50 | + .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 51 | + end |
| 52 | + |
| 53 | + it "runs pack generation successfully in quiet mode using bundle exec" do |
| 54 | + command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
| 55 | + allow(described_class).to receive(:system).with(command).and_return(true) |
| 56 | + |
| 57 | + expect { described_class.generate(verbose: false) } |
| 58 | + .to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process |
| 59 | + end |
| 60 | + |
| 61 | + it "exits with error when pack generation fails" do |
| 62 | + command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
| 63 | + allow(described_class).to receive(:system).with(command).and_return(false) |
27 | 64 |
|
28 | | - expect { described_class.generate(verbose: false) }.to raise_error(SystemExit) |
| 65 | + expect { described_class.generate(verbose: false) }.to raise_error(SystemExit) |
| 66 | + end |
29 | 67 | end |
30 | 68 | end |
31 | 69 | end |
0 commit comments