From 11bfa2c21150325378c0af2c880103acdc78fd50 Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 31 Oct 2022 14:06:03 +0100 Subject: [PATCH 1/2] Fix hash vs keyword arguments in RSpec expectations (bsc#1204871) New rspec-mocks distinguish between hash and keyword arguments passed to `with`. The tested code does use hashes but we've used keywords in tests because it's shorter to write. Fixed. rspec-mocks 3.11.2 / 2022-10-25: > Bug Fixes: Support keyword argument semantics when constraining argument > expectations using with on Ruby 3.0+ with instance_double > https://github.com/rspec/rspec-mocks/pull/1473 --- library/cwm/test/cwm_test.rb | 35 +++++++++++++++-------------- library/system/test/execute_test.rb | 9 +++++--- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/library/cwm/test/cwm_test.rb b/library/cwm/test/cwm_test.rb index bca7dc724..55e9aa179 100755 --- a/library/cwm/test/cwm_test.rb +++ b/library/cwm/test/cwm_test.rb @@ -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" => { @@ -158,9 +159,9 @@ 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 @@ -168,29 +169,29 @@ def generic_save(_key, _event) 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 @@ -198,25 +199,25 @@ def generic_save(_key, _event) 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 @@ -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 diff --git a/library/system/test/execute_test.rb b/library/system/test/execute_test.rb index 56b1d3305..22d49cab4 100755 --- a/library/system/test/execute_test.rb +++ b/library/system/test/execute_test.rb @@ -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 @@ -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 @@ -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 From 2933b5ada27a640689b631690ab644c932653afc Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Mon, 31 Oct 2022 14:08:09 +0100 Subject: [PATCH 2/2] version + changelog --- package/yast2.changes | 6 ++++++ package/yast2.spec | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package/yast2.changes b/package/yast2.changes index 8c7d2af9a..3adf82299 100644 --- a/package/yast2.changes +++ b/package/yast2.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Oct 31 13:07:35 UTC 2022 - Martin Vidner + +- Fix hash vs keyword arguments in RSpec expectations (bsc#1204871) +- 4.5.19 + ------------------------------------------------------------------- Tue Oct 25 08:32:48 UTC 2022 - Ladislav Slezák diff --git a/package/yast2.spec b/package/yast2.spec index 284c37633..e29545b95 100644 --- a/package/yast2.spec +++ b/package/yast2.spec @@ -17,7 +17,7 @@ Name: yast2 -Version: 4.5.18 +Version: 4.5.19 Release: 0 Summary: YaST2 Main Package