spec/beaker/subcommand_spec.rb in beaker-4.42.0 vs spec/beaker/subcommand_spec.rb in beaker-5.0.0

- old
+ new

@@ -1,13 +1,13 @@ require 'spec_helper' module Beaker SubcommandUtil = Beaker::Subcommands::SubcommandUtil describe Subcommand do - let( :subcommand ) { + let(:subcommand) do described_class.new - } + end describe '#initialize' do it 'creates a cli object' do expect(subcommand.cli).to be_instance_of(Beaker::CLI) end @@ -30,56 +30,56 @@ end end end context 'ensure that beaker options can be passed through' do + let(:beaker_options_list) do + %w[ + options-file + helper + load-path + tests + pre-suite + post-suite + pre-cleanup + provision + preserve-hosts + preserve-state + root-keys + keyfile + timeout + install + modules + quiet + color + color-host-output + log-level + log-prefix + dry-run + fail-mode + ntp + repo-proxy + package-proxy + validate + collect-perf-data + parse-only + tag + exclude-tags + xml-time-order + debug-errors + exec_manual_tests + test-tag-exclude + test-tag-and + test-tag-or + xml + type + debug + ] + end - let(:beaker_options_list) { [ - 'options-file', - 'helper', - 'load-path', - 'tests', - 'pre-suite', - 'post-suite', - 'pre-cleanup', - 'provision', - 'preserve-hosts', - 'preserve-state', - 'root-keys', - 'keyfile', - 'timeout', - 'install', - 'modules', - 'quiet', - 'color', - 'color-host-output', - 'log-level', - 'log-prefix', - 'dry-run', - 'fail-mode', - 'ntp', - 'repo-proxy', - 'add-el-extras', - 'package-proxy', - 'validate', - 'collect-perf-data', - 'parse-only', - 'tag', - 'exclude-tags', - 'xml-time-order', - 'debug-errors', - 'exec_manual_tests', - 'test-tag-exclude', - 'test-tag-and', - 'test-tag-or', - 'xml', - 'type', - 'debug', - ] } + let(:yaml_store_mock) { double('yaml_store_mock') } - let( :yaml_store_mock ) { double('yaml_store_mock') } - it 'does not error with valid beaker options' do beaker_options_list.each do |option| allow_any_instance_of(Beaker::CLI).to receive(:parse_options) allow_any_instance_of(Beaker::CLI).to receive(:configured_options).and_return({}) @@ -89,29 +89,29 @@ allow(File).to receive(:open) allow_any_instance_of(Beaker::Logger).to receive(:notify).twice expect(SubcommandUtil::SUBCOMMAND_OPTIONS).to receive(:exist?).and_return(true) expect(SubcommandUtil::SUBCOMMAND_STATE).to receive(:exist?).and_return(true) - expect {described_class.start(['init', '--hosts', 'centos', "--#{option}"])}.not_to output(/ERROR/).to_stderr + expect { described_class.start(['init', '--hosts', 'centos', "--#{option}"]) }.not_to output(/ERROR/).to_stderr end end it "errors with a bad option here" do allow(YAML::Store).to receive(:new).with(SubcommandUtil::SUBCOMMAND_STATE).and_return(yaml_store_mock) allow(yaml_store_mock).to receive(:transaction).and_yield allow(yaml_store_mock).to receive(:[]=).with('provisioned', false) expect(File).not_to receive(:open) expect(SubcommandUtil::SUBCOMMAND_OPTIONS).to receive(:exist?).and_return(true) expect(SubcommandUtil::SUBCOMMAND_STATE).to receive(:exist?).and_return(true) - expect {described_class.start(['init', '--hosts', 'centos', '--bad-option'])}.to output(/ERROR/).to_stderr + expect { described_class.start(['init', '--hosts', 'centos', '--bad-option']) }.to output(/ERROR/).to_stderr end end describe '#init' do - let( :cli ) { subcommand.cli } - let( :mock_options ) { {:timestamp => 'noon', :other_key => 'cordite'}} - let( :yaml_store_mock ) { double('yaml_store_mock') } + let(:cli) { subcommand.cli } + let(:mock_options) { { :timestamp => 'noon', :other_key => 'cordite' } } + let(:yaml_store_mock) { double('yaml_store_mock') } before do allow(cli).to receive(:parse_options) allow(cli).to receive(:configured_options).and_return(mock_options) end @@ -124,25 +124,25 @@ subcommand.init expect(mock_options).not_to have_key(:timestamp) end it 'requires hosts flag' do - expect{subcommand.init}.to raise_error(NotImplementedError) + expect { subcommand.init }.to raise_error(NotImplementedError) end end describe '#provision' do - let( :cli ) { subcommand.cli } - let( :yaml_store_mock ) { double('yaml_store_mock') } - let( :host_hash ) { {'mynode.net' => {:name => 'mynode', :platform => Beaker::Platform.new('centos-6-x86_64')}}} - let( :cleaned_hosts ) {double()} - let( :yielded_host_hash ) {double()} - let( :yielded_host_name) {double()} - let( :network_manager) {double('network_manager')} - let( :hosts) {double('hosts')} - let( :hypervisors) {double('hypervisors')} - let(:options) {double('options')} + let(:cli) { subcommand.cli } + let(:yaml_store_mock) { double('yaml_store_mock') } + let(:host_hash) { { 'mynode.net' => { :name => 'mynode', :platform => Beaker::Platform.new('centos-6-x86_64') } } } + let(:cleaned_hosts) { double } + let(:yielded_host_hash) { double } + let(:yielded_host_name) { double } + let(:network_manager) { double('network_manager') } + let(:hosts) { double('hosts') } + let(:hypervisors) { double('hypervisors') } + let(:options) { double('options') } it 'provisions the host and saves the host info' do expect(YAML::Store).to receive(:new).with(SubcommandUtil::SUBCOMMAND_STATE).and_return(yaml_store_mock) allow(yaml_store_mock).to receive(:[]).and_return(false) allow(cli).to receive(:preserve_hosts_file).and_return("/path/to/ho") @@ -166,31 +166,31 @@ expect(yaml_store_mock).to receive(:[]=).with('provisioned', true) subcommand.provision end it 'does not allow hosts to be passed' do - subcommand.options = {:hosts => "myhost"} - expect{subcommand.provision()}.to raise_error(NotImplementedError) + subcommand.options = { :hosts => "myhost" } + expect { subcommand.provision }.to raise_error(NotImplementedError) end end context 'exec' do before do allow(subcommand.cli).to receive(:parse_options) allow(subcommand.cli).to receive(:initialize_network_manager) allow(subcommand.cli).to receive(:execute!) end - let( :cleaned_hosts ) {double()} - let( :host_hash ) { {'mynode.net' => {:name => 'mynode', :platform => Beaker::Platform.new('centos-6-x86_64')}}} - let( :yaml_store_mock ) { double('yaml_store_mock') } + let(:cleaned_hosts) { double } + let(:host_hash) { { 'mynode.net' => { :name => 'mynode', :platform => Beaker::Platform.new('centos-6-x86_64') } } } + let(:yaml_store_mock) { double('yaml_store_mock') } it 'calls execute! when no resource is given' do expect_any_instance_of(Pathname).not_to receive(:directory?) expect_any_instance_of(Pathname).not_to receive(:exist?) expect(subcommand.cli).to receive(:execute!).once - expect{subcommand.exec}.not_to raise_error + expect { subcommand.exec }.not_to raise_error end it 'allows hard coded suite names to be specified' do subcommand.cli.options[:pre_suite] = %w[step1.rb] subcommand.cli.options[:post_suite] = %w[step2.rb] @@ -203,11 +203,11 @@ expect(subcommand.cli.options[:tests]).to eq(%w[tests/1.rb]) end it 'errors when a resource is neither a valid file resource or suite name' do allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) - expect{subcommand.exec('blahblahblah')}.to raise_error(ArgumentError) + expect { subcommand.exec('blahblahblah') }.to raise_error(ArgumentError) end it 'accepts a tests directory, clearing all other suites' do allow_any_instance_of(Pathname).to receive(:exist?).and_return(true) allow_any_instance_of(Pathname).to receive(:directory?).and_return(true) @@ -247,17 +247,15 @@ end it 'rejects comma-separated file and suite name' do allow_any_instance_of(Pathname).to receive(:exist?).and_return(false) - expect { + expect do subcommand.exec('pre-suite,tests/whoops') - }.to raise_error(ArgumentError, %r{Unable to parse pre-suite,tests/whoops}) + end.to raise_error(ArgumentError, %r{Unable to parse pre-suite,tests/whoops}) end - - it 'updates the subcommand_options file with new host info if `preserve-state` is set' do allow(yaml_store_mock).to receive(:[]).and_return(false) allow(subcommand).to receive(:options).and_return('preserve-state' => true) expect(subcommand.cli).to receive(:parse_options).and_return(subcommand.cli) @@ -278,13 +276,13 @@ expect(subcommand.cli.options['preserve-state']).to be_nil end end context 'destroy' do - let( :cli ) { subcommand.cli } - let( :mock_options ) { {:timestamp => 'noon', :other_key => 'cordite'}} - let( :yaml_store_mock ) { double('yaml_store_mock') } - let( :network_manager) {double('network_manager')} + let(:cli) { subcommand.cli } + let(:mock_options) { { :timestamp => 'noon', :other_key => 'cordite' } } + let(:yaml_store_mock) { double('yaml_store_mock') } + let(:network_manager) { double('network_manager') } it 'calls destroy and updates the yaml store' do allow(cli).to receive(:parse_options) allow(cli).to receive(:initialize_network_manager) allow(cli).to receive(:network_manager).and_return(network_manager)