Skip to content

Commit

Permalink
Merge pull request #1279 from yast/rspec-kw-hash
Browse files Browse the repository at this point in the history
Fix hash vs keyword arguments in RSpec expectations (bsc#1204871)
  • Loading branch information
mvidner committed Nov 4, 2022
2 parents a2c1a48 + 2933b5a commit aa302a7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
35 changes: 18 additions & 17 deletions library/cwm/test/cwm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def generic_save(_key, _event)

let(:test_stringterm) { VBox(HBox("w1")) }
let(:widget_names) { ["w1", "w2"] }
let(:event) { { "ID" => :my_event_id } }
let(:test_widgets) do
{
"w1" => {
Expand Down Expand Up @@ -158,65 +159,65 @@ def generic_save(_key, _event)
# used by CWMTab and CWM::ReplacePoint
describe "#saveWidgets" do
it "calls store methods" do
expect(self).to receive(:generic_save).with("w1", "ID" => :event)
expect(self).to receive(:w2_store).with("w2", "ID" => :event)
subject.saveWidgets(run_widgets, "ID" => :event)
expect(self).to receive(:generic_save).with("w1", event)
expect(self).to receive(:w2_store).with("w2", event)
subject.saveWidgets(run_widgets, event)
end

# used via GetProcessedWidget by yast2-slp-server and yast2
it "sets @processed_widget" do
allow(self).to receive(:generic_save)
allow(self).to receive(:w2_store)
expect(subject).to receive(:processed_widget=).twice
subject.saveWidgets(run_widgets, "ID" => :event)
subject.saveWidgets(run_widgets, event)
end
end

# used by CWMTab and CWM::ReplacePoint
describe "#handleWidgets" do
it "calls the handle methods" do
expect(self).to receive(:w1_handle).with("w1", "ID" => :event).and_return(nil)
expect(self).to receive(:w2_handle).with("w2", "ID" => :event).and_return(nil)
expect(subject.handleWidgets(run_widgets, "ID" => :event)).to eq(nil)
expect(self).to receive(:w1_handle).with("w1", event).and_return(nil)
expect(self).to receive(:w2_handle).with("w2", event).and_return(nil)
expect(subject.handleWidgets(run_widgets, event)).to eq(nil)
end

it "breaks the loop if a handler returns non-nil" do
expect(self).to receive(:w1_handle).with("w1", "ID" => :event).and_return(:foo)
expect(self).to receive(:w1_handle).with("w1", event).and_return(:foo)
expect(self).to_not receive(:w2_handle)
expect(subject.handleWidgets(run_widgets, "ID" => :event)).to eq(:foo)
expect(subject.handleWidgets(run_widgets, event)).to eq(:foo)
end

it "sets @processed_widget" do
allow(self).to receive(:w1_handle).and_return(nil)
allow(self).to receive(:w2_handle).and_return(nil)
expect(subject).to receive(:processed_widget=).twice
subject.handleWidgets(run_widgets, "ID" => :event)
subject.handleWidgets(run_widgets, event)
end

it "filters the events if 'handle_events' is specified" do
expect(self).to_not receive(:w1_handle)
allow(self).to receive(:w2_handle)
widgets = deep_copy(run_widgets)
widgets[0]["handle_events"] = [:special_event]
subject.handleWidgets(widgets, "ID" => :event)
subject.handleWidgets(widgets, event)
end
end

describe "#validateWidgets" do
it "calls the validate methods" do
expect(self).to receive(:w1_validate).with("w1", "ID" => :event).and_return(true)
expect(self).to receive(:w2_validate).with("w2", "ID" => :event).and_return(true)
expect(subject.validateWidgets(run_widgets, "ID" => :event)).to eq(true)
expect(self).to receive(:w1_validate).with("w1", event).and_return(true)
expect(self).to receive(:w2_validate).with("w2", event).and_return(true)
expect(subject.validateWidgets(run_widgets, event)).to eq(true)
end

context "if a handler returns false" do
before do
expect(self).to receive(:w1_validate).with("w1", "ID" => :event).and_return(false)
expect(self).to receive(:w1_validate).with("w1", event).and_return(false)
end

it "breaks the loop if a handler returns false" do
expect(self).to_not receive(:w2_validate)
expect(subject.validateWidgets(run_widgets, "ID" => :event)).to eq(false)
expect(subject.validateWidgets(run_widgets, event)).to eq(false)
end

# SetValidationFailedHandler
Expand All @@ -225,7 +226,7 @@ def generic_save(_key, _event)
handler = -> { called = true }
subject.SetValidationFailedHandler(handler)

subject.validateWidgets(run_widgets, "ID" => :event)
subject.validateWidgets(run_widgets, event)
# we cannot set an expectation on `handler` because a copy is made
expect(called).to eq(true)
end
Expand Down
9 changes: 6 additions & 3 deletions library/system/test/execute_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

it "adds to passed arguments chroot option if scr chrooted" do
allow(Yast::WFM).to receive(:scr_root).and_return("/mnt")
expect(Cheetah).to receive(:run).with("ls", "-a", chroot: "/mnt")
opts = { chroot: "/mnt" }
expect(Cheetah).to receive(:run).with("ls", "-a", opts)

subject.on_target("ls", "-a")
end
Expand All @@ -80,7 +81,8 @@

it "adds to passed arguments chroot option if scr chrooted" do
allow(Yast::WFM).to receive(:scr_root).and_return("/mnt")
expect(Cheetah).to receive(:run).with("ls", "-a", chroot: "/mnt")
opts = { chroot: "/mnt" }
expect(Cheetah).to receive(:run).with("ls", "-a", opts)

subject.on_target("ls", "-a")
end
Expand All @@ -96,7 +98,8 @@
end

it "captures stdout of the command" do
expect(Cheetah).to receive(:run).with("ls", "-a", stdout: :capture)
opts = { stdout: :capture }
expect(Cheetah).to receive(:run).with("ls", "-a", opts)

subject.stdout("ls", "-a")
end
Expand Down
6 changes: 6 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Mon Oct 31 13:07:35 UTC 2022 - Martin Vidner <mvidner@suse.com>

- Fix hash vs keyword arguments in RSpec expectations (bsc#1204871)
- 4.5.19

-------------------------------------------------------------------
Tue Oct 25 08:32:48 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2
Version: 4.5.18
Version: 4.5.19

Release: 0
Summary: YaST2 Main Package
Expand Down

0 comments on commit aa302a7

Please sign in to comment.