Skip to content

Instantly share code, notes, and snippets.

@skylerto
Last active July 6, 2017 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skylerto/8e1934ee3b84cdc50af990b15ea1fd41 to your computer and use it in GitHub Desktop.
Save skylerto/8e1934ee3b84cdc50af990b15ea1fd41 to your computer and use it in GitHub Desktop.
$LOAD_PATH.unshift(*Dir[File.expand_path('../vendor/gems/**/lib', __FILE__)])
require 'ruby_expect'
# Custom resource based on the InSpec resource DSL
class PerlModules < Inspec.resource(1)
name 'perl_modules'
desc "
Perl Modules resource for extracting the perl modules via instmodsh.
"
example "
describe perl_modules do
its('content') { should include('Perl') }
its('content') { should_not include('Foo') }
it { should exist }
end
"
def initialize
@params = {}
begin
exp = RubyExpect::Expect.spawn('instmodsh', :debug => true)
exp.procedure do
each do
expect /cmd/ do
send "l"
end
expect /cmd/ do
data = before.split("\n")
$modules = data[2..data.length]
end
end
end
@modules = $modules
@modules = @modules.map(&:strip!)
@params['content'] = @modules
rescue Exception
return skip_resource "#{@file}: #{$!}"
end
end
# Example method called by 'it { should exist }'
def exists?
!@modules.empty?
end
# Expose all parameters
def method_missing(name)
return @params[name.to_s]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment