Skip to content

Commit ed84a0b

Browse files
justin808claude
andcommitted
Add comprehensive test coverage for tri-state process manager logic
Updates process_manager_spec.rb to properly test the tri-state return values (nil/true/false) from run_process_if_available, ensuring correct behavior when process managers are not found vs found but fail. Key improvements: - Fix incorrect mock return values (nil vs false for "not found" scenarios) - Add test for overmind fails but foreman succeeds (fallback scenario) - Add test for overmind fails with foreman not found - Add test for both overmind and foreman fail - Add test for overmind not found but foreman fails - Update existing tests to use correct nil values for "not found" This ensures the bug fix in process_manager.rb is properly tested and prevents the misleading "Process Manager Not Found" message when a process manager is installed but exits with an error. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 33b66ae commit ed84a0b

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

spec/react_on_rails/dev/process_manager_spec.rb

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,63 @@
7171
end
7272

7373
it "uses foreman when overmind not available and foreman is available" do
74+
expect(described_class).to receive(:run_process_if_available)
75+
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(nil)
76+
expect(described_class).to receive(:run_process_if_available)
77+
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(true)
78+
79+
described_class.run_with_process_manager("Procfile.dev")
80+
end
81+
82+
it "exits silently when overmind is installed but exits with error (foreman not found)" do
83+
expect(described_class).to receive(:run_process_if_available)
84+
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(false)
85+
expect(described_class).to receive(:run_process_if_available)
86+
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(nil)
87+
expect(described_class).not_to receive(:show_process_manager_installation_help)
88+
expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit)
89+
90+
expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit)
91+
end
92+
93+
it "exits silently when overmind fails but foreman succeeds" do
7494
expect(described_class).to receive(:run_process_if_available)
7595
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(false)
7696
expect(described_class).to receive(:run_process_if_available)
7797
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(true)
98+
expect(described_class).not_to receive(:show_process_manager_installation_help)
99+
expect_any_instance_of(Kernel).not_to receive(:exit)
78100

79101
described_class.run_with_process_manager("Procfile.dev")
80102
end
81103

82-
it "exits with error when no process manager available" do
104+
it "exits silently when overmind fails and foreman also fails" do
83105
expect(described_class).to receive(:run_process_if_available)
84106
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(false)
85107
expect(described_class).to receive(:run_process_if_available)
86108
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(false)
109+
expect(described_class).not_to receive(:show_process_manager_installation_help)
110+
expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit)
111+
112+
expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit)
113+
end
114+
115+
it "exits silently when overmind not found but foreman exits with error" do
116+
expect(described_class).to receive(:run_process_if_available)
117+
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(nil)
118+
expect(described_class).to receive(:run_process_if_available)
119+
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(false)
120+
expect(described_class).not_to receive(:show_process_manager_installation_help)
121+
expect_any_instance_of(Kernel).to receive(:exit).with(1).and_raise(SystemExit)
122+
123+
expect { described_class.run_with_process_manager("Procfile.dev") }.to raise_error(SystemExit)
124+
end
125+
126+
it "exits with error when no process manager available" do
127+
expect(described_class).to receive(:run_process_if_available)
128+
.with("overmind", ["start", "-f", "Procfile.dev"]).and_return(nil)
129+
expect(described_class).to receive(:run_process_if_available)
130+
.with("foreman", ["start", "-f", "Procfile.dev"]).and_return(nil)
87131
expect(described_class).to receive(:show_process_manager_installation_help)
88132
expect_any_instance_of(Kernel).to receive(:exit).with(1)
89133

@@ -117,12 +161,12 @@
117161
expect(result).to be true
118162
end
119163

120-
it "returns false when process not available anywhere" do
164+
it "returns nil when process not available anywhere" do
121165
allow(described_class).to receive(:installed?).with("nonexistent").and_return(false)
122166
allow(described_class).to receive(:process_available_in_system?).with("nonexistent").and_return(false)
123167

124168
result = described_class.send(:run_process_if_available, "nonexistent", ["start"])
125-
expect(result).to be false
169+
expect(result).to be_nil
126170
end
127171
end
128172

0 commit comments

Comments
 (0)