How to use expect method of Inspec Package

Best Inspec_ruby code snippet using Inspec.expect

inspec_spec.rb

Source:inspec_spec.rb Github

copy

Full Screen

...71 let(:verifier) do72 Kitchen::Verifier::Inspec.new(config).finalize_config!(instance)73 end74 it "verifier api_version is 1" do75 expect(verifier.diagnose_plugin[:api_version]).to eq(1)76 end77 it "plugin_version is set to Kitchen::Verifier::INSPEC_VERSION" do78 expect(verifier.diagnose_plugin[:version])79 .to eq(Kitchen::Verifier::INSPEC_VERSION)80 end81 describe "configuration" do82 let(:transport) do83 Kitchen::Transport::Ssh.new({})84 end85 it "supports reporter config platform and suite replacements" do86 config = verifier.send(:runner_options, transport, {}, "osx", "internal")87 expected_value = [88 "cli",89 "junit:path/to/results/osx_internal_inspec.xml",90 ]91 expect(config.to_hash).to include("reporter" => expected_value)92 end93 it "backend_cache option sets to true" do94 config = verifier.send(:runner_options, transport)95 expect(config.to_hash).to include(backend_cache: true)96 end97 it "backend_cache option defaults to false" do98 config[:backend_cache] = nil99 config = verifier.send(:runner_options, transport)100 expect(config.to_hash).to include(backend_cache: false)101 end102 end103 describe "#finalize_config!" do104 let(:kitchen_inspec_tests) { File.join(kitchen_root, "test", "recipes") }105 context "when a test/recipes folder exists" do106 before do107 FileUtils.mkdir_p(kitchen_inspec_tests)108 end109 it "should read the tests from there" do110 expect(verifier[:test_base_path]).to eq(kitchen_inspec_tests)111 end112 end113 context "when a test/recipes folder does not exist" do114 it "should read the tests from the default location" do115 expect(verifier[:test_base_path]).to eq(File.join(kitchen_root, "test", "integration"))116 end117 end118 end119 describe "#setup_inputs" do120 let(:input_opts) { {} }121 let(:input_cfg) { {} }122 context "when InSpec is recent" do123 context "when file inputs are provided" do124 context "using modern syntax" do125 it "should place them in input_file" do126 stub_const("Inspec::VERSION", "3.99.0")127 input_cfg[:input_files] = ["a.yaml", "b.yaml"]128 verifier.send(:setup_inputs, input_opts, input_cfg)129 expect(input_opts.keys).to include :input_file130 expect(input_opts[:input_file]).to eq(input_cfg[:input_files])131 end132 end133 context "using legacy syntax" do134 it "should place them in input_file" do135 stub_const("Inspec::VERSION", "3.99.0")136 input_cfg[:attrs] = ["a.yaml", "b.yaml"]137 # TODO: this should emit a warning138 verifier.send(:setup_inputs, input_opts, input_cfg)139 expect(input_opts.keys).to include :input_file140 expect(input_opts[:input_file]).to eq(input_cfg[:attrs])141 end142 end143 end144 context "when hash inputs are provided" do145 context "using modern syntax" do146 it "should place them in attributes" do147 stub_const("Inspec::VERSION", "3.99.0")148 input_cfg[:inputs] = { a: 1, b: 2 }149 verifier.send(:setup_inputs, input_opts, input_cfg)150 expect(input_opts.keys).to include :attributes151 expect(input_opts[:attributes]).to eq({ "a" => 1, "b" => 2 })152 end153 end154 context "using legacy syntax" do155 it "should place them in attributes" do156 stub_const("Inspec::VERSION", "3.99.0")157 input_cfg[:attributes] = { a: 1, b: 2 }158 verifier.send(:setup_inputs, input_opts, input_cfg)159 expect(input_opts.keys).to include :attributes160 expect(input_opts[:attributes]).to eq({ "a" => 1, "b" => 2 })161 end162 end163 end164 end165 context "when InSpec is old" do166 context "when file inputs are provided" do167 context "using modern syntax" do168 it "should place them in attrs" do169 stub_const("Inspec::VERSION", "3.0.0")170 input_cfg[:input_files] = ["a.yaml", "b.yaml"]171 verifier.send(:setup_inputs, input_opts, input_cfg)172 expect(input_opts.keys).to include :attrs173 expect(input_opts[:attrs]).to eq(input_cfg[:input_files])174 end175 end176 context "using legacy syntax" do177 it "should place them in input_file" do178 stub_const("Inspec::VERSION", "3.0.0")179 input_cfg[:attrs] = ["a.yaml", "b.yaml"]180 # TODO: this should emit a warning181 verifier.send(:setup_inputs, input_opts, input_cfg)182 expect(input_opts.keys).to include :attrs183 expect(input_opts[:attrs]).to eq(input_cfg[:attrs])184 end185 end186 end187 context "when hash inputs are provided" do188 context "using modern syntax" do189 it "should place them in attributes" do190 stub_const("Inspec::VERSION", "3.0.0")191 input_cfg[:inputs] = { a: 1, b: 2 }192 verifier.send(:setup_inputs, input_opts, input_cfg)193 expect(input_opts.keys).to include :attributes194 expect(input_opts[:attributes]).to eq({ "a" => 1, "b" => 2 })195 end196 end197 context "using legacy syntax" do198 it "should place them in attributes" do199 stub_const("Inspec::VERSION", "3.0.0")200 input_cfg[:attributes] = { a: 1, b: 2 }201 verifier.send(:setup_inputs, input_opts, input_cfg)202 expect(input_opts.keys).to include :attributes203 expect(input_opts[:attributes]).to eq({ "a" => 1, "b" => 2 })204 end205 end206 end207 end208 end209 describe "#resolve_config_inspec_tests" do210 context "when the entry is a string" do211 context "when the path does not exist" do212 it "returns the original string" do213 config[:inspec_tests] = ["test/integration/foo"]214 expect(File).to receive(:exist?).with("test/integration/foo").and_return(false)215 allow(File).to receive(:exist?).and_call_original216 expect(verifier.send(:resolve_config_inspec_tests)).to eq(["test/integration/foo"])217 end218 end219 context "when the path exists" do220 it "expands to an absolute path and returns a hash" do221 config[:inspec_tests] = ["test/integration/foo"]222 expect(File).to receive(:exist?).with("test/integration/foo").and_return(true)223 allow(File).to receive(:exist?).and_call_original224 expect(File).to receive(:expand_path).with("test/integration/foo").and_return("/absolute/path/to/foo")225 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ path: "/absolute/path/to/foo" }])226 end227 end228 end229 context "when the entry is a hash" do230 context "when the entry is a path" do231 it "expands the path to an absolute path and removes unnecessary keys" do232 config[:inspec_tests] = [{ name: "foo_profile", path: "test/integration/foo" }]233 expect(File).to receive(:expand_path).with("test/integration/foo").and_return("/absolute/path/to/foo")234 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ path: "/absolute/path/to/foo" }])235 end236 end237 context "when the entry is a url item" do238 it "returns a hash with unnecessary keys removed" do239 config[:inspec_tests] = [{ name: "foo_profile", url: "http://some.domain/profile" }]240 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ url: "http://some.domain/profile" }])241 end242 end243 context "when the entry is a git item" do244 it "returns a hash with unnecessary keys removed" do245 config[:inspec_tests] = [{ name: "foo_profile", git: "http://some.domain/profile" }]246 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ git: "http://some.domain/profile" }])247 end248 end249 context "when the entry is a compliance item" do250 it "returns a hash with unnecessary keys removed" do251 config[:inspec_tests] = [{ name: "foo_profile", compliance: "me/foo" }]252 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ compliance: "me/foo" }])253 end254 end255 context "when the entry only contains a name" do256 it "returns it as-is to be resolved on Supermarket" do257 config[:inspec_tests] = [{ name: "me/foo" }]258 expect(verifier.send(:resolve_config_inspec_tests)).to eq([{ name: "me/foo" }])259 end260 end261 context "when the entry contains no acceptable keys" do262 it "returns nil" do263 config[:inspec_tests] = [{ key1: "value1", key2: "value2" }]264 expect(verifier.send(:resolve_config_inspec_tests)).to eq([nil])265 end266 end267 end268 it "returns an array of properly formatted entries when multiple entries are supplied" do269 config[:inspec_tests] = [270 { name: "profile1", git: "me/profile1" },271 { name: "profile2", random_key: "random_value", compliance: "me/profile2" },272 { name: "profile3", url: "someurl", random_key: "what is this for?", another_random_key: 123 },273 { name: "profile4" },274 ]275 expect(verifier.send(:resolve_config_inspec_tests)).to eq([276 { git: "me/profile1" },277 { compliance: "me/profile2" },278 { url: "someurl" },279 { name: "profile4" },280 ])281 end282 end283 context "with an ssh transport" do284 let(:transport_config) do285 {286 hostname: "boogie",287 port: "I shouldn't be used",288 username: "dance",289 ssh_key: "/backstage/pass",290 keepalive: "keepalive",291 keepalive_interval: "forever",292 connection_timeout: "nope",293 connection_retries: "thousand",294 connection_retry_sleep: "sleepy",295 max_wait_until_ready: 42,296 compression: "maxyo",297 compression_level: "pico",298 forward_agent: true,299 }300 end301 let(:transport) do302 Kitchen::Transport::Ssh.new(transport_config)303 end304 let(:runner) do305 instance_double("Inspec::Runner")306 end307 before do308 allow(runner).to receive(:add_target)309 allow(runner).to receive(:run).and_return 0310 end311 it "constructs a Inspec::Runner using transport config data and state" do312 config[:sudo] = "jellybeans"313 config[:sudo_command] = "allyourbase"314 config[:proxy_command] = "gateway"315 config[:forward_agent] = true316 expect(Inspec::Runner).to receive(:new)317 .with(318 hash_including(319 "backend" => "ssh",320 "logger" => logger,321 "sudo" => "jellybeans",322 "sudo_command" => "allyourbase",323 "host" => "boogie",324 "port" => 123,325 "user" => "dance",326 "keepalive" => "keepalive",327 "keepalive_interval" => "forever",328 "connection_timeout" => "nope",329 "connection_retries" => "thousand",330 "connection_retry_sleep" => "sleepy",331 "max_wait_until_ready" => 42,332 "compression" => "maxyo",333 "compression_level" => "pico",334 "key_files" => ["/backstage/pass"],335 "proxy_command" => "gateway",336 "forward_agent" => true337 )338 )339 .and_return(runner)340 verifier.call(port: 123)341 end342 it "constructs a Inspec::Runner using transport config data(host and port)" do343 config[:host] = "192.168.33.40"344 config[:port] = 222345 expect(Inspec::Runner).to receive(:new)346 .with(347 hash_including(348 "backend" => "ssh",349 "host" => "192.168.33.40",350 "port" => 222351 )352 )353 .and_return(runner)354 verifier.call(port: 123)355 end356 it "constructs an Inspec::Runner with a specified inspec output format" do357 config[:format] = "documentation"358 expect(Inspec::Runner).to receive(:new)359 .with(360 hash_including(361 "format" => "documentation"362 )363 )364 .and_return(runner)365 verifier.call(port: 123)366 end367 it "constructs an Inspec::Runner with a controls filter" do368 config[:controls] = %w{a control}369 expect(Inspec::Runner).to receive(:new)370 .with(371 hash_including(372 controls: %w{a control}373 )374 )375 .and_return(runner)376 verifier.call(port: 123)377 end378 it "does not send keys_only=true to InSpec (which breaks SSH Agent usage)" do379 expect(Inspec::Runner).to receive(:new)380 .with(381 hash_not_including(382 "keys_only" => true383 )384 )385 .and_return(runner)386 verifier.call(port: 123)387 end388 it "provide platform and test suite to build output path" do389 allow(Inspec::Runner).to receive(:new).and_return(runner)390 expect(verifier).to receive(:runner_options).with(391 transport,392 {},393 "default",394 "germany"395 ).and_return({})396 verifier.call({})397 end398 it "custom inspec output path" do399 ensure_suite_directory("germany")400 config[:output] = "/tmp/inspec_results.xml"401 allow(Inspec::Runner).to receive(:new).and_return(runner)402 expect(runner).to receive(:add_target).with({ path: File.join(403 config[:test_base_path],404 "germany"405 ) }, hash_including(406 "output" => "/tmp/inspec_results.xml"407 ))408 verifier.call({})409 end410 it "resolve template format for inspec output path" do411 ensure_suite_directory("germany")412 config[:output] = "/tmp/%{platform}_%{suite}.xml"413 allow(Inspec::Runner).to receive(:new).and_return(runner)414 expect(runner).to receive(:add_target).with({ path: File.join(415 config[:test_base_path],416 "germany"417 ) }, hash_including(418 "output" => "/tmp/default_germany.xml"419 ))420 verifier.call({})421 end422 it "find test directory for runner" do423 ensure_suite_directory("germany")424 allow(Inspec::Runner).to receive(:new).and_return(runner)425 expect(runner).to receive(:add_target).with({ path: File.join(426 config[:test_base_path],427 "germany"428 ) }, anything)429 verifier.call({})430 end431 it "find test directory for runner if legacy" do432 create_legacy_test_directories433 allow(Inspec::Runner).to receive(:new).and_return(runner)434 expect(runner).to receive(:add_target).with({ path: File.join(435 config[:test_base_path],436 "germany", "inspec"437 ) }, anything)438 verifier.call({})439 end440 it "non-existent test directory for runner" do441 allow(Inspec::Runner).to receive(:new).and_return(runner)442 expect(runner).to_not receive(:add_target).with(443 File.join(444 config[:test_base_path],445 "nobody"446 ), anything)447 verifier.call({})448 end449 it "calls #run on the runner" do450 allow(Inspec::Runner).to receive(:new).and_return(runner)451 expect(runner).to receive(:run)452 verifier.call({})453 end454 end455 context "with an remote profile" do456 let(:transport) do457 Kitchen::Transport::Ssh.new({})458 end459 let(:runner) do460 instance_double("Inspec::Runner")461 end462 let(:suite) do463 instance_double("Kitchen::Suite", { name: "local" })464 end465 let(:instance) do466 instance_double(467 "Kitchen::Instance",468 name: "coolbeans",469 logger: logger,470 platform: platform,471 suite: suite,472 transport: transport,473 to_str: "instance"474 )475 end476 let(:config) do477 {478 inspec_tests: [{ url: "https://github.com/nathenharvey/tmp_compliance_profile" }],479 kitchen_root: kitchen_root,480 test_base_path: File.join(kitchen_root, "test", "integration"),481 }482 end483 before do484 allow(runner).to receive(:add_target)485 allow(runner).to receive(:run).and_return 0486 end487 it "find test directory and remote profile" do488 ensure_suite_directory("local")489 allow(Inspec::Runner).to receive(:new).and_return(runner)490 expect(runner).to receive(:add_target).with({ path: File.join(config[:test_base_path], "local") }, anything)491 expect(runner).to receive(:add_target).with(492 { url: "https://github.com/nathenharvey/tmp_compliance_profile" }, anything)493 verifier.call({})494 end495 end496 context "with an winrm transport" do497 let(:transport_config) do498 {499 username: "dance",500 password: "party",501 connection_retries: "thousand",502 connection_retry_sleep: "sleepy",503 max_wait_until_ready: 42,504 }505 end506 let(:transport) do507 Kitchen::Transport::Winrm.new(transport_config)508 end509 let(:runner) do510 instance_double("Inspec::Runner")511 end512 before do513 allow(runner).to receive(:add_target)514 allow(runner).to receive(:run).and_return 0515 end516 it "constructs a Inspec::Runner using transport config data and state" do517 expect(Inspec::Runner).to receive(:new)518 .with(519 hash_including(520 "backend" => "winrm",521 "logger" => logger,522 "host" => "win.dows",523 "port" => 123,524 "user" => "dance",525 "password" => "party",526 "connection_retries" => "thousand",527 "connection_retry_sleep" => "sleepy",528 "max_wait_until_ready" => 42,529 "color" => true530 )531 )532 .and_return(runner)533 verifier.call(hostname: "win.dows", port: 123)534 end535 it "constructs a Inspec::Runner using transport config data(host and port)" do536 config[:host] = "192.168.56.40"537 config[:port] = 22538 expect(Inspec::Runner).to receive(:new)539 .with(540 hash_including(541 "backend" => "winrm",542 "host" => "192.168.56.40",543 "port" => 22544 )545 )546 .and_return(runner)547 verifier.call(hostname: "win.dows", port: 123)548 end549 end550 context "with an exec transport" do551 let(:transport) do552 Kitchen::Transport::Exec.new553 end554 let(:runner) do555 instance_double("Inspec::Runner")556 end557 before do558 allow(runner).to receive(:add_target)559 allow(runner).to receive(:run).and_return 0560 end561 it "constructs a Inspec::Runner using transport config data and state" do562 expect(Inspec::Runner).to receive(:new)563 .with(564 hash_including(565 "backend" => "local",566 "logger" => logger,567 "color" => true568 )569 )570 .and_return(runner)571 verifier.call({})572 end573 end574 context "with an unsupported transport" do575 it "#call raises a UserError" do576 expect { verifier.call({}) }.to raise_error(Kitchen::UserError)577 end578 end579 def create_legacy_test_directories580 base = File.join(config[:test_base_path], "germany")581 FileUtils.mkdir_p(File.join(base, "inspec"))582 FileUtils.mkdir_p(File.join(base, "serverspec"))583 end584 def ensure_suite_directory(suitename)585 suite = File.join(config[:test_base_path], suitename)586 FileUtils.mkdir_p(suite)587 end588end...

