Skip to content

Commit

Permalink
Override the selinux_module string to be 'SELinux module'
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
uroesch committed Mar 6, 2016
1 parent 5e3aee9 commit 12b917b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion lib/serverspec/matcher/be_installed.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down
6 changes: 5 additions & 1 deletion lib/serverspec/type/selinux_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions spec/type/linux/selinux_module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12b917b

Please sign in to comment.