Last active
July 6, 2017 12:35
-
-
Save skylerto/8e1934ee3b84cdc50af990b15ea1fd41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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