Skip to content

Commit

Permalink
Enable RSpec verifying doubles in unit tests (bsc#1194784)
Browse files Browse the repository at this point in the history
- Fixed crash when importing an SSH configuration in AutoYaST
  installation
- 4.4.35
  • Loading branch information
lslezak committed Jan 20, 2022
1 parent 84d1871 commit 0db4739
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 47 deletions.
9 changes: 9 additions & 0 deletions package/yast2-installation.changes
@@ -1,3 +1,12 @@
-------------------------------------------------------------------
Thu Jan 20 08:52:18 UTC 2022 - Ladislav Slezák <lslezak@suse.cz>

- Enable RSpec verifying doubles in unit tests to ensue that
the mocked methods really exist (bsc#1194784)
- Fixed crash when importing an SSH configuration in AutoYaST
installation
- 4.4.35

-------------------------------------------------------------------
Wed Jan 12 13:02:56 UTC 2022 - Josef Reidinger <jreidinger@suse.com>

Expand Down
6 changes: 3 additions & 3 deletions package/yast2-installation.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-installation
Version: 4.4.34
Version: 4.4.35
Release: 0
Summary: YaST2 - Installation Parts
License: GPL-2.0-only
Expand All @@ -41,8 +41,8 @@ BuildRequires: yast2-firewall
BuildRequires: yast2-network >= 4.4.12
# ProductSpec API
BuildRequires: yast2-packager >= 4.4.13
# for AbortException and handle direct abort
BuildRequires: yast2-ruby-bindings >= 4.0.6
# yast/rspec/helpers.rb
BuildRequires: yast2-ruby-bindings >= 4.4.7
# For LSM classes
BuildRequires: yast2-security
# using /usr/bin/udevadm
Expand Down
2 changes: 1 addition & 1 deletion src/lib/installation/clients/ssh_import_auto.rb
Expand Up @@ -133,7 +133,7 @@ def write
Popup.Notify _("It makes no sense to write these settings to system.")
true
else
ssh_importer.write(::Installation.destdir)
ssh_importer.write(Yast::Installation.destdir)
end
end

Expand Down
1 change: 0 additions & 1 deletion test/inst_update_installer_test.rb
Expand Up @@ -56,7 +56,6 @@
allow(subject).to receive(:fetch_profile).and_return(ay_profile)
allow(subject).to receive(:process_profile)
allow(subject).to receive(:valid_repositories?).and_return(true)
allow(finder).to receive(:add_installation_repo)

# stub the Profile module to avoid dependency on autoyast2-installation
stub_const("Yast::Profile", ay_profile)
Expand Down
1 change: 0 additions & 1 deletion test/lib/clients/inst_complex_welcome_test.rb
Expand Up @@ -108,7 +108,6 @@
allow(Yast::FileUtils).to receive(:Exists).with("/README.BETA")
.and_return(true)
allow(Yast::GetInstArgs).to receive(:going_back).and_return(false)
allow(subject).to receive(:event_loop)
allow(Yast::ProductLicense).to receive(:AcceptanceNeeded).and_return(false)
end

Expand Down
2 changes: 1 addition & 1 deletion test/lib/clients/security_finish_test.rb
Expand Up @@ -108,7 +108,7 @@
end

it "skips writting policy kit default privileges" do
allow(proposal_settings).to receive(:polkit_default_privs).and_return("easy")
allow(proposal_settings).to receive(:polkit_default_privileges).and_return("easy")
expect(Yast::SCR).to_not receive(:Write).with(
path(".sysconfig.security.POLKIT_DEFAULT_PRIVS"), anything
)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/security_settings_test.rb
Expand Up @@ -142,7 +142,7 @@ def create_target_config
lsm_config.configurable = true
allow(Yast::PackagesProposal).to receive("SetResolvables")
.with("LSM", :pattern, anything)
allow(subject).to receive(:propose_default)
allow(lsm_config).to receive(:propose_default)
end

context "but there is already a module selected" do
Expand Down
4 changes: 1 addition & 3 deletions test/lib/update_repositories_finder_test.rb
Expand Up @@ -77,8 +77,6 @@
allow(Yast::ProductFeatures).to receive(:GetStringFeature)
.with("globals", "self_update_url")
.and_return(url_from_control)
# TODO: test don't mock!
allow(finder).to receive(:add_installation_repo)
allow(Yast::Linuxrc).to receive(:InstallInf).with("regurl")
.and_return(nil)
end
Expand Down Expand Up @@ -113,7 +111,7 @@
)
end

let(:regservice_selection) { Class.new }
let(:regservice_selection) { Class.new { def self.run(_arg); end } }

let(:url_helpers) do
double("url_helpers", registration_url: smt0.slp_url, slp_discovery: [])
Expand Down
4 changes: 4 additions & 0 deletions test/lib/widgets/online_repos_test.rb
Expand Up @@ -7,5 +7,9 @@
describe Installation::Widgets::OnlineRepos do
subject { described_class.new }

before do
allow(Yast::WFM).to receive(:CallFunction)
end

include_examples "CWM::PushButton"
end
2 changes: 2 additions & 0 deletions test/lib/widgets/system_role_reader_test.rb
Expand Up @@ -8,6 +8,8 @@
class DummySystemRoleReader
include Yast::Logger
include ::Installation::Widgets::SystemRoleReader

attr_accessor :value
end

subject { DummySystemRoleReader.new }
Expand Down
24 changes: 13 additions & 11 deletions test/proposal_runner_test.rb
Expand Up @@ -159,17 +159,19 @@ class C < ::Installation::ProposalStore; end
end

context "and it enables soft r/o proposal in case of error" do
PROPERTIES = {
"enable_skip" => "no",
"label" => "Installation Settings",
"mode" => "autoinstallation",
"name" => "initial",
"stage" => "initial",
"unique_id" => "auto_inst_proposal",
"proposal_modules" => [
{ "name" => "software", "presentation_order" => "15", "read_only" => "soft" }
]
}.freeze
let(:properties) do
{
"enable_skip" => "no",
"label" => "Installation Settings",
"mode" => "autoinstallation",
"name" => "initial",
"stage" => "initial",
"unique_id" => "auto_inst_proposal",
"proposal_modules" => [
{ "name" => "software", "presentation_order" => "15", "read_only" => "soft" }
]
}
end
let(:proposals) { [["software_proposal", 15]] }

it "makes a proposal" do
Expand Down
2 changes: 1 addition & 1 deletion test/ssh_import_auto_test.rb
Expand Up @@ -128,7 +128,7 @@

before do
importer.add_config(fixtures_dir("root1"), "dev")
allow(::Installation).to receive(:destdir).and_return("/")
allow(Yast::Installation).to receive(:destdir).and_return("/")
end

it "writes the keys/configuration to the installation directory" do
Expand Down
53 changes: 29 additions & 24 deletions test/test_helper.rb
Expand Up @@ -15,32 +15,9 @@

FIXTURES_DIR = Pathname.new(__FILE__).dirname.join("fixtures")

# mock some dependencies, to not increase built dependencies
# mock some dependencies, to not increase build dependencies
$LOAD_PATH.unshift(File.join(FIXTURES_DIR.to_s, "stub_libs"))

# stub module to prevent its Import
# 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 })
end

# stub classes from other modules to speed up a build
stub_module("AddOnProduct")
stub_module("AutoinstConfig")
stub_module("AutoinstGeneral")
stub_module("AutoinstSoftware")
stub_module("Console")
stub_module("InstURL")
stub_module("Keyboard")
stub_module("Language")
stub_module("Packages")
stub_module("ProductLicense")
stub_module("Profile")
stub_module("ProfileLocation")
# we cannot depend on this module (circular dependency)
stub_module("NtpClient")
stub_module("Proxy")

if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
Expand Down Expand Up @@ -73,8 +50,36 @@ def stub_module(name)
config.extend Yast::I18n # available in context/describe
config.include Yast::I18n # available in it/let/before/...
config.include Helpers # custom helpers

config.mock_with :rspec do |c|
# verify that the mocked methods actually exist
# https://relishapp.com/rspec/rspec-mocks/v/3-0/docs/verifying-doubles/partial-doubles
c.verify_partial_doubles = true
end
end

# stub YaST modules to prevent importing them,
# useful for modules from different yast packages to avoid build dependencies
Yast::RSpec::Helpers.define_yast_module("AddOnProduct", methods: [:selected_installation_products])
Yast::RSpec::Helpers.define_yast_module("AutoinstConfig", methods: [:cio_ignore, :second_stage])
Yast::RSpec::Helpers.define_yast_module("AutoinstGeneral",
methods: [:self_update, :self_update_url])
Yast::RSpec::Helpers.define_yast_module("AutoinstSoftware")
Yast::RSpec::Helpers.define_yast_module("Console")
Yast::RSpec::Helpers.define_yast_module("InstURL", methods: [:installInf2Url])
Yast::RSpec::Helpers.define_yast_module("Keyboard")
Yast::RSpec::Helpers.define_yast_module("Language", methods: [:language])
Yast::RSpec::Helpers.define_yast_module("NtpClient",
methods: [:modified=, :ntp_conf, :ntp_selected=, :run_service=, :synchronize_time=])
Yast::RSpec::Helpers.define_yast_module("Packages",
methods: [:GetBaseSourceID, :Reset, :SelectSystemPackages, :SelectSystemPatterns,
:check_remote_installation_packages, :init_called])
Yast::RSpec::Helpers.define_yast_module("ProductLicense")
Yast::RSpec::Helpers.define_yast_module("Profile", methods: [:current])
Yast::RSpec::Helpers.define_yast_module("ProfileLocation")
Yast::RSpec::Helpers.define_yast_module("Proxy",
methods: [:Export, :Import, :WriteCurlrc, :WriteSysconfig, :modified, :to_target])

# require the "bin/yupdate" script for testing it, unfortunately we cannot use
# a simple require/require_relative for it, let's share the workaround in a single place
def require_yupdate
Expand Down

0 comments on commit 0db4739

Please sign in to comment.