Full Screen

Full Screen

audit_report_spec.rb

Source:audit_report_spec.rb Github

copy

Full Screen

...41 describe 'report when interval settings are set to default (disabled)' do42 interval_enabled = false43 it 'returns true for check_interval_settings' do44 status = @audit_report.check_interval_settings(@interval, interval_enabled, @interval_time)45 expect(status).to eq(true)46 end47 end48 describe 'report when interval settings are enabled' do49 interval_enabled = true50 it 'returns false for check_interval_settings' do51 status = @audit_report.check_interval_settings(@interval, interval_enabled, @interval_time)52 expect(status).to eq(false)53 end54 end55 end56 describe 'validate_inspec_version method' do57 before :each do58 require 'inspec'59 end60 it 'inspec min version fail' do61 stub_const('Inspec::VERSION', '1.20.0')62 expect { @audit_report.validate_inspec_version }63 .to raise_error(RuntimeError)64 .with_message('This audit cookbook version requires InSpec 1.25.1 or newer, aborting compliance scan...')65 end66 it 'inspec version warn for backend_cache' do67 stub_const('Inspec::VERSION', '1.46.0')68 set_inspec_backend_cache(true)69 expect(Chef::Log).to receive(:warn)70 .with('inspec_backend_cache requires InSpec version >= 1.47.0')71 .and_return('captured')72 expect(@audit_report.validate_inspec_version).to eq('captured')73 end74 it 'inspec version passes all requirements' do75 stub_const('Inspec::VERSION', '1.47.0')76 set_inspec_backend_cache(true)77 expect(Chef::Log).to_not receive(:warn)78 expect { @audit_report.validate_inspec_version }.to_not raise_error79 end80 end81 describe 'get_opts method' do82 it 'sets the format to json-min' do83 format = 'json-min'84 quiet = true85 set_inspec_backend_cache(true)86 opts = @audit_report.get_opts(format, quiet, {})87 expect(opts['report']).to be true88 expect(opts['format']).to eq('json-min')89 expect(opts['output']).to eq('/dev/null')90 expect(opts['logger']).to eq(Chef::Log)91 expect(opts[:waiver_file]).to eq([])92 expect(opts[:backend_cache]).to be true93 expect(opts[:attributes].empty?).to be true94 end95 it 'sets the format to json' do96 allow(File).to receive(:exist?).with('/tmp/exists.yaml').and_return(true)97 allow(File).to receive(:exist?).with('/tmp/missing.yaml').and_return(false)98 format = 'json'99 quiet = true100 set_inspec_backend_cache(true)101 mynode.default['audit']['waiver_file'] = ['/tmp/exists.yaml', '/tmp/missing.yaml']102 opts = @audit_report.get_opts(format, quiet, {})103 expect(opts['report']).to be true104 expect(opts['format']).to eq('json')105 expect(opts['output']).to eq('/dev/null')106 expect(opts['logger']).to eq(Chef::Log)107 expect(opts[:waiver_file]).to eq(['/tmp/exists.yaml'])108 expect(opts[:backend_cache]).to be true109 expect(opts[:attributes].empty?).to be true110 end111 it 'sets the backend_cache to false' do112 format = 'json'113 quiet = true114 set_inspec_backend_cache(false)115 opts = @audit_report.get_opts(format, quiet, {})116 expect(opts['report']).to be true117 expect(opts['format']).to eq('json')118 expect(opts['output']).to eq('/dev/null')119 expect(opts['logger']).to eq(Chef::Log)120 expect(opts[:backend_cache]).to be false121 expect(opts[:attributes].empty?).to be true122 end123 it 'sets the attributes' do124 format = 'json-min'125 quiet = true126 attributes = {127 first: 'value1',128 second: 'value2',129 }130 set_inspec_backend_cache(true)131 opts = @audit_report.get_opts(format, quiet, attributes)132 expect(opts[:attributes][:first]).to eq('value1')133 expect(opts[:attributes][:second]).to eq('value2')134 end135 end136 describe 'call' do137 it 'given a profile, returns a json report' do138 opts = { 'report' => true, 'format' => 'json', 'output' => '/dev/null' }139 path = File.expand_path('../../data/mock_profile.rb', __dir__)140 profiles = [{ 'name': 'example', 'path': path }]141 # we circumvent the default load mechanisms, therefore we have to require inspec142 require 'inspec'143 report = @audit_report.call(opts, profiles)144 expected_report = /^.*profiles.*controls.*version.*statistics.*duration.*controls.*/145 expect(report.to_json).to match(expected_report)146 end147 it 'given a profile, returns a json-min report' do148 require 'inspec'149 opts = { 'report' => true, 'format' => 'json-min', 'output' => '/dev/null' }150 path = File.expand_path('../../data/mock_profile.rb', __dir__)151 profiles = [{ 'name': 'example', 'path': path }]152 # we circumvent the default load mechanisms, therefore we have to require inspec153 require 'inspec'154 report = @audit_report.call(opts, profiles)155 expect(report[:controls].length).to eq(2)156 end157 it 'given an unfetchable profile, returns a min failed report' do158 require 'inspec'159 opts = { 'report' => true, 'format' => 'json-automate', 'output' => '/dev/null' }160 profiles = [{ 'name': 'example', 'path': '/tmp/missing-in-action-profile' }]161 # we circumvent the default load mechanisms, therefore we have to require inspec162 require 'inspec'163 report = @audit_report.call(opts, profiles)164 expect(report[:profiles].length).to eq(0)165 expect(report[:status]).to eq('failed')166 expect(report[:platform]).to eq({ 'name': 'unknown', 'release': 'unknown' })167 expected_status_message = /^Cannot fetch all profiles.*does not exist$/168 expect(report[:status_message]).to match(expected_status_message)169 end170 it 'given a bad InSpec config, returns a min failed report' do171 require 'inspec'172 opts = { 'backend' => 'ssh', 'report' => true, 'format' => 'json-automate', 'output' => '/dev/null' }173 path = File.expand_path('../../data/mock_profile.rb', __dir__)174 profiles = [{ 'name': 'example', 'path': path }]175 # we circumvent the default load mechanisms, therefore we have to require inspec176 require 'inspec'177 report = @audit_report.call(opts, profiles)178 expect(report[:profiles].length).to eq(0)179 expect(report[:status]).to eq('failed')180 expect(report[:platform]).to eq({ 'name': 'unknown', 'release': 'unknown' })181 expected_status_message = /^Client error. can't connect.*/182 expect(report[:status_message]).to match(expected_status_message)183 end184 end185end...

