mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
Merge pull request #1844 from cattywampus/cattywampus/gem-not-installed
Fix assert that a gem is not installed
This commit is contained in:
commit
45afca2e98
4 changed files with 12 additions and 6 deletions
|
@ -39,16 +39,16 @@ module Inspec::Resources
|
|||
return @info if defined?(@info)
|
||||
|
||||
cmd = inspec.command("#{@gem_binary} list --local -a -q \^#{@package_name}\$")
|
||||
@info = {
|
||||
installed: cmd.exit_status.zero?,
|
||||
type: 'gem',
|
||||
}
|
||||
return @info unless @info[:installed]
|
||||
return {} unless cmd.exit_status.zero?
|
||||
|
||||
# extract package name and version
|
||||
# parses data like winrm (1.3.4, 1.3.3)
|
||||
params = /^\s*([^\(]*?)\s*\((.*?)\)\s*$/.match(cmd.stdout.chomp)
|
||||
return {} if params.nil?
|
||||
@info = {
|
||||
installed: !params.nil?,
|
||||
type: 'gem',
|
||||
}
|
||||
return @info unless @info[:installed]
|
||||
|
||||
versions = params[2].split(',')
|
||||
@info[:name] = params[1]
|
||||
|
|
|
@ -175,6 +175,7 @@ class MockLoader
|
|||
'rpm -qia curl' => cmd.call('rpm-qia-curl'),
|
||||
'pacman -Qi curl' => cmd.call('pacman-qi-curl'),
|
||||
'brew info --json=v1 curl' => cmd.call('brew-info--json-v1-curl'),
|
||||
'gem list --local -a -q ^not-installed$' => cmd.call('gem-list-local-a-q-not-installed'),
|
||||
'gem list --local -a -q ^rubocop$' => cmd.call('gem-list-local-a-q-rubocop'),
|
||||
'/opt/ruby-2.3.1/embedded/bin/gem list --local -a -q ^pry$' => cmd.call('gem-list-local-a-q-pry'),
|
||||
'/opt/chef/embedded/bin/gem list --local -a -q ^chef-sugar$' => cmd.call('gem-list-local-a-q-chef-sugar'),
|
||||
|
|
0
test/unit/mock/cmd/gem-list-local-a-q-not-installed
Normal file
0
test/unit/mock/cmd/gem-list-local-a-q-not-installed
Normal file
|
@ -7,6 +7,11 @@ require 'helper'
|
|||
require 'inspec/resource'
|
||||
|
||||
describe 'Inspec::Resources::Gem' do
|
||||
it 'verify gem is not installed' do
|
||||
resource = load_resource('gem', 'not-installed')
|
||||
_(resource.installed?).must_equal false
|
||||
end
|
||||
|
||||
it 'verify gem package detail parsing' do
|
||||
resource = load_resource('gem', 'rubocop')
|
||||
pkg = {
|
||||
|
|
Loading…
Reference in a new issue