Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lslezak committed Jan 19, 2017
1 parent 7724d34 commit 0957e10
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions library/commandline/test/commandline_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
Yast.import "CommandLine"

describe Yast::CommandLine do
# restore the original modes to no accidentally influence the other tests
# (these tests change the UI mode to "commandline")
around(:example) do |example|
orig_mode = Yast::Mode.mode
orig_ui = Yast::Mode.ui
example.run
Yast::Mode.SetMode(orig_mode)
Yast::Mode.SetUI(orig_ui)
end

it "invokes initialize, handler and finish" do
expect(STDOUT).to receive(:puts).with("Initialize called").ordered
expect(STDOUT).to receive(:puts).with("something").ordered
Expand Down
1 change: 1 addition & 0 deletions library/general/src/modules/Mode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def ui

# Setter for {#ui}.
def SetUI(new_ui)
# puts "*** SetUI: #{new_ui}"
if !Builtins.contains(["commandline", "dialog", "none"], new_ui)
Builtins.y2error("Unknown UI mode %1", new_ui)
end
Expand Down
9 changes: 9 additions & 0 deletions library/general/test/mode_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
Yast::Mode.Initialize()
end

# restore the original modes to no accidentally influence the other tests
around(:example) do |example|
orig_mode = Yast::Mode.mode
orig_ui = Yast::Mode.ui
example.run
Yast::Mode.SetMode(orig_mode)
Yast::Mode.SetUI(orig_ui)
end

describe "#SetMode" do
it "sets mode to given one" do
Yast::Mode.SetMode("installation")
Expand Down
13 changes: 13 additions & 0 deletions library/packages/test/file_conflict_callbacks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "reuses the package installation progress" do
expect(Yast::UI).to receive(:WidgetExists).and_return(true)
expect(Yast::UI).to receive(:ChangeWidget).twice
Expand Down Expand Up @@ -209,6 +213,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "returns false to abort if user clicks Abort" do
expect(Yast::UI).to receive(:PollInput).and_return(:abort)

Expand Down Expand Up @@ -320,6 +328,7 @@ def CallbackFileConflictFinish(func)

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
allow(Yast::UI).to receive(:OpenDialog)
allow(Yast::UI).to receive(:CloseDialog)
allow(Yast::UI).to receive(:SetFocus)
Expand Down Expand Up @@ -368,6 +377,10 @@ def CallbackFileConflictFinish(func)
end

context "in UI mode" do
before do
allow(Yast::Mode).to receive(:commandline).and_return(false)
end

it "no change if installation progress was already displayed" do
ui = double("no method call expected", WidgetExists: true)
stub_const("Yast::UI", ui)
Expand Down

0 comments on commit 0957e10

Please sign in to comment.