Full Screen

Full Screen

task_inspec_spec.rb

Source:task_inspec_spec.rb Github

copy

Full Screen

...7 it 'fails to run' do8 # inspec requires build-essential for gem install boooooo9 shell('puppet resource package build-essential ensure=installed')10 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec')11 expect(task_result[0]['status']).to eq('failure')12 end13 it 'returns helpful error message' do14 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec')15 expect(task_result[0]['result']['_output']).to match(%r{unable\sto\sdetect\sthis\snode.*\srole\susing\sfacter})16 end17 end18 describe 'test_tool=inspec, test_file=example_pass.rb' do19 it 'installs inspec gem' do20 task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_pass.rb')21 expect(shell('ls /tmp/puppet_test/inspec/gems/inspec*/inspec.gemspec').exit_code).to eq(0)22 end23 it 'runs a passing test successfully' do24 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_pass.rb')25 expect(task_result[0]['status']).to eq('success')26 end27 it 'returns output' do28 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_pass.rb')29 expect(task_result[0]['result']['_output']).to match(%r{\d+\sexamples,\s0\sfailures})30 end31 end32 describe 'test_tool=inspec, test_file=example_pass.rb, return_status=false' do33 it 'does not return the status from the test' do34 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_fail.rb', 'return_status' => false)35 expect(task_result[0]['status']).to eq('success')36 end37 end38 describe 'test_tool=inspec, test_file=example_pass.rb, return_status=true' do39 it 'returns status from test - success' do40 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_pass.rb', 'return_status' => true)41 expect(task_result[0]['status']).to eq('success')42 end43 it 'returns status from test - failure' do44 task_result = task_run('test::role', '', '', '', 'test_tool' => 'inspec', 'test_file' => 'example_fail.rb', 'return_status' => true)45 expect(task_result[0]['status']).to eq('failure')46 end47 end48end...

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe command('whoami') do2 its('stdout') { should eq "root3" }4describe command('whoami') do5 its('stdout') { should eq "root6" }7describe command('whoami') do8 its('stdout') { should eq "root9" }10describe command('whoami') do11 its('stdout') { should eq "root12" }13describe command('whoami') do14 its('stdout') { should eq "root15" }16describe command('whoami') do17 its('stdout') { should eq "root18" }19describe command('whoami') do20 its('stdout') { should eq "root21" }22describe command('whoami') do23 its('stdout') { should eq "root24" }25describe command('whoami') do26 its('stdout') { should eq "root27" }28describe command('whoami') do29 its('stdout') { should eq "root30" }31describe command('whoami') do32 its('stdout') { should eq "root33" }34describe command('whoami') do35 its('stdout') { should eq "root36" }37describe command('whoami')

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe command('ruby -v') do2 its('stdout') { should match /ruby 2\.5\.1p57/ }3describe command('ruby -v') do4 its('stdout') { should match /ruby 2\.5\.1p57/ }5describe command('ruby -v') do6 its('stdout') { should match /ruby 2\.5\.1p57/ }7describe command('ruby -v') do8 its('stdout') { should match /ruby 2\.5\.1p57/ }9describe command('ruby -v') do10 its('stdout') { should match /ruby 2\.5\.1p57/ }11describe command('ruby -v') do12 its('stdout') { should match /ruby 2\.5\.1p57/ }13describe command('ruby -v') do14 its('stdout') { should match /ruby 2\.5\.1p57/ }15describe command('ruby -v') do16 its('stdout') { should match /ruby 2\.5\.1p57/ }17describe command('ruby -v') do18 its('stdout') { should match /ruby 2\.5\.1p57/ }19describe command('ruby -v') do20 its('stdout') { should match /ruby 2\.5\.1p57/ }21describe command('ruby -v') do

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe file('file1.txt') do2 it { should exist }3 its('content') { should match /hello/ }4 its('content') { should match /world/ }5describe file('file2.txt') do6 it { should exist }7 its('content') { should match /hello/ }8 its('content') { should match /world/ }9describe file('file3.txt') do10 it { should exist }11 its('content') { should match /hello/ }12 its('content') { should match /world/ }13describe file('file4.txt') do14 it { should exist }15 its('content') { should match /hello/ }16 its('content') { should match /world/ }17describe file('file5.txt') do18 it { should exist }19 its('content') { should match /hello/ }20 its('content') { should match /world/ }21describe file('file6.txt') do22 it { should exist }23 its('content') { should match /hello/ }24 its('content') { should match /world/ }25describe file('file7.txt') do26 it { should exist }27 its('content') { should match /hello/ }28 its('content') { should match /world/ }29describe file('file8.txt') do30 it { should exist }31 its('content') { should match /hello/ }32 its('content') { should match /world/ }33describe file('file9.txt') do34 it { should exist }35 its('content') { should match /hello/

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1 describe command('ruby -v') do2 its('stdout') { should match /ruby 2.4/ }3 describe command('ruby -v') do4 its('stdout') { should match /ruby 2.4/ }5 describe command('ruby -v') do6 its('stdout') { should match /ruby 2.4/ }7 describe command('ruby -v') do8 its('stdout') { should match /ruby 2.4/ }9 describe command('ruby -v') do10 its('stdout') { should match /ruby 2.4/ }

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe file('/etc/passwd') do2 it { should be_file }3 its('size') { should > 0 }4 its('content') { should match(/root/) }5Profile: tests from 1.rb (tests from 1.rb)6Version: (not specified)

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe file('/home/centos/1.rb') do2 it { should exist }3describe file('/home/centos/2.rb') do4 it { should exist }5describe file('/home/centos/3.rb') do6 it { should exist }7describe file('/home/centos/4.rb') do8 it { should exist }9describe file('/home/centos/5.rb') do10 it { should exist }11describe file('/home/centos/6.rb') do12 it { should exist }13describe file('/home/centos/7.rb') do14 it { should exist }15describe file('/home/centos/8.rb') do16 it { should exist }17describe file('/home/centos/9.rb') do18 it { should exist }19describe file('/home/centos/10.rb') do20 it { should exist }21describe file('/home/centos/11.rb') do22 it { should exist }

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe file('/etc/passwd') do2 it { should exist }3 it { should be_owned_by 'root' }4 it { should_not be_writable.by('others') }5describe file('/etc/passwd') do6 it { should exist }7 it { should be_owned_by 'root' }8 it { should_not be_writable.by('others') }9describe file('/etc/passwd') do10 it { should exist }11 it { should be_owned_by 'root' }12 it { should_not be_writable.by('others') }13describe file('/etc/passwd') do14 it { should exist }15 it { should be_owned_by 'root' }16 it { should_not be_writable.by('others') }17describe file('/etc/passwd') do18 it { should exist }19 it { should be_owned_by 'root' }20 it { should_not be_writable.by('others') }

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe command('ls -l /etc') do2 its('stdout') { should match /passwd/ }3Profile: tests from 1.rb (tests from 1.rb)4Version: (not specified)5describe command('ls -l /etc') do6 its('stdout') { should match /passwd/ }7Profile: tests from 2.rb (tests from 2.rb)8Version: (not specified)9describe command('ls -l /etc') do10 its('stdout') { should match /passwd/ }11Profile: tests from 3.rb (tests from 3.rb)12Version: (not specified)13describe command('ls -l /etc') do14 its('stdout') { should match /passwd/ }15Profile: tests from 4.rb (tests from 4.rb)

Full Screen

Full Screen

expect

Using AI Code Generation

copy

Full Screen

1describe file('/tmp/1.txt') do2 it { should exist }3 its('owner') { should eq 'root' }4 its('group') { should eq 'root' }5 its('mode') { should cmp '0644' }6 its('content') { should match(/Hello World/) }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful