Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed May 31, 2017
2 parents afd2216 + cd58efc commit 884f43c
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 91 deletions.
8 changes: 5 additions & 3 deletions library/general/src/modules/Report.rb
Expand Up @@ -45,6 +45,7 @@ def main
Yast.import "Mode"
Yast.import "Popup"
Yast.import "Summary"
Yast.import "CommandLine"

# stored messages
@errors = []
Expand Down Expand Up @@ -486,7 +487,9 @@ def Warning(warning_string)
Builtins.y2warning(1, "%1", warning_string) if @log_warnings

if @display_warnings
if Ops.greater_than(@timeout_warnings, 0)
if Mode.commandline
CommandLine.Print "Warning: #{warning_string}"
elsif Ops.greater_than(@timeout_warnings, 0)
Popup.TimedWarning(warning_string, @timeout_warnings)
else
Popup.Warning(warning_string)
Expand Down Expand Up @@ -527,8 +530,7 @@ def Error(error_string)

if @display_errors
if Mode.commandline
Yast.import "CommandLine"
CommandLine.Print error_string
CommandLine.Print "Error: #{error_string}"
elsif Ops.greater_than(@timeout_errors, 0)
Popup.TimedError(error_string, @timeout_errors)
else
Expand Down
15 changes: 15 additions & 0 deletions library/general/test/popup_test.rb
Expand Up @@ -273,6 +273,21 @@
expect(subject).to receive(:VSpacing).with(40)
subject.TimedLongErrorGeometry("Title", 1, 30, 40)
end

context "when arguments are bad" do
it "raises exception when the block parameter is missing" do
# no block passed
expect { subject.Feedback("Label", "Message") }.to raise_error(ArgumentError, /block must be supplied/)
end
end
end

describe ".AnyTimedMessage" do
it "is an adapter for anyTimedMessageInternal" do
expect(subject).to receive(:anyTimedMessageInternal)
.with("headline", "message", Integer)
expect(subject.AnyTimedMessage("headline", "message", 5)).to eq nil
end
end

#
Expand Down
97 changes: 97 additions & 0 deletions library/general/test/report_test.rb
Expand Up @@ -171,4 +171,101 @@
end
end

describe ".Warning" do
let(:show) { true }
let(:message) { "Message" }

before do
allow(Yast::Mode).to receive(:commandline).and_return(commandline?)
end

context "while in command-line mode" do
let(:commandline?) { true }

it "prints the message only on console" do
expect(Yast::CommandLine).to receive(:Print)
.with(/#{message}/)
expect(Yast::Popup).to_not receive(:Warning)
expect(Yast::Popup).to_not receive(:TimedWarning)
subject.Warning(message)
end
end

context "while in UI mode and timeout is disabled" do
let(:timeout) { 0 }
let(:commandline?) { false }

before(:each) do
subject.DisplayWarnings(show, timeout)
end

it "shows a popup" do
expect(Yast::Popup).to receive(:Warning).with(/#{message}/)
subject.Warning(message)
end
end

context "while in UI mode and timeout is enabled" do
let(:timeout) { 1 }
let(:commandline?) { false }

before(:each) do
subject.DisplayWarnings(show, timeout)
end

it "shows timed popup" do
expect(Yast::Popup).to receive(:TimedWarning).with(/#{message}/, timeout)
subject.Warning(message)
end
end
end

describe ".Error" do
let(:show) { true }
let(:message) { "Message" }

before do
allow(Yast::Mode).to receive(:commandline).and_return(commandline?)
end

context "while in command-line mode" do
let(:commandline?) { true }

it "prints the message only on console" do
expect(Yast::CommandLine).to receive(:Print)
.with(/#{message}/)
expect(Yast::Popup).to_not receive(:Error)
expect(Yast::Popup).to_not receive(:TimedError)
subject.Error(message)
end
end

context "while in UI mode and timeout is disabled" do
let(:timeout) { 0 }
let(:commandline?) { false }

before(:each) do
subject.DisplayErrors(show, timeout)
end

it "shows a popup" do
expect(Yast::Popup).to receive(:Error).with(/#{message}/)
subject.Error(message)
end
end

context "while in UI mode and timeout is enabled" do
let(:timeout) { 1 }
let(:commandline?) { false }

before(:each) do
subject.DisplayErrors(show, timeout)
end

it "shows a timed popup" do
expect(Yast::Popup).to receive(:TimedError).with(/#{message}/, timeout)
subject.Error(message)
end
end
end
end

0 comments on commit 884f43c

Please sign in to comment.