diff options
author | Tim Smith <tsmith@chef.io> | 2019-12-30 14:43:27 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-30 14:43:27 -0800 |
commit | 0d829b9a3b29af8e77dd26d9ff1f88342afa2634 (patch) | |
tree | eecd4721c03e733e9354792d954852a6bb60b29a | |
parent | 3d510f4064028f94f43be800b3fab7e27c4b6188 (diff) | |
parent | 7d227bd79277a062657dbee625f9435dc633badf (diff) | |
download | ohai-0d829b9a3b29af8e77dd26d9ff1f88342afa2634.tar.gz |
Merge pull request #1417 from chef/specs
Minor spec cleanup from rubocop-rspec project
28 files changed, 154 insertions, 113 deletions
diff --git a/spec/functional/plugins/powershell_spec.rb b/spec/functional/plugins/powershell_spec.rb index c7058078..c9e12a9a 100644 --- a/spec/functional/plugins/powershell_spec.rb +++ b/spec/functional/plugins/powershell_spec.rb @@ -25,6 +25,7 @@ describe Ohai::System, "languages plugin" do it "is present" do expect(subject).not_to be_nil end + it "looks like a version" do expect(subject).to match(VERSION_MATCHING_REGEX) end diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index 17ffcebd..61a59e5e 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -24,26 +24,26 @@ RSpec.describe Ohai::Config do describe "config_context :ohai" do describe "option :plugin" do it "gets configured with a value" do - Ohai::Config.ohai[:plugin][:foo] = true - expect(Ohai::Config.ohai[:plugin]).to have_key(:foo) - expect(Ohai::Config.ohai[:plugin][:foo]).to be true + described_class.ohai[:plugin][:foo] = true + expect(described_class.ohai[:plugin]).to have_key(:foo) + expect(described_class.ohai[:plugin][:foo]).to be true end it "gets configured with a Hash" do value = { bar: true, baz: true } - Ohai::Config.ohai[:plugin][:foo] = value - expect(Ohai::Config.ohai[:plugin]).to have_key(:foo) - expect(Ohai::Config.ohai[:plugin][:foo]).to eq(value) + described_class.ohai[:plugin][:foo] = value + expect(described_class.ohai[:plugin]).to have_key(:foo) + expect(described_class.ohai[:plugin][:foo]).to eq(value) end it "raises an error if the plugin name is not a symbol" do - expect { Ohai::Config.ohai[:plugin]["foo"] = false } + expect { described_class.ohai[:plugin]["foo"] = false } .to raise_error(Ohai::Exceptions::PluginConfigError, /Expected Symbol/) end it "raises an error if the value Hash has non-Symbol key" do value = { :bar => true, "baz" => true } - expect { Ohai::Config.ohai[:plugin][:foo] = value } + expect { described_class.ohai[:plugin][:foo] = value } .to raise_error(Ohai::Exceptions::PluginConfigError, /Expected Symbol/) end end @@ -51,7 +51,7 @@ RSpec.describe Ohai::Config do describe "Ohai.config" do it "returns the ohai config context" do - expect(Ohai.config).to eq(Ohai::Config.ohai) + expect(Ohai.config).to eq(described_class.ohai) end end end diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb index 2553e098..31a1cbcc 100644 --- a/spec/unit/dsl/plugin_spec.rb +++ b/spec/unit/dsl/plugin_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" shared_examples "Ohai::DSL::Plugin" do - context "#initialize" do + describe "#initialize" do it "sets has_run? to false" do expect(plugin.has_run?).to be false end @@ -30,7 +30,7 @@ shared_examples "Ohai::DSL::Plugin" do end end - context "#run" do + describe "#run" do before do allow(plugin).to receive(:run_plugin).and_return(true) allow(plugin).to receive(:name).and_return(:TestPlugin) @@ -282,12 +282,12 @@ shared_examples "Ohai::DSL::Plugin" do describe "a top-level attribute" do describe "as a string" do it "returns false when the attribute does not exist" do - expect(plugin.attribute?("alice in chains")).to eql(false) + expect(plugin.attribute?("alice in chains")).to be(false) end it "returns true if an attribute exists with the given name" do plugin.metallica("death magnetic") - expect(plugin.attribute?("metallica")).to eql(true) + expect(plugin.attribute?("metallica")).to be(true) end end diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb index c714024d..4315138e 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -22,14 +22,14 @@ require "spec_helper" describe Ohai::Loader do extend IntegrationSupport - let(:loader) { Ohai::Loader.new(ohai) } + let(:loader) { described_class.new(ohai) } let(:ohai) { double("Ohai::System", data: Mash.new, provides_map: provides_map, logger: Ohai::Log) } let(:provides_map) { Ohai::ProvidesMap.new } describe "#initialize" do it "returns an Ohai::Loader object" do - loader = Ohai::Loader.new(ohai) - expect(loader).to be_a_kind_of(Ohai::Loader) + loader = described_class.new(ohai) + expect(loader).to be_a_kind_of(described_class) end end diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb index 3086e36c..b0b9fd26 100644 --- a/spec/unit/mixin/command_spec.rb +++ b/spec/unit/mixin/command_spec.rb @@ -31,8 +31,8 @@ describe Ohai::Mixin::Command, "shell_out" do let(:logger) { instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) } before do - allow(Ohai::Mixin::Command).to receive(:logger).and_return(logger) - allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name) + allow(described_class).to receive(:logger).and_return(logger) + allow(described_class).to receive(:name).and_return(plugin_name) @original_env = ENV.to_hash ENV.clear end @@ -59,7 +59,7 @@ describe Ohai::Mixin::Command, "shell_out" do expect(logger).to receive(:trace) .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256") - Ohai::Mixin::Command.shell_out(cmd) + described_class.shell_out(cmd) end end @@ -79,7 +79,7 @@ describe Ohai::Mixin::Command, "shell_out" do .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and failed " \ "#<Errno::ENOENT: No such file or directory - sparkle-dream>") - expect { Ohai::Mixin::Command.shell_out(cmd) } + expect { described_class.shell_out(cmd) } .to raise_error(Ohai::Exceptions::Exec) end end @@ -100,7 +100,7 @@ describe Ohai::Mixin::Command, "shell_out" do .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \ "out after 30 seconds") - expect { Ohai::Mixin::Command.shell_out(cmd) } + expect { described_class.shell_out(cmd) } .to raise_error(Ohai::Exceptions::Exec) end end @@ -124,7 +124,7 @@ describe Ohai::Mixin::Command, "shell_out" do expect(logger).to receive(:trace) .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and returned 256") - Ohai::Mixin::Command.shell_out(cmd, options) + described_class.shell_out(cmd, options) end describe "when the command times out" do @@ -143,7 +143,7 @@ describe Ohai::Mixin::Command, "shell_out" do .with("Plugin OSSparkleDream: ran 'sparkle-dream --version' and timed " \ "out after 10 seconds") - expect { Ohai::Mixin::Command.shell_out(cmd, options) } + expect { described_class.shell_out(cmd, options) } .to raise_error(Ohai::Exceptions::Exec) end end diff --git a/spec/unit/mixin/dmi_decode_spec.rb b/spec/unit/mixin/dmi_decode_spec.rb index cde87a1a..fc9968d6 100644 --- a/spec/unit/mixin/dmi_decode_spec.rb +++ b/spec/unit/mixin/dmi_decode_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" require "ohai/mixin/dmi_decode" describe Ohai::Mixin::DmiDecode, "guest_from_dmi_data" do - let(:mixin) { Object.new.extend(Ohai::Mixin::DmiDecode) } + let(:mixin) { Object.new.extend(described_class) } # for the full DMI data used in these tests see https://github.com/chef/dmidecode_collection # the fields here are manufacturer, product, and version as passed to #guest_from_dmi_data diff --git a/spec/unit/mixin/ec2_metadata_spec.rb b/spec/unit/mixin/ec2_metadata_spec.rb index 88d3b5d8..3f194b76 100644 --- a/spec/unit/mixin/ec2_metadata_spec.rb +++ b/spec/unit/mixin/ec2_metadata_spec.rb @@ -21,7 +21,7 @@ require "ohai/mixin/ec2_metadata" describe Ohai::Mixin::Ec2Metadata do let(:mixin) do - metadata_object = Object.new.extend(Ohai::Mixin::Ec2Metadata) + metadata_object = Object.new.extend(described_class) http_client = double("Net::HTTP client") allow(http_client).to receive(:get).and_return(response) allow(metadata_object).to receive(:http_client).and_return(http_client) @@ -33,7 +33,7 @@ describe Ohai::Mixin::Ec2Metadata do allow(mixin).to receive(:logger).and_return(logger) end - context "#best_api_version" do + describe "#best_api_version" do context "with a sorted list of metadata versions" do let(:response) { double("Net::HTTP Response", body: "1.0\n2011-05-01\n2012-01-12\nUnsupported", code: "200") } @@ -76,7 +76,7 @@ describe Ohai::Mixin::Ec2Metadata do end end - context "#metadata_get" do + describe "#metadata_get" do context "when the response code is unexpected" do let(:response) { double("Net::HTTP Response", body: "", code: "418") } diff --git a/spec/unit/mixin/network_helper_spec.rb b/spec/unit/mixin/network_helper_spec.rb index ec0b2472..a57af17f 100644 --- a/spec/unit/mixin/network_helper_spec.rb +++ b/spec/unit/mixin/network_helper_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" require "ohai/mixin/network_helper" describe Ohai::Mixin::NetworkHelper, "Network Helper Mixin" do - let(:mixin) { Object.new.extend(Ohai::Mixin::NetworkHelper) } + let(:mixin) { Object.new.extend(described_class) } describe "hex_to_dec_netmask method" do it "converts a netmask from hexadecimal form to decimal form" do diff --git a/spec/unit/mixin/softlayer_metadata_spec.rb b/spec/unit/mixin/softlayer_metadata_spec.rb index d636b378..23e490e6 100644 --- a/spec/unit/mixin/softlayer_metadata_spec.rb +++ b/spec/unit/mixin/softlayer_metadata_spec.rb @@ -23,7 +23,7 @@ require "ohai/mixin/softlayer_metadata" describe ::Ohai::Mixin::SoftlayerMetadata do let(:mixin) do - mixin = Object.new.extend(::Ohai::Mixin::SoftlayerMetadata) + mixin = Object.new.extend(described_class) mixin end diff --git a/spec/unit/plugins/aix/virtualization_spec.rb b/spec/unit/plugins/aix/virtualization_spec.rb index 70f3ad79..4c8c3896 100644 --- a/spec/unit/plugins/aix/virtualization_spec.rb +++ b/spec/unit/plugins/aix/virtualization_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai::System, "AIX virtualization plugin" do - context "inside an LPAR" do + context "when inside an LPAR" do let(:plugin) do p = get_plugin("aix/virtualization") @@ -301,7 +301,7 @@ describe Ohai::System, "AIX virtualization plugin" do end end - context "inside a WPAR" do + context "when inside a WPAR" do let(:plugin) do p = get_plugin("aix/virtualization") allow(p).to receive(:collect_os).and_return(:aix) diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 99356b3a..319bc476 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -81,7 +81,7 @@ describe Ohai::System, "plugin c" do allow(plugin).to receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC)) end - context "on AIX" do + context "when on AIX" do before do allow(plugin).to receive(:collect_os).and_return(:aix) allow(plugin).to receive(:shell_out).with("xlc -qversion").and_return(mock_shell_out(0, C_XLC, "")) @@ -124,7 +124,7 @@ describe Ohai::System, "plugin c" do end - context "on Darwin" do + context "when on Darwin" do before do allow(plugin).to receive(:shell_out).with("/usr/bin/xcode-select -p").and_return(mock_shell_out(0, "", "")) allow(plugin).to receive(:collect_os).and_return(:darwin) @@ -143,7 +143,7 @@ describe Ohai::System, "plugin c" do end - context "on Windows" do + context "when on Windows" do before do allow(plugin).to receive(:collect_os).and_return(:windows) allow(plugin).to receive(:shell_out).with("cl /\?").and_return(mock_shell_out(0, "", C_CL)) @@ -209,7 +209,7 @@ describe Ohai::System, "plugin c" do end end - context "on Linux" do + context "when on Linux" do before do allow(plugin).to receive(:collect_os).and_return(:linux) # glibc diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index 63826f82..952bbef6 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -133,6 +133,7 @@ describe Ohai::System, "plugin dmi" do plugin.run expect(plugin[:dmi][id][attribute]).to eql(value) end + it "attribute [:dmi][:#{id}][:#{attribute}] set for windows output" do stdout = convert_windows_output(DMI_OUT) expect(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, "")) diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb index 4287ffc1..bb563dd0 100644 --- a/spec/unit/plugins/docker_spec.rb +++ b/spec/unit/plugins/docker_spec.rb @@ -77,7 +77,7 @@ overlay}, describe Ohai::System, "plugin docker" do let(:plugin) { get_plugin("docker") } - context "if the machine does not have docker installed" do + context "without docker installed" do it "does not create a docker attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new @@ -86,7 +86,7 @@ describe Ohai::System, "plugin docker" do end end - context "if the machine has docker installed" do + context "with docker installed" do it "creates a docker attribute with correct data" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new diff --git a/spec/unit/plugins/haskell_spec.rb b/spec/unit/plugins/haskell_spec.rb index f3623039..b8cac16f 100644 --- a/spec/unit/plugins/haskell_spec.rb +++ b/spec/unit/plugins/haskell_spec.rb @@ -45,7 +45,7 @@ describe Ohai::System, "plugin haskell" do .and_return(mock_shell_out(0, stack_out, "")) end - context "if haskell/ghc is installed" do + context "when haskell/ghc is installed" do before do setup_plugin @@ -61,7 +61,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/ghci is installed" do + context "when haskell/ghci is installed" do before do setup_plugin @@ -77,7 +77,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/cabal is installed" do + context "when haskell/cabal is installed" do before do setup_plugin @@ -93,7 +93,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/stack is installed" do + context "when haskell/stack is installed" do before do setup_plugin @@ -109,7 +109,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/stack prerelease is installed" do + context "when haskell/stack prerelease is installed" do before do setup_plugin @@ -128,7 +128,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell is NOT installed" do + context "when haskell is NOT installed" do before do allow(plugin).to receive(:shell_out) @@ -141,7 +141,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/ghc is NOT installed" do + context "when haskell/ghc is NOT installed" do before do allow(plugin).to receive(:shell_out) .with("ghc --version") @@ -163,7 +163,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/ghci is NOT installed" do + context "when haskell/ghci is NOT installed" do before do allow(plugin).to receive(:shell_out) .with("ghc --version") @@ -185,7 +185,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/cabal is NOT installed" do + context "when haskell/cabal is NOT installed" do before do allow(plugin).to receive(:shell_out) .with("ghc --version") @@ -207,7 +207,7 @@ describe Ohai::System, "plugin haskell" do end end - context "if haskell/stack is NOT installed" do + context "when haskell/stack is NOT installed" do before do allow(plugin).to receive(:shell_out) .with("ghc --version") diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb index 79d2af9c..8ddcb1f1 100644 --- a/spec/unit/plugins/linux/kernel_spec.rb +++ b/spec/unit/plugins/linux/kernel_spec.rb @@ -59,7 +59,7 @@ describe Ohai::System, "Linux kernel plugin" do allow(File).to receive(:exist?).with("/sys/module/#{mod}/version").and_return(true) allow(File).to receive(:read).with("/sys/module/#{mod}/version").and_return(vers) end - expect(@plugin).to receive(:shell_out).with("env lsmod").at_least(1).times + expect(@plugin).to receive(:shell_out).with("env lsmod").at_least(:once) @plugin.run end diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 8c81d5a6..ccb29e79 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -131,7 +131,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin.platform_id_remap("ubuntu")).to eq("ubuntu") end - context "on a centos subshell on a nexus switch" do + context "when on a centos subshell on a nexus switch" do let(:os_release_content) do <<~OS_RELEASE NAME="CentOS Linux" @@ -314,7 +314,7 @@ describe Ohai::System, "Linux plugin platform" do end end - context "on system without /etc/os-release (legacy)" do + context "when on system without /etc/os-release (legacy)" do let(:have_debian_version) { false } let(:have_redhat_release) { false } let(:have_exherbo_release) { false } @@ -617,7 +617,7 @@ describe Ohai::System, "Linux plugin platform" do context "with lsb_results" do - context "on version 5.x" do + context "when on version 5.x" do let(:have_enterprise_release) { true } @@ -632,7 +632,7 @@ describe Ohai::System, "Linux plugin platform" do end end - context "on version 6.x" do + context "when on version 6.x" do let(:have_oracle_release) { true } @@ -654,7 +654,7 @@ describe Ohai::System, "Linux plugin platform" do plugin.lsb = nil end - context "on version 5.x" do + context "when on version 5.x" do let(:have_enterprise_release) { true } @@ -684,7 +684,7 @@ describe Ohai::System, "Linux plugin platform" do end - context "on version 6.x" do + context "when on version 6.x" do let(:have_oracle_release) { true } @@ -708,7 +708,7 @@ describe Ohai::System, "Linux plugin platform" do end describe "on suse" do - context "on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES12.1)" do + context "when on versions that have no /etc/os-release but /etc/SuSE-release (e.g. SLES12.1)" do let(:have_suse_release) { true } let(:have_os_release) { false } @@ -727,7 +727,7 @@ describe Ohai::System, "Linux plugin platform" do end end - context "on openSUSE and older SLES versions" do + context "when on openSUSE and older SLES versions" do let(:have_suse_release) { true } describe "without lsb_release results" do @@ -751,7 +751,7 @@ describe Ohai::System, "Linux plugin platform" do end it "[OHAI-272] should read the version as 11.3" do - expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3") + expect(File).to receive(:read).with("/etc/SuSE-release").once.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3") plugin.run expect(plugin[:platform]).to eq("opensuse") expect(plugin[:platform_version]).to eq("11.3") @@ -759,7 +759,7 @@ describe Ohai::System, "Linux plugin platform" do end it "[OHAI-272] should read the version as 11.4" do - expect(File).to receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon") + expect(File).to receive(:read).with("/etc/SuSE-release").once.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon") plugin.run expect(plugin[:platform]).to eq("opensuse") expect(plugin[:platform_version]).to eq("11.4") diff --git a/spec/unit/plugins/linux/sysctl_spec.rb b/spec/unit/plugins/linux/sysctl_spec.rb index b16c3d75..b424fde1 100644 --- a/spec/unit/plugins/linux/sysctl_spec.rb +++ b/spec/unit/plugins/linux/sysctl_spec.rb @@ -21,7 +21,7 @@ require_relative "../../../spec_helper.rb" describe Ohai::System, "sysctl plugin", :unix_only do let(:plugin) { get_plugin("linux/sysctl") } - it "should populate sysctl if sysctl is found" do + it "populates sysctl if sysctl is found" do sysctl_out = <<-SYSCTL_OUT vm.nr_overcommit_hugepages = 0 vm.numa_stat = 1 @@ -44,7 +44,7 @@ describe Ohai::System, "sysctl plugin", :unix_only do }) end - it "should not populate sysctl if sysctl is not found" do + it "does not populate sysctl if sysctl is not found" do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:which).with("sysctl").and_return(false) plugin.run diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index a851b88d..468c5e0f 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -576,7 +576,7 @@ describe Ohai::System, "Linux virtualization platform" do expect(plugin[:virtualization]).to eq({ "systems" => {} }) end - context "/proc/self/cgroup only has / mounts" do + context "when /proc/self/cgroup only has / mounts" do before do self_cgroup = <<~CGROUP 8:blkio:/ diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb index cb67402a..f31ab8f5 100644 --- a/spec/unit/plugins/openstack_spec.rb +++ b/spec/unit/plugins/openstack_spec.rb @@ -87,6 +87,7 @@ describe Ohai::System, "plugin openstack" do it "doesn't set metadata attributes" do expect(plugin[:openstack][:instance_id]).to be_nil end + context "when timout was set" do let(:override_timout) { 10 } @@ -226,63 +227,83 @@ describe Ohai::System, "plugin openstack" do it "reads the reservation_id from the metadata service" do expect(plugin["openstack"]["reservation_id"]).to eq("r-4tjvl99h") end + it "reads the public_keys_0_openssh_key from the metadata service" do expect(plugin["openstack"]["public_keys_0_openssh_key"]).to eq("SSH KEY DATA") end + it "reads the security_groups from the metadata service" do expect(plugin["openstack"]["security_groups"]).to eq(["default"]) end + it "reads the public_ipv4 from the metadata service" do expect(plugin["openstack"]["public_ipv4"]).to eq("172.31.7.2") end + it "ignore the public_ipv6 from the metadata service when empty" do expect(plugin["openstack"]).not_to have_key("public_ipv6") end + it "reads the ami_manifest_path from the metadata service" do expect(plugin["openstack"]["ami_manifest_path"]).to eq("FIXME") end + it "reads the instance_type from the metadata service" do expect(plugin["openstack"]["instance_type"]).to eq("opc-tester") end + it "reads the instance_id from the metadata service" do expect(plugin["openstack"]["instance_id"]).to eq("i-0000162a") end + it "reads the local_ipv4 from the metadata service" do expect(plugin["openstack"]["local_ipv4"]).to eq("172.31.7.23") end + it "reads the ari_id from the metadata service" do expect(plugin["openstack"]["ari_id"]).to eq("ari-00000037") end + it "reads the local_hostname from the metadata service" do expect(plugin["openstack"]["local_hostname"]).to eq("ohai-7-system-test.opscode.us") end + it "reads the placement_availability_zone from the metadata service" do expect(plugin["openstack"]["placement_availability_zone"]).to eq("nova") end + it "reads the ami_launch_index from the metadata service" do expect(plugin["openstack"]["ami_launch_index"]).to eq("0") end + it "reads the public_hostname from the metadata service" do expect(plugin["openstack"]["public_hostname"]).to eq("ohai-7-system-test.opscode.us") end + it "reads the hostname from the metadata service" do expect(plugin["openstack"]["hostname"]).to eq("ohai-7-system-test.opscode.us") end + it "reads the ami_id from the metadata service" do expect(plugin["openstack"]["ami_id"]).to eq("ami-00000035") end + it "reads the instance_action from the metadata service" do expect(plugin["openstack"]["instance_action"]).to eq("none") end + it "reads the aki_id from the metadata service" do expect(plugin["openstack"]["aki_id"]).to eq("aki-00000036") end + it "reads the block_device_mapping_ami from the metadata service" do expect(plugin["openstack"]["block_device_mapping_ami"]).to eq("vda") end + it "reads the block_device_mapping_root from the metadata service" do expect(plugin["openstack"]["block_device_mapping_root"]).to eq("/dev/vda") end + it "sets the provider to openstack" do expect(plugin["openstack"]["provider"]).to eq("openstack") end diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index ee62b4d3..e4ad9015 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai::System, "plugin packages" do - context "on debian" do + context "when on debian" do let(:plugin) do get_plugin("packages").tap do |plugin| plugin[:platform_family] = "debian" @@ -59,7 +59,7 @@ describe Ohai::System, "plugin packages" do end end - context "on fedora" do + context "when on fedora" do let(:plugin) do get_plugin("packages").tap do |plugin| plugin[:platform_family] = "fedora" @@ -122,7 +122,7 @@ describe Ohai::System, "plugin packages" do end end - context "on arch" do + context "when on arch" do let(:plugin) do get_plugin("packages").tap do |plugin| plugin[:platform_family] = "arch" @@ -159,7 +159,7 @@ describe Ohai::System, "plugin packages" do end end - context "on windows", :windows_only do + context "when on windows", :windows_only do let(:plugin) do get_plugin("packages").tap do |plugin| @@ -247,7 +247,7 @@ describe Ohai::System, "plugin packages" do end end - context "on aix" do + context "when on aix" do let(:plugin) { get_plugin("packages") } let(:stdout) do @@ -276,7 +276,7 @@ describe Ohai::System, "plugin packages" do end end - context "on freebsd" do + context "when on freebsd" do let(:plugin) { get_plugin("packages") } let(:stdout) do @@ -301,7 +301,7 @@ describe Ohai::System, "plugin packages" do end end - context "on solaris2" do + context "when on solaris2" do let(:plugin) { get_plugin("packages") } let(:pkglist_output) do diff --git a/spec/unit/plugins/scala_spec.rb b/spec/unit/plugins/scala_spec.rb index 66b51ee2..c0b749c5 100644 --- a/spec/unit/plugins/scala_spec.rb +++ b/spec/unit/plugins/scala_spec.rb @@ -33,7 +33,7 @@ describe Ohai::System, "plugin scala" do .and_return(mock_shell_out(0, "", scala_out)) end - context "if scala is installed" do + context "when scala is installed" do before do setup_plugin plugin.run @@ -44,7 +44,7 @@ describe Ohai::System, "plugin scala" do end end - context "if scala is not installed" do + context "when scala is not installed" do before do allow(plugin).to receive(:shell_out) .and_raise( Ohai::Exceptions::Exec ) diff --git a/spec/unit/plugins/solaris2/cpu_spec.rb b/spec/unit/plugins/solaris2/cpu_spec.rb index 92f1acda..6bc6ff62 100644 --- a/spec/unit/plugins/solaris2/cpu_spec.rb +++ b/spec/unit/plugins/solaris2/cpu_spec.rb @@ -447,23 +447,23 @@ describe Ohai::System, "Solaris2.X cpu plugin" do end it "gets the total virtual processor count" do - expect(@plugin["cpu"]["total"]).to eql(16) + expect(@plugin["cpu"]["total"]).to be(16) end it "gets the total processor count" do - expect(@plugin["cpu"]["real"]).to eql(2) + expect(@plugin["cpu"]["real"]).to be(2) end it "gets the number of threads per core" do - expect(@plugin["cpu"]["corethreads"]).to eql(2) + expect(@plugin["cpu"]["corethreads"]).to be(2) end it "gets the total number of online cores" do - expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(8) + expect(@plugin["cpu"]["cpustates"]["on-line"]).to be(8) end it "gets the total number of offline cores" do - expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(8) + expect(@plugin["cpu"]["cpustates"]["off-line"]).to be(8) end describe "per-cpu information" do @@ -2813,27 +2813,27 @@ describe Ohai::System, "Solaris2.X cpu plugin" do end it "gets the total virtual processor count" do - expect(@plugin["cpu"]["total"]).to eql(128) + expect(@plugin["cpu"]["total"]).to be(128) end it "gets the total processor count" do - expect(@plugin["cpu"]["real"]).to eql(1) + expect(@plugin["cpu"]["real"]).to be(1) end it "gets the total core count" do - expect(@plugin["cpu"]["cores"]).to eql(16) + expect(@plugin["cpu"]["cores"]).to be(16) end it "gets the number of threads per core" do - expect(@plugin["cpu"]["corethreads"]).to eql(8) + expect(@plugin["cpu"]["corethreads"]).to be(8) end it "gets the total number of online cores" do - expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(124) + expect(@plugin["cpu"]["cpustates"]["on-line"]).to be(124) end it "gets the total number of offline cores" do - expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(4) + expect(@plugin["cpu"]["cpustates"]["off-line"]).to be(4) end describe "per-cpu information" do diff --git a/spec/unit/plugins/virtualbox_spec.rb b/spec/unit/plugins/virtualbox_spec.rb index a884e3fa..98e15106 100644 --- a/spec/unit/plugins/virtualbox_spec.rb +++ b/spec/unit/plugins/virtualbox_spec.rb @@ -352,7 +352,7 @@ describe Ohai::System, "plugin virtualbox" do end context "when on a vbox host" do - context "if the host has virtualbox installed" do + context "when the host has virtualbox installed" do it "creates a vbox attribute with accurate data" do plugin[:virtualization][:systems][:vbox] = "host" allow(plugin).to receive(:which).with("VBoxManage").and_return("/usr/bin/VBoxManage") diff --git a/spec/unit/plugins/vmware_spec.rb b/spec/unit/plugins/vmware_spec.rb index 8e746940..86d13dc4 100644 --- a/spec/unit/plugins/vmware_spec.rb +++ b/spec/unit/plugins/vmware_spec.rb @@ -25,7 +25,7 @@ describe Ohai::System, "plugin vmware" do allow(plugin).to receive(:collect_os).and_return(:linux) end - context "on vmware guest with toolbox installed" do + context "when on vmware guest with toolbox installed" do before do allow(File).to receive(:exist?).with("/usr/bin/vmware-toolbox-cmd").and_return(true) allow(plugin).to receive(:shell_out).with("#{path} stat speed").and_return(mock_shell_out(0, "2000 MHz", nil)) @@ -58,7 +58,7 @@ describe Ohai::System, "plugin vmware" do end end - context "on vmware guest without toolbox" do + context "when on vmware guest without toolbox" do it "does not create a vmware attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new @@ -69,7 +69,7 @@ describe Ohai::System, "plugin vmware" do end end - context "on vbox guest" do + context "when on vbox guest" do it "does not create a vmware attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new diff --git a/spec/unit/plugins/windows/network_spec.rb b/spec/unit/plugins/windows/network_spec.rb index 2a7479ca..ff732cc7 100644 --- a/spec/unit/plugins/windows/network_spec.rb +++ b/spec/unit/plugins/windows/network_spec.rb @@ -29,12 +29,14 @@ describe Ohai::System, "Windows Network Plugin" do describe "#interface_code" do let(:interface_idx) { 1 } let(:index) { 2 } + context "when interface index is given" do it "Returns a valid string having hexadecimal interface_index" do index = nil expect(plugin.interface_code(interface_idx, index)).to eq("0x1") end end + context "when interface index is not given" do it "Returns a valid string having hexadecimal index" do interface_idx = nil @@ -46,35 +48,43 @@ describe Ohai::System, "Windows Network Plugin" do describe "#prefer_ipv4" do let(:inet4) { "192.168.1.1" } let(:inet6) { "fe80::2fe:c8ff:fef5:c88f" } - context "When Array is not passed" do + + context "when Array is not passed" do it "Returns nil" do expect(plugin.prefer_ipv4("Invalid")).to be_nil end end - context "When no address is passed in Array" do + + context "when no address is passed in Array" do it "Returns nil" do expect(plugin.prefer_ipv4([])).to be_nil end end - context "Preferred chances of IPV4 address" do + + context "preferred chances of IPV4 address" do it "Returns the address when only IPV4 address is passed" do expect(plugin.prefer_ipv4([inet4])).to eq(inet4) end - it "Returns the address when IPV6 is also present at latter place" do + + it "returns the address when IPV6 is also present at latter place" do expect(plugin.prefer_ipv4([inet4, inet6])).to eq(inet4) end - it "Returns the address when IPV6 is also present at former place" do + + it "returns the address when IPV6 is also present at former place" do expect(plugin.prefer_ipv4([inet6, inet4])).to eq(inet4) end end + context "Preferred chances of IPV6 address" do - it "Returns the address when only IPV6 address is passed" do + it "returns the address when only IPV6 address is passed" do expect(plugin.prefer_ipv4([inet4])).to eq(inet4) end - it "Does not return the address if IPV4 is also present at former place" do + + it "does not return the address if IPV4 is also present at former place" do expect(plugin.prefer_ipv4([inet4, inet6])).not_to eq(inet6) end - it "Does not return the address if IPV4 is also present at latter place" do + + it "does not return the address if IPV4 is also present at latter place" do expect(plugin.prefer_ipv4([inet6, inet4])).not_to eq(inet6) end end @@ -88,34 +98,40 @@ describe Ohai::System, "Windows Network Plugin" do "default_ip_gateway" => ["fe80::2fe:c8ff:fef5:c88f", "192.168.1.1"] } end let(:iface_config) { { 1 => interface1 } } - context "When a hash is not passed" do - it "Returns nil" do + + context "when a hash is not passed" do + it "returns nil" do expect(plugin.favored_default_route_windows("Invalid")).to be_nil end end - context "When no interface is passed in Hash" do - it "Returns nil" do + + context "when no interface is passed in Hash" do + it "returns nil" do expect(plugin.favored_default_route_windows({})).to be_nil end end - context "When an interface configuration is passed" do + + context "when an interface configuration is passed" do context "without default_ip_gateway" do - it "Returns nil" do + it "returns nil" do interface1["default_ip_gateway"] = nil expect(plugin.favored_default_route_windows(iface_config)).to be_nil end end + context "with default_ip_gateway" do - it "Returns a hash with details" do + it "returns a hash with details" do expect(plugin.favored_default_route_windows(iface_config)).to be_a(Hash) expect(plugin.favored_default_route_windows(iface_config)).not_to be_empty end - it "Returns the default_gateway in IPV4 format" do + + it "returns the default_gateway in IPV4 format" do expect(plugin.favored_default_route_windows(iface_config)).to include(default_ip_gateway: "192.168.1.1") end end end - context "When multiple interfaces are passed" do + + context "when multiple interfaces are passed" do let(:interface2) do { "index" => 2, "interface_index" => 3, @@ -126,10 +142,12 @@ describe Ohai::System, "Windows Network Plugin" do { 1 => interface1, 2 => interface2 } end - it "Returns the default route as least metric interface" do + + it "returns the default route as least metric interface" do expect(plugin.favored_default_route_windows(iface_config)).to include(interface_index: 1) end - it "Returns its default_gateway in IPV4 format" do + + it "returns its default_gateway in IPV4 format" do expect(plugin.favored_default_route_windows(iface_config)).to include(default_ip_gateway: "192.168.1.1") end end diff --git a/spec/unit/plugins/zpools_spec.rb b/spec/unit/plugins/zpools_spec.rb index fc16bc2e..5ed5a559 100644 --- a/spec/unit/plugins/zpools_spec.rb +++ b/spec/unit/plugins/zpools_spec.rb @@ -18,7 +18,7 @@ require "spec_helper" describe Ohai::System, "zpools plugin" do let(:plugin) { get_plugin("zpools") } - context "on Linux" do + context "when on Linux" do let(:zpool_status_tank) do <<-EOST pool: tank @@ -130,7 +130,7 @@ describe Ohai::System, "zpools plugin" do end end - context "on Solaris2" do + context "when on Solaris2" do let(:zpool_status_tank) do <<~EOST pool: tank diff --git a/spec/unit/provides_map_spec.rb b/spec/unit/provides_map_spec.rb index 6e689057..c1484ca1 100644 --- a/spec/unit/provides_map_spec.rb +++ b/spec/unit/provides_map_spec.rb @@ -22,7 +22,7 @@ require "spec_helper" describe Ohai::ProvidesMap do let(:ohai_system) { Ohai::System.new } - let(:provides_map) { Ohai::ProvidesMap.new } + let(:provides_map) { described_class.new } let(:plugin_1) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) } let(:plugin_2) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) } let(:plugin_3) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) } diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index ce111f4e..536ef17d 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -24,7 +24,7 @@ describe Ohai::Runner, "run_plugin" do before do @ohai = Ohai::System.new - @runner = Ohai::Runner.new(@ohai, safe_run) + @runner = described_class.new(@ohai, safe_run) end describe "when running an invalid plugin" do @@ -180,7 +180,7 @@ describe Ohai::Runner, "run_plugin" do describe "when running a plugin with many dependencies" do before do @ohai = Ohai::System.new - @runner = Ohai::Runner.new(@ohai, true) + @runner = described_class.new(@ohai, true) klass1 = Ohai.plugin(:One) do provides("one") @@ -220,7 +220,7 @@ describe Ohai::Runner, "run_plugin" do end describe "when a cycle is detected" do - let(:runner) { Ohai::Runner.new(@ohai, true) } + let(:runner) { described_class.new(@ohai, true) } context "when there are no edges in the cycle (A->A)" do let(:plugin_class) do @@ -278,7 +278,7 @@ describe Ohai::Runner, "run_plugin" do describe "when A depends on B and C, and B depends on C" do before do @ohai = Ohai::System.new - @runner = Ohai::Runner.new(@ohai, true) + @runner = described_class.new(@ohai, true) klass_a = Ohai.plugin(:A) do provides("A") @@ -335,7 +335,7 @@ describe Ohai::Runner, "fetch_plugins" do @provides_map = Ohai::ProvidesMap.new @data = Mash.new @ohai = double("Ohai::System", data: @data, provides_map: @provides_map, logger: Ohai::Log.with_child) - @runner = Ohai::Runner.new(@ohai, true) + @runner = described_class.new(@ohai, true) end it "collects the provider" do @@ -373,7 +373,7 @@ end describe Ohai::Runner, "#get_cycle" do before do @ohai = Ohai::System.new - @runner = Ohai::Runner.new(@ohai, true) + @runner = described_class.new(@ohai, true) klass1 = Ohai.plugin(:One) do provides("one") |