|
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) |
11 | | - |
12 | | - expect { described_class.generate(verbose: true) } |
13 | | - .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 8 | + before do |
| 9 | + allow(ReactOnRails::PackerUtils).to receive(:shakapacker_precompile_hook_configured?).and_return(false) |
14 | 10 | end |
15 | 11 |
|
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) |
| 12 | + context "when shakapacker precompile hook is configured" do |
| 13 | + before do |
| 14 | + allow(ReactOnRails::PackerUtils).to receive(:shakapacker_precompile_hook_configured?).and_return(true) |
| 15 | + end |
| 16 | + |
| 17 | + it "skips pack generation in verbose mode" do |
| 18 | + expect { described_class.generate(verbose: true) } |
| 19 | + .to output(/⏭️ Skipping pack generation \(handled by shakapacker precompile hook\)/) |
| 20 | + .to_stdout_from_any_process |
| 21 | + end |
19 | 22 |
|
20 | | - expect { described_class.generate(verbose: false) } |
21 | | - .to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process |
| 23 | + it "skips pack generation in quiet mode" do |
| 24 | + expect { described_class.generate(verbose: false) } |
| 25 | + .not_to output.to_stdout_from_any_process |
| 26 | + end |
22 | 27 | end |
23 | 28 |
|
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) |
| 29 | + context "when shakapacker precompile hook is not configured" do |
| 30 | + it "runs pack generation successfully in verbose mode" do |
| 31 | + command = "bundle exec rake react_on_rails:generate_packs" |
| 32 | + allow(described_class).to receive(:system).with(command).and_return(true) |
| 33 | + |
| 34 | + expect { described_class.generate(verbose: true) } |
| 35 | + .to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process |
| 36 | + end |
| 37 | + |
| 38 | + it "runs pack generation successfully in quiet mode" do |
| 39 | + command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
| 40 | + allow(described_class).to receive(:system).with(command).and_return(true) |
| 41 | + |
| 42 | + expect { described_class.generate(verbose: false) } |
| 43 | + .to output(/📦 Generating packs\.\.\. ✅/).to_stdout_from_any_process |
| 44 | + end |
| 45 | + |
| 46 | + it "exits with error when pack generation fails" do |
| 47 | + command = "bundle exec rake react_on_rails:generate_packs > /dev/null 2>&1" |
| 48 | + allow(described_class).to receive(:system).with(command).and_return(false) |
27 | 49 |
|
28 | | - expect { described_class.generate(verbose: false) }.to raise_error(SystemExit) |
| 50 | + expect { described_class.generate(verbose: false) }.to raise_error(SystemExit) |
| 51 | + end |
29 | 52 | end |
30 | 53 | end |
31 | 54 | end |
0 commit comments