From 12b917bca30a4879283ce9edd8cc54d33c444190 Mon Sep 17 00:00:00 2001 From: Urs Roesch Date: Sat, 5 Mar 2016 20:54:16 +0100 Subject: [PATCH] Override the selinux_module string to be 'SELinux module' Summary: When running rspec in '-f d' mode the selinux type says 'SELinux' while the selinux_module type read 'Selinux module'. With this change it is now 'SELinux module'. Plus better descriptions for the types selinux_module and package. Type selinux_module: describe selinux_module('bootloader') do it { should be_installed } end describe selinux_module('bootloader') do it { should be_installed.with_version('1.10') } end Before: Selinux module "bootloader" should be enabled Selinux module "bootloader" should be enabled After: SELinux module "bootloader" should be enabled SELinux module "bootloader" should be enabled with version "1.10" Type package: describe package('jekyll') do it { should be_installed.by(:gem) } end describe package('jekyll') do it { should be_installed.by(:gem).with_version('1.1.1') } end Before: Package "jekyll" should be installed Package "jekyll" should be installed After: Package "jekyll" should be installed by "gem" Package "jekyll" should be installed by "gem" with version "1.1.1" --- lib/serverspec/matcher/be_installed.rb | 13 ++++++++++++- lib/serverspec/type/selinux_module.rb | 6 +++++- spec/type/linux/selinux_module_spec.rb | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/serverspec/matcher/be_installed.rb b/lib/serverspec/matcher/be_installed.rb index 6d62100d..5d815208 100644 --- a/lib/serverspec/matcher/be_installed.rb +++ b/lib/serverspec/matcher/be_installed.rb @@ -1,6 +1,17 @@ RSpec::Matchers.define :be_installed do match do |name| - name.installed?(@provider, @version) + if subject.class.name == 'Serverspec::Type::SelinuxModule' + name.installed?(@version) + else + name.installed?(@provider, @version) + end + end + + description do + message = 'be installed' + message << %( by "#{@provider}") if @provider + message << %( with version "#{@version}") if @version + message end chain :by do |provider| diff --git a/lib/serverspec/type/selinux_module.rb b/lib/serverspec/type/selinux_module.rb index bbcfb601..924238cd 100644 --- a/lib/serverspec/type/selinux_module.rb +++ b/lib/serverspec/type/selinux_module.rb @@ -4,8 +4,12 @@ def enabled? @runner.check_selinux_module_is_enabled(@name) end - def installed?(name, version=nil) + def installed?(version = nil) @runner.check_selinux_module_is_installed(@name, version) end + + def to_s + %(SELinux module "#{@name}") + end end end diff --git a/spec/type/linux/selinux_module_spec.rb b/spec/type/linux/selinux_module_spec.rb index a62be6b8..7446dc07 100644 --- a/spec/type/linux/selinux_module_spec.rb +++ b/spec/type/linux/selinux_module_spec.rb @@ -4,6 +4,10 @@ describe selinux_module('bootloader') do it { should be_installed } +end + +describe selinux_module('bootloader') do + it { should be_installed.with_version('1.10') } end describe selinux_module('bootloader') do