Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable RSpec verifying doubles (bsc#1194784) #124

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package/yast2-add-on.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jan 20 16:11:51 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

- Enable RSpec verifying doubles in unit tests to ensure that
the mocked methods really exist (bsc#1194784)
- 4.4.6

-------------------------------------------------------------------
Thu Dec 2 17:06:27 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

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


Name: yast2-add-on
Version: 4.4.5
Version: 4.4.6
Release: 0
Summary: YaST2 - Add-On media installation code
License: GPL-2.0-only
Expand Down
7 changes: 5 additions & 2 deletions src/lib/add-on/clients/add-on_auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@

module Yast
class AddOnAutoClient < ::Installation::AutoClient
def initialize
Yast.include self, "add-on/add-on-workflow.rb"
super
end

def run
textdomain "add-on"

Yast.include self, "add-on/add-on-workflow.rb"

progress_orig = Progress.set(false)
ret = super
Progress.set(progress_orig)
Expand Down
15 changes: 9 additions & 6 deletions test/add-on-workflow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

require_relative "../src/include/add-on/add-on-workflow.rb"

# just a dummy class for including the tested methods
class AddOnAddOnWorkflowIncludeTest
include Yast::AddOnAddOnWorkflowInclude
end

Yast.import "AddOnProduct"
Yast.import "SourceDialogs"

describe Yast::AddOnAddOnWorkflowInclude do
subject { AddOnAddOnWorkflowIncludeTest.new }
subject do
# anonymous class for testing the include
klass = Class.new do
include Yast::AddOnAddOnWorkflowInclude
def TypeDialogOpts(_arg1, _arg2); end
end

klass.new
end

describe ".media_type_selection" do
context "Full medium installation with no add-ons yet" do
Expand Down
20 changes: 11 additions & 9 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
ENV["LC_ALL"] = "en_US.UTF-8"

require "yast"
require "yast/rspec"

# Stub a module to prevent its importation
#
# Useful for modules from different YaST packages, to avoid build dependencies
def stub_module(name)
Yast.const_set(name.to_sym, Class.new { def self.fake_method; end })
# configure RSpec
RSpec.configure do |config|
config.mock_with :rspec do |c|
# https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/verifying-doubles/partial-doubles
c.verify_partial_doubles = true
end
end

# Stub classes from other modules to speed up a build
stub_module("AutoinstGeneral")
stub_module("AutoinstSoftware")

if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
Expand All @@ -45,3 +43,7 @@ def stub_module(name)
]
end
end

# mock missing YaST modules
Yast::RSpec::Helpers.define_yast_module("AutoinstSoftware", methods: [:pmInit])
Yast::RSpec::Helpers.define_yast_module("AutoinstGeneral")
4 changes: 2 additions & 2 deletions test/y2add_on/clients/inst_add-on_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
before do
allow(Yast::Linuxrc).to receive(:InstallInf).with("addon").and_return(addons)
allow(subject).to receive(:NetworkSetupForAddons).and_return(:next)
allow(subject).to receive(:InstallProduct)
allow_any_instance_of(Yast::AddOnAddOnWorkflowInclude).to receive(:InstallProduct)
allow(Yast::AddOnProduct).to receive(:skip_add_ons).and_return(skip_add_ons)
allow(Yast::Installation).to receive(:add_on_selected).and_return(add_on_selected)
allow(Yast::InstURL).to receive(:installInf2Url).and_return(inst_url)
allow(subject).to receive(:RunAddOnMainDialog).and_return(:next)
allow_any_instance_of(Yast::AddOnAddOnWorkflowInclude).to receive(:RunAddOnMainDialog).and_return(:next)
end

context "when add-on products selection should be skipped" do
Expand Down