From 5a2bf48510b13f0f353bac6435a9d398b3d259bc Mon Sep 17 00:00:00 2001 From: Maxim Samsonov Date: Sun, 2 Mar 2025 21:10:30 +0300 Subject: [PATCH] chore: update tests for warning messages --- spec/cli_helpers_spec.rb | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/spec/cli_helpers_spec.rb b/spec/cli_helpers_spec.rb index 9b58b6d7..619e91ae 100644 --- a/spec/cli_helpers_spec.rb +++ b/spec/cli_helpers_spec.rb @@ -132,6 +132,62 @@ expect { do_press(options_manager) }.to output(/WARNING/).to_stdout end end + end + + describe "#check_warnings" do + let(:options_manager) { Tebako::OptionsManager.new(options) } + + context "when mode is runtime" do + before do + options["mode"] = "runtime" + end + + it "does not display any warnings" do + expect { check_warnings(options_manager) }.not_to output.to_stdout + end + end + + context "when package is within root" do + before do + options["mode"] = "both" + allow(options_manager).to receive(:package_within_root?).and_return(true) + allow(options_manager).to receive(:prefix_within_root?).and_return(false) + allow(self).to receive(:sleep) + end + + it "displays package warning" do + expect { check_warnings(options_manager) }.to output(Tebako::CliHelpers::WARN).to_stdout + end + end + + context "when prefix is within root" do + before do + options["mode"] = "both" + allow(options_manager).to receive(:package_within_root?).and_return(false) + allow(options_manager).to receive(:prefix_within_root?).and_return(true) + allow(self).to receive(:sleep) + end + + it "displays prefix warning" do + expect { check_warnings(options_manager) }.to output(Tebako::CliHelpers::WARN2).to_stdout + end + end + + context "when both package and prefix are within root" do + before do + options["mode"] = "both" + allow(options_manager).to receive(:package_within_root?).and_return(true) + allow(options_manager).to receive(:prefix_within_root?).and_return(true) + allow(self).to receive(:sleep) + end + + it "displays both warnings" do + expect do + check_warnings(options_manager) + end.to output(Tebako::CliHelpers::WARN + Tebako::CliHelpers::WARN2).to_stdout + end + end + end describe "#do_setup" do let(:options_manager) { Tebako::OptionsManager.new(options) }