diff options
author | Tim Smith <tsmith84@gmail.com> | 2019-08-16 13:15:22 -0700 |
---|---|---|
committer | Tim Smith <tsmith84@gmail.com> | 2019-08-16 13:15:22 -0700 |
commit | 54b3cc831750805f19f838d60dea25e23dfa2e8c (patch) | |
tree | 81f539fca05ca2d0ed0761011913cd852b46d450 | |
parent | 038fd847c6d75dfaf6e60b67de185732aa245cc3 (diff) | |
download | ohai-54b3cc831750805f19f838d60dea25e23dfa2e8c.tar.gz |
rspec updates from rubocop-rspecrspec
Autocorrects for a few different things that rubocop-rspec identified.
Signed-off-by: Tim Smith <tsmith@chef.io>
131 files changed, 891 insertions, 818 deletions
diff --git a/spec/functional/application_spec.rb b/spec/functional/application_spec.rb index b222e532..5370c92c 100644 --- a/spec/functional/application_spec.rb +++ b/spec/functional/application_spec.rb @@ -25,12 +25,12 @@ RSpec.describe "Ohai::Application" do let(:argv) { [] } let(:stderr) { StringIO.new } - before(:each) do + before do @original_argv = ARGV.dup ARGV.replace(argv) end - after(:each) do + after do ARGV.replace(@original_argv) end @@ -40,13 +40,13 @@ RSpec.describe "Ohai::Application" do let(:config_dir) { Dir.mktmpdir(".chef") } let(:config_location) { File.join(config_dir, "config.rb") } - before(:each) do + before do File.open(config_location, "w+") do |f| f.write(config_content) end end - after(:each) do + after do FileUtils.rm_rf(config_dir) end @@ -74,7 +74,7 @@ RSpec.describe "Ohai::Application" do # https://github.com/chef/chef/blob/master/chef-config/lib/chef-config/workstation_config_loader.rb#L102 let(:env) { { "KNIFE_HOME" => config_dir } } - before(:each) do + before do allow_any_instance_of(ChefConfig::WorkstationConfigLoader) .to receive(:env).and_return(env) end diff --git a/spec/functional/loader_spec.rb b/spec/functional/loader_spec.rb index f1eb2c2f..02ba673f 100644 --- a/spec/functional/loader_spec.rb +++ b/spec/functional/loader_spec.rb @@ -25,7 +25,7 @@ RSpec.describe "Ohai::Loader" do let(:plugin_directory) { Dir.mktmpdir("plugins") } let(:plugin_path) { plugin_directory.tr("/", "\\") } - before(:each) do + before do Ohai.config[:plugin_path] = plugin_path plugin_content = <<~EOF @@ -38,7 +38,7 @@ RSpec.describe "Ohai::Loader" do end end - after(:each) do + after do FileUtils.rm_rf(plugin_directory) end diff --git a/spec/functional/plugins/powershell_spec.rb b/spec/functional/plugins/powershell_spec.rb index a4fa4d4b..c7058078 100644 --- a/spec/functional/plugins/powershell_spec.rb +++ b/spec/functional/plugins/powershell_spec.rb @@ -22,52 +22,58 @@ describe Ohai::System, "languages plugin" do VERSION_MATCHING_REGEX = /^(?:[\d]+\.)+[\d]+$/.freeze describe "powershell plugin", :windows_only do RSpec.shared_examples "a version looking thing" do - it "should be present" do + it "is present" do expect(subject).not_to be_nil end - it "should look like a version" do + it "looks like a version" do expect(subject).to match(VERSION_MATCHING_REGEX) end end + subject { @plugin[:languages][:powershell] } + before(:all) do @plugin = get_plugin("powershell") @plugin[:languages] = Mash.new @plugin.run end - subject { @plugin[:languages][:powershell] } - - it "should have information about powershell" do + it "has information about powershell" do expect(subject).not_to be_nil end describe :version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end describe :ws_man_stack_version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end describe :serialization_version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end describe :clr_version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end describe :build_version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end describe :remoting_protocol_version do subject { @plugin.languages[:powershell][described_class] } + it_behaves_like "a version looking thing" end diff --git a/spec/functional/plugins/root_group_spec.rb b/spec/functional/plugins/root_group_spec.rb index f52915a3..be0cb9dd 100644 --- a/spec/functional/plugins/root_group_spec.rb +++ b/spec/functional/plugins/root_group_spec.rb @@ -26,7 +26,7 @@ describe Ohai::System, "root_group plugin" do describe "windows platform", :windows_only do let(:wmi) { WmiLite::Wmi.new } - it "should return the system's administrators (root) group" do + it "returns the system's administrators (root) group" do # Notethat the Win32_Group WMI provider can be slow if your # system is domain-joined and has hundreds of thousands of # groups in Active Directory -- not a typical test scenario, but diff --git a/spec/functional/plugins/windows/uptime_spec.rb b/spec/functional/plugins/windows/uptime_spec.rb index c8ff75de..6b28caed 100644 --- a/spec/functional/plugins/windows/uptime_spec.rb +++ b/spec/functional/plugins/windows/uptime_spec.rb @@ -32,18 +32,18 @@ describe Ohai::System, "Windows plugin uptime" do }) end - before(:each) do + before do allow(uptime_plugin).to receive(:collect_os).and_return(:windows) allow(WmiLite::Wmi).to receive(:new).and_return(wmi) allow(Time).to receive_message_chain(:new, :to_i).and_return(1473756619) end - it "should set uptime_seconds to uptime" do + it "sets uptime_seconds to uptime" do uptime_plugin.run expect(uptime_plugin[:uptime_seconds]).to be == 80331 end - it "should set uptime to a human readable value" do + it "sets uptime to a human readable value" do uptime_plugin.run expect(uptime_plugin[:uptime]).to eq("22 hours 18 minutes 51 seconds") end diff --git a/spec/ohai_spec.rb b/spec/ohai_spec.rb index e57f7a39..c2701e76 100644 --- a/spec/ohai_spec.rb +++ b/spec/ohai_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai do - it "should have a version constant defined" do + it "has a version constant defined" do expect(Ohai::VERSION).to be_a_kind_of(String) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 94bdffc6..0eaf93fb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -16,8 +16,8 @@ PLUGIN_PATH = File.expand_path("../../lib/ohai/plugins", __FILE__) SPEC_PLUGIN_PATH = File.expand_path("../data/plugins", __FILE__) RSpec.configure do |config| - config.before(:each) { @object_pristine = Object.clone } - config.after(:each) { remove_constants } + config.before { @object_pristine = Object.clone } + config.after { remove_constants } end include Ohai::Mixin::ConstantHelper @@ -36,19 +36,19 @@ def convert_windows_output(stdout) end def it_should_check_from(plugin, attribute, from, value) - it "should set the #{attribute} to the value from '#{from}'" do + it "sets the #{attribute} to the value from '#{from}'" do @plugin.run expect(@plugin[attribute]).to eq(value) end end def it_should_check_from_mash(plugin, attribute, from, value) - it "should get the #{plugin}[:#{attribute}] value from '#{from}'" do + it "gets the #{plugin}[:#{attribute}] value from '#{from}'" do expect(@plugin).to receive(:shell_out).with(from).and_return(mock_shell_out(value[0], value[1], value[2])) @plugin.run end - it "should set the #{plugin}[:#{attribute}] to the value from '#{from}'" do + it "sets the #{plugin}[:#{attribute}] to the value from '#{from}'" do @plugin.run expect(@plugin[plugin][attribute]).to eq(value[1].split($/)[0]) end @@ -64,12 +64,12 @@ end # the mash variable may be an array listing multiple levels of Mash hierarchy def it_should_check_from_deep_mash(plugin, mash, attribute, from, value) - it "should get the #{mash.inspect}[:#{attribute}] value from '#{from}'" do + it "gets the #{mash.inspect}[:#{attribute}] value from '#{from}'" do expect(@plugin).to receive(:shell_out).with(from).and_return(mock_shell_out(value[0], value[1], value[2])) @plugin.run end - it "should set the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do + it "sets the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do @plugin.run value = value[1].split($/)[0] if mash.is_a?(String) @@ -114,7 +114,7 @@ RSpec.configure do |config| config.run_all_when_everything_filtered = true - config.before :each do + config.before do # TODO: Change to Ohai.config once Ohai::Config is deprecated fully. Needs # to stay Ohai::Config for now so that top-level attributes will get cleared # out between tests (config_spec should be the only place where top-level diff --git a/spec/support/integration_helper.rb b/spec/support/integration_helper.rb index 05c5de0c..7a02f20f 100644 --- a/spec/support/integration_helper.rb +++ b/spec/support/integration_helper.rb @@ -21,11 +21,11 @@ module IntegrationSupport def when_plugins_directory(description, &block) context "When the plugins directory #{description}" do - before(:each) do + before do @plugins_directory = Dir.mktmpdir("ohai-plugins") end - after(:each) do + after do if @plugins_directory begin FileUtils.remove_entry_secure(@plugins_directory) @@ -49,7 +49,7 @@ module IntegrationSupport end def self.with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition - before :each do + before do with_plugin(plugin_path, contents) end end diff --git a/spec/unit/application_spec.rb b/spec/unit/application_spec.rb index 765287b7..e38ad827 100644 --- a/spec/unit/application_spec.rb +++ b/spec/unit/application_spec.rb @@ -24,12 +24,12 @@ RSpec.describe "Ohai::Application" do let(:argv) { [] } let(:app) { Ohai::Application.new } - before(:each) do + before do @original_argv = ARGV ARGV.replace(argv) end - after(:each) do + after do ARGV.replace(@original_argv) end @@ -41,7 +41,7 @@ RSpec.describe "Ohai::Application" do context "when specified on the command line" do let(:argv) { [ "-c", config_file ] } - before(:each) do + before do if windows? expect(ChefConfig::WorkstationConfigLoader).to receive(:new) .with("C:#{config_file}", Ohai::Log) @@ -68,7 +68,7 @@ RSpec.describe "Ohai::Application" do end context "when a local workstation config exists" do - before(:each) do + before do expect(ChefConfig::WorkstationConfigLoader).to receive(:new) .with(nil, Ohai::Log) .and_return(config_loader) @@ -86,7 +86,7 @@ RSpec.describe "Ohai::Application" do let(:directory) { "/some/fantastic/plugins" } it "does not generate deprecated config warnings for cli options" do - expect(Ohai::Log).to_not receive(:warn) + expect(Ohai::Log).not_to receive(:warn) .with(/Ohai::Config\[:directory\] is deprecated/) app.configure_ohai end diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb index 5119fed7..2553e098 100644 --- a/spec/unit/dsl/plugin_spec.rb +++ b/spec/unit/dsl/plugin_spec.rb @@ -155,7 +155,7 @@ shared_examples "Ohai::DSL::Plugin" do end context "when getting attributes" do - before(:each) do + before do plugin.set_attribute(:tea, "is soothing") end @@ -170,7 +170,7 @@ shared_examples "Ohai::DSL::Plugin" do end describe "a top-level attribute" do - before(:each) do + before do plugin.set_attribute(:tea, "is soothing") end @@ -196,7 +196,7 @@ shared_examples "Ohai::DSL::Plugin" do end describe "a nested attribute" do - before(:each) do + before do plugin.set_attribute(:the_monarch, { arch_rival: "dr_venture" }) end @@ -304,7 +304,7 @@ shared_examples "Ohai::DSL::Plugin" do end describe "a nested attribute" do - before(:each) do + before do plugin.set_attribute(:the_monarch, { arch_rival: "dr_venture" }) end @@ -383,9 +383,10 @@ end describe Ohai::DSL::Plugin::VersionVII do let(:logger) { Ohai::Log } + it "does not modify the plugin name when the plugin is named correctly" do plugin = Ohai.plugin(:FunkyVALIDpluginName) {}.new({}, logger) - expect(plugin.name).to eql(:FunkyVALIDpluginName) + expect(plugin.name).to be(:FunkyVALIDpluginName) end describe "when the plugin is named incorrectly" do @@ -411,7 +412,7 @@ describe Ohai::DSL::Plugin::VersionVII do describe "#version" do it "saves the plugin version as :version7" do plugin = Ohai.plugin(:Test) {} - expect(plugin.version).to eql(:version7) + expect(plugin.version).to be(:version7) end end @@ -575,7 +576,7 @@ describe Ohai::DSL::Plugin::VersionVII do it "does not auto-vivify an un-configured plugin" do plugin.configuration(:foo) - expect(Ohai.config[:plugin]).to_not have_key(:test) + expect(Ohai.config[:plugin]).not_to have_key(:test) end it "returns nil when the option is not configured" do diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb index 6e0d9cf0..3086e36c 100644 --- a/spec/unit/mixin/command_spec.rb +++ b/spec/unit/mixin/command_spec.rb @@ -30,14 +30,14 @@ describe Ohai::Mixin::Command, "shell_out" do let(:logger) { instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) } - before(:each) do + before do allow(Ohai::Mixin::Command).to receive(:logger).and_return(logger) allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name) @original_env = ENV.to_hash ENV.clear end - after(:each) do + after do ENV.clear ENV.update(@original_env) end diff --git a/spec/unit/plugins/abort_spec.rb b/spec/unit/plugins/abort_spec.rb index 8384997c..68531eb1 100644 --- a/spec/unit/plugins/abort_spec.rb +++ b/spec/unit/plugins/abort_spec.rb @@ -38,13 +38,13 @@ describe "a plug-in that aborts execution" do end - before(:each) do + before do fail_file = File.open("#{tmp}/plugins/abort.rb", "w+") fail_file.write(abortstr) fail_file.close end - after(:each) do + after do File.delete("#{tmp}/plugins/abort.rb") end @@ -56,13 +56,13 @@ describe "a plug-in that aborts execution" do end - before(:each) do + before do @ohai = Ohai::System.new @loader = Ohai::Loader.new(@ohai) @runner = Ohai::Runner.new(@ohai) end - it "should raise SystemExit" do + it "raises SystemExit" do @plugin = @loader.load_plugin("#{tmp}/plugins/abort.rb") expect { @runner.run_plugin(@plugin) }.to raise_error(SystemExit) end diff --git a/spec/unit/plugins/aix/cpu_spec.rb b/spec/unit/plugins/aix/cpu_spec.rb index 98150dfa..146534e2 100644 --- a/spec/unit/plugins/aix/cpu_spec.rb +++ b/spec/unit/plugins/aix/cpu_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "AIX cpu plugin" do - before(:each) do + before do @lsdev_cc_processor = <<~LSDEV_CC_PROCESSOR proc0 Available 00-00 Processor proc4 Defined 00-04 Processor diff --git a/spec/unit/plugins/aix/filesystem_spec.rb b/spec/unit/plugins/aix/filesystem_spec.rb index 78fd0de1..9770f286 100644 --- a/spec/unit/plugins/aix/filesystem_spec.rb +++ b/spec/unit/plugins/aix/filesystem_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "AIX filesystem plugin" do - before(:each) do + before do @df_pk_lpar = <<~DF_PK Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hd4 2097152 219796 1877356 11% / diff --git a/spec/unit/plugins/aix/hostname_spec.rb b/spec/unit/plugins/aix/hostname_spec.rb index 9600c956..0fcfcc5e 100644 --- a/spec/unit/plugins/aix/hostname_spec.rb +++ b/spec/unit/plugins/aix/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "AIX hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:from_cmd).with("hostname -s").and_return("aix_admin") @@ -27,7 +27,7 @@ describe Ohai::System, "AIX hostname plugin" do @plugin.run end - it "should set the machinename" do + it "sets the machinename" do expect(@plugin[:machinename]).to eql("aix_admin") end end diff --git a/spec/unit/plugins/aix/kernel_spec.rb b/spec/unit/plugins/aix/kernel_spec.rb index 686f8a56..c9138bc8 100644 --- a/spec/unit/plugins/aix/kernel_spec.rb +++ b/spec/unit/plugins/aix/kernel_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "AIX kernel plugin" do - before(:each) do + before do @plugin = get_plugin("aix/kernel") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "AIX", nil)) diff --git a/spec/unit/plugins/aix/memory_spec.rb b/spec/unit/plugins/aix/memory_spec.rb index 232009dd..e5b86b61 100644 --- a/spec/unit/plugins/aix/memory_spec.rb +++ b/spec/unit/plugins/aix/memory_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "AIX memory plugin" do - before(:each) do + before do @plugin = get_plugin("aix/memory") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).with("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'").and_return(mock_shell_out(0, " 513280.00 340034.17 173245.83 62535.17 230400.05 276950.14 70176.00\n", nil)) @@ -27,22 +27,22 @@ describe Ohai::System, "AIX memory plugin" do allow(@plugin).to receive(:shell_out).with("swap -s").and_return(mock_shell_out(0, @swap_s, nil)) end - it "should get total memory" do + it "gets total memory" do @plugin.run expect(@plugin["memory"]["total"]).to eql("#{513280 * 1024}kB") end - it "should get free memory" do + it "gets free memory" do @plugin.run expect(@plugin["memory"]["free"]).to eql("#{173245.83.to_i * 1024}kB") end - it "should get total swap" do + it "gets total swap" do @plugin.run expect(@plugin["memory"]["swap"]["total"]).to eql( "#{23887872 * 4}kB") end - it "should get free swap" do + it "gets free swap" do @plugin.run expect(@plugin["memory"]["swap"]["free"]).to eql( "#{23598960 * 4}kB") end diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb index 801e4f4e..a290e48a 100644 --- a/spec/unit/plugins/aix/network_spec.rb +++ b/spec/unit/plugins/aix/network_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai::System, "AIX network plugin" do - before(:each) do + before do @netstat_rn_grep_default = <<~NETSTAT_RN_GREP_DEFAULT default 172.31.8.1 UG 2 121789 en0 - - NETSTAT_RN_GREP_DEFAULT @@ -232,6 +232,7 @@ describe Ohai::System, "AIX network plugin" do @plugin.run @inet_interface_addresses = @plugin["network"]["interfaces"]["en0"][:addresses]["BE:42:80:00:B0:05"] end + it "detects the family" do expect(@inet_interface_addresses[:family]).to eq("lladdr") end @@ -286,6 +287,7 @@ describe Ohai::System, "AIX network plugin" do before do @plugin.run end + it "supresses the hostname entries" do expect(@plugin["network"]["arp"][0][:remote_host]).to eq("?") end @@ -303,6 +305,7 @@ describe Ohai::System, "AIX network plugin" do before do @plugin.run end + it "converts a netmask from hexadecimal form to decimal form" do expect(@plugin.hex_to_dec_netmask("0xffff0000")).to eq("255.255.0.0") end diff --git a/spec/unit/plugins/aix/platform_spec.rb b/spec/unit/plugins/aix/platform_spec.rb index c3e3e6fa..32816d84 100644 --- a/spec/unit/plugins/aix/platform_spec.rb +++ b/spec/unit/plugins/aix/platform_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Aix plugin platform" do - before(:each) do + before do @plugin = get_plugin("aix/platform") allow(@plugin).to receive(:collect_os).and_return(:aix) kernel = Mash.new @@ -30,15 +30,15 @@ describe Ohai::System, "Aix plugin platform" do @plugin.run end - it "should set platform to aix" do + it "sets platform to aix" do expect(@plugin[:platform]).to eq("aix") end - it "should set the platform_version" do + it "sets the platform_version" do expect(@plugin[:platform_version]).to eq("7.1") end - it "should set platform_family" do + it "sets platform_family" do expect(@plugin[:platform_family]).to eq(@plugin[:platform]) end end diff --git a/spec/unit/plugins/aix/uptime_spec.rb b/spec/unit/plugins/aix/uptime_spec.rb index b54bb4be..3023d41f 100644 --- a/spec/unit/plugins/aix/uptime_spec.rb +++ b/spec/unit/plugins/aix/uptime_spec.rb @@ -20,20 +20,20 @@ require "spec_helper" describe Ohai::System, "Aix plugin uptime" do - before(:each) do + before do @plugin = get_plugin("aix/uptime") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).and_call_original end - it "should set uptime_seconds and uptime standard case" do + it "sets uptime_seconds and uptime standard case" do allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil)) @plugin.run expect(@plugin[:uptime_seconds]).to eq(99262490) expect(@plugin[:uptime]).to eq("1148 days 20 hours 54 minutes 50 seconds") end - it "should set uptime_seconds and uptime in the whitespace case" do + it "sets uptime_seconds and uptime in the whitespace case" do allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, " 2-20:54:50", nil)) @plugin.run expect(@plugin[:uptime_seconds]).to eq(248090) diff --git a/spec/unit/plugins/aix/virtualization_spec.rb b/spec/unit/plugins/aix/virtualization_spec.rb index 46add5c4..70f3ad79 100644 --- a/spec/unit/plugins/aix/virtualization_spec.rb +++ b/spec/unit/plugins/aix/virtualization_spec.rb @@ -31,7 +31,7 @@ describe Ohai::System, "AIX virtualization plugin" do p end - before(:each) do + before do @lswpar_l = <<~LSWPAR_L ================================================================= applejack-541ba3 - Active diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index abddd25f..f11a2b9b 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -74,7 +74,7 @@ describe Ohai::System, "plugin azure" do end describe "with azure hint file" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return(hint) end @@ -90,7 +90,7 @@ describe Ohai::System, "plugin azure" do end describe "without azure hint file or agent or dhcp options" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false) allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false) @@ -123,7 +123,7 @@ describe Ohai::System, "plugin azure" do end describe "with rackspace hint file, no agent, and no dhcp lease" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("rackspace").and_return(true) allow(plugin).to receive(:hint?).with("azure").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false) @@ -135,7 +135,7 @@ describe Ohai::System, "plugin azure" do end describe "without azure hint file but with agent on linux" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(true) allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false) @@ -145,7 +145,7 @@ describe Ohai::System, "plugin azure" do end describe "without azure hint file but with agent on windows" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false) allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(true) @@ -155,7 +155,7 @@ describe Ohai::System, "plugin azure" do end describe "without azure hint or agent but with dhcp option" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/waagent").and_return(false) allow(Dir).to receive(:exist?).with('C:\WindowsAzure').and_return(false) @@ -188,7 +188,7 @@ describe Ohai::System, "plugin azure" do end describe "with non-responsive metadata endpoint" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return({}) end @@ -205,7 +205,7 @@ describe Ohai::System, "plugin azure" do end describe "with responsive metadata endpoint" do - before(:each) do + before do allow(plugin).to receive(:hint?).with("azure").and_return({}) allow(plugin).to receive(:can_socket_connect?) .with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80) diff --git a/spec/unit/plugins/bsd/filesystem_spec.rb b/spec/unit/plugins/bsd/filesystem_spec.rb index e3d8be5e..f4982de3 100644 --- a/spec/unit/plugins/bsd/filesystem_spec.rb +++ b/spec/unit/plugins/bsd/filesystem_spec.rb @@ -21,7 +21,8 @@ require "spec_helper" describe Ohai::System, "BSD filesystem plugin" do let(:plugin) { get_plugin("filesystem") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:freebsd) allow(plugin).to receive(:shell_out).with("df").and_return(mock_shell_out(0, "", "")) @@ -30,7 +31,7 @@ describe Ohai::System, "BSD filesystem plugin" do end describe "when gathering filesystem usage data from df" do - before(:each) do + before do @stdout = <<~DF Filesystem 1K-blocks Used Avail Capacity Mounted on /dev/ada0p2 9637788 3313504 5553264 37% / @@ -46,55 +47,55 @@ describe Ohai::System, "BSD filesystem plugin" do allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) end - it "should run df and df -iP" do + it "runs df and df -iP" do expect(plugin).to receive(:shell_out).ordered.with("df").and_return(mock_shell_out(0, @stdout, "")) expect(plugin).to receive(:shell_out).ordered.with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) plugin.run end - it "should set kb_size to value from df" do + it "sets kb_size to value from df" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:kb_size]).to eq("9637788") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:kb_size]).to eq("9637788") end - it "should set kb_used to value from df" do + it "sets kb_used to value from df" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:kb_used]).to eq("3313504") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:kb_used]).to eq("3313504") end - it "should set kb_available to value from df" do + it "sets kb_available to value from df" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:kb_available]).to eq("5553264") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:kb_available]).to eq("5553264") end - it "should set percent_used to value from df" do + it "sets percent_used to value from df" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:percent_used]).to eq("37%") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:percent_used]).to eq("37%") end - it "should set mount to value from df" do + it "sets mount to value from df" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:mount]).to eq("/") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:mount]).to eq("/") end - it "should set total_inodes to value from df -iP" do + it "sets total_inodes to value from df -iP" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:total_inodes]).to eq("1043326") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:total_inodes]).to eq("1043326") end - it "should set inodes_used to value from df -iP" do + it "sets inodes_used to value from df -iP" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:inodes_used]).to eq("252576") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:inodes_used]).to eq("252576") end - it "should set inodes_available to value from df -iP" do + it "sets inodes_available to value from df -iP" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:inodes_available]).to eq("790750") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:inodes_available]).to eq("790750") @@ -102,7 +103,7 @@ describe Ohai::System, "BSD filesystem plugin" do end describe "when gathering mounted filesystem data from mount" do - before(:each) do + before do @stdout = <<~MOUNT /dev/ada0p2 on / (ufs, local, journaled soft-updates) devfs on /dev (devfs, local, multilabel) @@ -110,24 +111,24 @@ describe Ohai::System, "BSD filesystem plugin" do allow(plugin).to receive(:shell_out).with("mount -l").and_return(mock_shell_out(0, @stdout, "")) end - it "should run mount" do + it "runs mount" do expect(plugin).to receive(:shell_out).with("mount -l").and_return(mock_shell_out(0, @stdout, "")) plugin.run end - it "should set mount to value from mount" do + it "sets mount to value from mount" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:mount]).to eq("/") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:mount]).to eq("/") end - it "should set fs_type to value from mount" do + it "sets fs_type to value from mount" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:fs_type]).to eq("ufs") expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:fs_type]).to eq("ufs") end - it "should set mount_options to an array of values from mount" do + it "sets mount_options to an array of values from mount" do plugin.run expect(plugin[:filesystem]["/dev/ada0p2"][:mount_options]).to eq(["local", "journaled soft-updates"]) expect(plugin[:filesystem2]["by_pair"]["/dev/ada0p2,/"][:mount_options]).to eq(["local", "journaled soft-updates"]) diff --git a/spec/unit/plugins/bsd/virtualization_spec.rb b/spec/unit/plugins/bsd/virtualization_spec.rb index 74e31e0f..8001695c 100644 --- a/spec/unit/plugins/bsd/virtualization_spec.rb +++ b/spec/unit/plugins/bsd/virtualization_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "BSD virtualization plugin" do let(:plugin) { get_plugin("bsd/virtualization") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:freebsd) allow(plugin).to receive(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "0", "")) allow(plugin).to receive(:shell_out).with((Ohai.abs_path( "/sbin/kldstat" )).to_s).and_return(mock_shell_out(0, "", "")) diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 4f0a4665..99356b3a 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -74,7 +74,7 @@ describe Ohai::System, "plugin c" do let(:plugin) { get_plugin("c") } - before(:each) do + before do plugin[:languages] = Mash.new # gcc @@ -82,7 +82,7 @@ describe Ohai::System, "plugin c" do end context "on AIX" do - before(:each) 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, "")) end @@ -123,8 +123,9 @@ describe Ohai::System, "plugin c" do end end + context "on Darwin" do - before(:each) 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) end @@ -143,7 +144,7 @@ describe Ohai::System, "plugin c" do end context "on Windows" do - before(:each) 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)) allow(plugin).to receive(:shell_out).with("devenv.com /\?").and_return(mock_shell_out(0, C_VS, "")) @@ -209,7 +210,7 @@ describe Ohai::System, "plugin c" do end context "on Linux" do - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) # glibc allow(plugin).to receive(:shell_out).with("/lib/libc.so.6").and_return(mock_shell_out(0, C_GLIBC, "")) diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb index 3fd779ac..1596e152 100644 --- a/spec/unit/plugins/chef_spec.rb +++ b/spec/unit/plugins/chef_spec.rb @@ -23,11 +23,11 @@ begin require "chef/version" describe Ohai::System, "plugin chef" do - before(:each) do + before do @plugin = get_plugin("chef") end - it "should set [:chef_packages][:chef][:version] to the current chef version", if: defined?(Chef) do + it "sets [:chef_packages][:chef][:version] to the current chef version", if: defined?(Chef) do @plugin.run expect(@plugin[:chef_packages][:chef][:version]).to eq(Chef::VERSION) end diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb index 5c9d25f0..d805c93c 100644 --- a/spec/unit/plugins/cloud_spec.rb +++ b/spec/unit/plugins/cloud_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" require "ipaddr" describe "CloudAttrs object" do - before(:each) do + before do @plugin = get_plugin("cloud") end @@ -73,7 +73,7 @@ describe "CloudAttrs object" do end describe Ohai::System, "plugin cloud" do - before(:each) do + before do @plugin = get_plugin("cloud") end @@ -335,7 +335,7 @@ describe Ohai::System, "plugin cloud" do expect(@plugin[:cloud][:public_ssh_port]).to be_nil end - it "should not populate cloud public_ssh_port when winrm is used" do + it "does not populate cloud public_ssh_port when winrm is used" do @plugin[:azure]["public_winrm_port"] = "5985" @plugin.run expect(@plugin[:cloud][:public_ssh_port]).to be_nil @@ -399,7 +399,7 @@ describe Ohai::System, "plugin cloud" do } end - before(:each) do + before do @plugin.run end diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb index 75461638..1c0313c4 100644 --- a/spec/unit/plugins/darwin/cpu_spec.rb +++ b/spec/unit/plugins/darwin/cpu_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Darwin cpu plugin" do - before(:each) do + before do @plugin = get_plugin("cpu") @stdout = <<~CTL hw.ncpu: 8 @@ -82,43 +82,43 @@ describe Ohai::System, "Darwin cpu plugin" do @plugin.run end - it "should set cpu[:cores] to 4" do + it "sets cpu[:cores] to 4" do expect(@plugin[:cpu][:cores]).to eq(4) end - it "should set cpu[:total] to 8" do + it "sets cpu[:total] to 8" do expect(@plugin[:cpu][:total]).to eq(8) end - it "should set cpu[:real] to 1" do + it "sets cpu[:real] to 1" do expect(@plugin[:cpu][:real]).to eq(1) end - it "should set cpu[:mhz] to 2800" do + it "sets cpu[:mhz] to 2800" do expect(@plugin[:cpu][:mhz]).to eq(2800) end - it "should set cpu[:vendor_id] to GenuineIntel" do + it "sets cpu[:vendor_id] to GenuineIntel" do expect(@plugin[:cpu][:vendor_id]).to eq("GenuineIntel") end - it "should set cpu[:model_name] to Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz" do + it "sets cpu[:model_name] to Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz" do expect(@plugin[:cpu][:model_name]).to eq("Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz") end - it "should set cpu[:model] to 70" do + it "sets cpu[:model] to 70" do expect(@plugin[:cpu][:model]).to eq(70) end - it "should set cpu[:family] to 6" do + it "sets cpu[:family] to 6" do expect(@plugin[:cpu][:family]).to eq(6) end - it "should set cpu[:stepping] to 1" do + it "sets cpu[:stepping] to 1" do expect(@plugin[:cpu][:stepping]).to eq(1) end - it "should set cpu[:flags] to array of flags" do + it "sets cpu[:flags] to array of flags" do expect(@plugin[:cpu][:flags]).to eq(["fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce", "cx8", "apic", "sep", "mtrr", "pge", "mca", "cmov", "pat", "pse36", "clfsh", "ds", "acpi", "mmx", "fxsr", "sse", "sse2", "ss", "htt", "tm", "pbe", "sse3", "pclmulqdq", "dtes64", "mon", "dscpl", "vmx", "smx", "est", "tm2", "ssse3", "fma", "cx16", "tpr", "pdcm", "sse4.1", "sse4.2", "x2apic", "movbe", "popcnt", "aes", "pcid", "xsave", "osxsave", "seglim64", "tsctmr", "avx1.0", "rdrand", "f16c"]) end end diff --git a/spec/unit/plugins/darwin/filesystem_spec.rb b/spec/unit/plugins/darwin/filesystem_spec.rb index df0c19fc..e971f622 100644 --- a/spec/unit/plugins/darwin/filesystem_spec.rb +++ b/spec/unit/plugins/darwin/filesystem_spec.rb @@ -20,7 +20,8 @@ require "spec_helper" describe Ohai::System, "darwin filesystem plugin" do let(:plugin) { get_plugin("filesystem") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:darwin) allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, "", "")) @@ -28,7 +29,7 @@ describe Ohai::System, "darwin filesystem plugin" do end describe "when gathering filesystem usage data from df" do - before(:each) do + before do @stdout = <<~DF Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / @@ -41,12 +42,12 @@ describe Ohai::System, "darwin filesystem plugin" do allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @stdout, "")) end - it "should run df -i" do + it "runs df -i" do expect(plugin).to receive(:shell_out).ordered.with("df -i").and_return(mock_shell_out(0, @stdout, "")) plugin.run end - it "should set size to value from df -i" do + it "sets size to value from df -i" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768") expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224") @@ -54,13 +55,13 @@ describe Ohai::System, "darwin filesystem plugin" do expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%") end - it "should set device and mount to value from df -i" do + it "sets device and mount to value from df -i" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2") end - it "should set inode info to value from df -i" do + it "sets inode info to value from df -i" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440") expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054") @@ -69,7 +70,7 @@ describe Ohai::System, "darwin filesystem plugin" do end describe "when gathering mounted filesystem data from mount" do - before(:each) do + before do @stdout = <<~MOUNT /dev/disk0s2 on / (hfs, local, journaled) devfs on /dev (devfs, local, nobrowse) @@ -81,12 +82,12 @@ describe Ohai::System, "darwin filesystem plugin" do allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) end - it "should run mount" do + it "runs mount" do expect(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) plugin.run end - it "should set values from mount" do + it "sets values from mount" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs") @@ -95,7 +96,7 @@ describe Ohai::System, "darwin filesystem plugin" do end describe "when gathering filesystem data with devices mounted more than once" do - before(:each) do + before do @dfstdout = <<~DF Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / @@ -109,14 +110,14 @@ describe Ohai::System, "darwin filesystem plugin" do allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) end - it "should provide a devices view with all mountpoints" do + it "provides a devices view with all mountpoints" do plugin.run expect(plugin[:filesystem]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"]) end end describe "when gathering filesystem data with double-mounts" do - before(:each) do + before do @dfstdout = <<~DF Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on /dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / @@ -131,7 +132,7 @@ describe Ohai::System, "darwin filesystem plugin" do allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) end - it "should provide a mounts view with all devices" do + it "provides a mounts view with all devices" do plugin.run expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"]) end diff --git a/spec/unit/plugins/darwin/hardware_spec.rb b/spec/unit/plugins/darwin/hardware_spec.rb index 41886cd0..e29b1e2e 100644 --- a/spec/unit/plugins/darwin/hardware_spec.rb +++ b/spec/unit/plugins/darwin/hardware_spec.rb @@ -21,7 +21,8 @@ require_relative "hardware_system_profiler_output" describe Ohai::System, "Darwin hardware plugin", :unix_only do let(:plugin) { get_plugin("darwin/hardware") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:darwin) # Make sure it always runs correct commands and mock the data as it calls them allow(plugin).to receive(:shell_out).with( diff --git a/spec/unit/plugins/darwin/hostname_spec.rb b/spec/unit/plugins/darwin/hostname_spec.rb index b0028936..b4ab4ccd 100644 --- a/spec/unit/plugins/darwin/hostname_spec.rb +++ b/spec/unit/plugins/darwin/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Darwin hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:darwin) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", "")) @@ -31,12 +31,12 @@ describe Ohai::System, "Darwin hostname plugin" do it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - it "should use #resolve_fqdn to find the fqdn" do + it "uses #resolve_fqdn to find the fqdn" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.bethell") end - it "should set the domain to everything after the first dot of the fqdn" do + it "sets the domain to everything after the first dot of the fqdn" do @plugin.run expect(@plugin[:domain]).to eq("bethell") end diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb index 70d58815..2cf727be 100644 --- a/spec/unit/plugins/darwin/kernel_spec.rb +++ b/spec/unit/plugins/darwin/kernel_spec.rb @@ -19,13 +19,13 @@ require "spec_helper" describe Ohai::System, "Darwin kernel plugin" do - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:darwin) allow(@plugin).to receive(:init_kernel).and_return({}) end - it "should populate kernel[:modules] from `kextstat -k -l`" do + it "populates kernel[:modules] from `kextstat -k -l`" do allow(@plugin).to receive(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "0", "")) allow(@plugin).to receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, <<EOF, "")) 8 0 0xffffff7f81aed000 0x41000 0x41000 com.apple.kec.corecrypto (1.0) <7 6 5 4 3 1> @@ -42,21 +42,21 @@ EOF expect(@plugin[:kernel][:modules]).to eql(modules) end - it "should not set kernel_machine to x86_64" do + it "does not set kernel_machine to x86_64" do allow(@plugin).to receive(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "0", "")) allow(@plugin).to receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run expect(@plugin[:kernel][:machine]).not_to eq("x86_64") end - it "should set kernel_machine to x86_64" do + it "sets kernel_machine to x86_64" do allow(@plugin).to receive(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "1", "")) allow(@plugin).to receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run expect(@plugin[:kernel][:machine]).to eq("x86_64") end - it "should set the kernel_os to the kernel_name value" do + it "sets the kernel_os to the kernel_name value" do allow(@plugin).to receive(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "1", "")) allow(@plugin).to receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) @plugin.run diff --git a/spec/unit/plugins/darwin/memory_spec.rb b/spec/unit/plugins/darwin/memory_spec.rb index 07f6fa3e..1baf96d0 100644 --- a/spec/unit/plugins/darwin/memory_spec.rb +++ b/spec/unit/plugins/darwin/memory_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Darwin Memory Plugin" do - before(:each) do + before do darwin_memsize = <<~DARWIN_MEMSIZE 17179869184 DARWIN_MEMSIZE @@ -46,19 +46,19 @@ describe Ohai::System, "Darwin Memory Plugin" do @plugin.run end - it "should set memory[:total] to 16384MB" do + it "sets memory[:total] to 16384MB" do expect(@plugin[:memory][:total]).to eq("16384MB") end - it "should set memory[:active] to 5140MB" do + it "sets memory[:active] to 5140MB" do expect(@plugin[:memory][:active]).to eq("5140MB") end - it "should set memory[:inactive] to 738MB" do + it "sets memory[:inactive] to 738MB" do expect(@plugin[:memory][:inactive]).to eq("738MB") end - it "should set memory[:free] to 10504MB" do + it "sets memory[:free] to 10504MB" do expect(@plugin[:memory][:free]).to eq("10504MB") end end diff --git a/spec/unit/plugins/darwin/network_spec.rb b/spec/unit/plugins/darwin/network_spec.rb index d076bc6b..46e53518 100644 --- a/spec/unit/plugins/darwin/network_spec.rb +++ b/spec/unit/plugins/darwin/network_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Darwin Network Plugin" do - before(:each) do + before do @darwin_ifconfig = <<~DARWIN_IFCONFIG lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 options=3<RXCSUM,TXCSUM> @@ -430,7 +430,7 @@ describe Ohai::System, "Darwin Network Plugin" do end describe "gathering IP layer address info" do - before(:each) do + before do allow(@plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, @darwin_arp, "")) allow(@plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @darwin_ifconfig, "")) allow(@plugin).to receive(:shell_out).with("netstat -i -d -l -b -n").and_return(mock_shell_out(0, @darwin_netstat, "")) @@ -549,7 +549,7 @@ describe Ohai::System, "Darwin Network Plugin" do expect(@plugin["network"][:default_gateway]).to eq("10.20.10.1") end - it "should detect network settings" do + it "detects network settings" do expect(@plugin["network"]["settings"]["net.local.stream.sendspace"]).to eq("8192") expect(@plugin["network"]["settings"]["net.local.stream.recvspace"]).to eq("8192") expect(@plugin["network"]["settings"]["net.local.stream.tracemdns"]).to eq("0") diff --git a/spec/unit/plugins/darwin/platform_spec.rb b/spec/unit/plugins/darwin/platform_spec.rb index 96184212..ecd2c5f0 100644 --- a/spec/unit/plugins/darwin/platform_spec.rb +++ b/spec/unit/plugins/darwin/platform_spec.rb @@ -19,51 +19,51 @@ require "spec_helper" describe Ohai::System, "Darwin plugin platform" do - before(:each) do + before do @plugin = get_plugin("darwin/platform") allow(@plugin).to receive(:collect_os).and_return(:darwin) @stdout = "ProductName: Mac OS X\nProductVersion: 10.5.5\nBuildVersion: 9F33" allow(@plugin).to receive(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, "")) end - it "should run sw_vers" do + it "runs sw_vers" do expect(@plugin).to receive(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, "")) @plugin.run end - it "should set platform to ProductName, downcased with _ for \\s" do + it "sets platform to ProductName, downcased with _ for \\s" do @plugin.run expect(@plugin[:platform]).to eq("mac_os_x") end - it "should set platform_version to ProductVersion" do + it "sets platform_version to ProductVersion" do @plugin.run expect(@plugin[:platform_version]).to eq("10.5.5") end - it "should set platform_build to BuildVersion" do + it "sets platform_build to BuildVersion" do @plugin.run expect(@plugin[:platform_build]).to eq("9F33") end - it "should set platform_family to mac_os_x" do + it "sets platform_family to mac_os_x" do @plugin.run expect(@plugin[:platform_family]).to eq("mac_os_x") end describe "on os x server" do - before(:each) do + before do @plugin[:os] = "darwin" @stdout = "ProductName: Mac OS X Server\nProductVersion: 10.6.8\nBuildVersion: 10K549" allow(@plugin).to receive(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, "")) end - it "should set platform to mac_os_x_server" do + it "sets platform to mac_os_x_server" do @plugin.run expect(@plugin[:platform]).to eq("mac_os_x_server") end - it "should set platform_family to mac_os_x" do + it "sets platform_family to mac_os_x" do @plugin.run expect(@plugin[:platform_family]).to eq("mac_os_x") end diff --git a/spec/unit/plugins/darwin/virtualization_spec.rb b/spec/unit/plugins/darwin/virtualization_spec.rb index 2fe3ad01..55936c93 100644 --- a/spec/unit/plugins/darwin/virtualization_spec.rb +++ b/spec/unit/plugins/darwin/virtualization_spec.rb @@ -23,7 +23,7 @@ require "spec_helper" describe Ohai::System, "Darwin virtualization platform" do let(:plugin) { get_plugin("darwin/virtualization") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:darwin) allow(plugin).to receive(:prlctl_exists?).and_return(false) allow(plugin).to receive(:ioreg_exists?).and_return(false) @@ -35,12 +35,12 @@ describe Ohai::System, "Darwin virtualization platform" do end describe "when detecting OS X virtualization" do - it "should not set virtualization keys if no binaries are found" do + it "does not set virtualization keys if no binaries are found" do plugin.run expect(plugin[:virtualization]).to eq({ "systems" => {} }) end - it "should set docker host if docker exists" do + it "sets docker host if docker exists" do allow(plugin).to receive(:docker_exists?).and_return(true) plugin.run expect(plugin[:virtualization][:system]).to eq("docker") @@ -48,7 +48,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:docker]).to eq("host") end - it "should set vmware host if /Applications/VMware\ Fusion.app exists" do + it "sets vmware host if /Applications/VMware\ Fusion.app exists" do allow(plugin).to receive(:fusion_exists?).and_return(true) plugin.run expect(plugin[:virtualization][:system]).to eq("vmware") @@ -56,7 +56,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:vmware]).to eq("host") end - it "should set vmware guest if hardware attributes mention vmware" do + it "sets vmware guest if hardware attributes mention vmware" do plugin[:hardware][:boot_rom_version] = "VMW71.00V.6997262.B64.1710270607" plugin.run expect(plugin[:virtualization][:system]).to eq("vmware") @@ -64,7 +64,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:vmware]).to eq("guest") end - it "should set vbox host if /usr/local/bin/VBoxManage exists" do + it "sets vbox host if /usr/local/bin/VBoxManage exists" do allow(plugin).to receive(:vboxmanage_exists?).and_return("/usr/local/bin/VBoxManage") plugin.run expect(plugin[:virtualization][:system]).to eq("vbox") @@ -72,7 +72,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:vbox]).to eq("host") end - it "should set vbox guest if hardware attributes mention virtualbox" do + it "sets vbox guest if hardware attributes mention virtualbox" do plugin[:hardware][:boot_rom_version] = "VirtualBox" plugin.run expect(plugin[:virtualization][:system]).to eq("vbox") @@ -80,7 +80,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:vbox]).to eq("guest") end - it "should set parallels host if /usr/bin/prlctl exists" do + it "sets parallels host if /usr/bin/prlctl exists" do allow(plugin).to receive(:prlctl_exists?).and_return("/usr/bin/prlctl") plugin.run expect(plugin[:virtualization][:system]).to eq("parallels") @@ -88,7 +88,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:parallels]).to eq("host") end - it "should set parallels guest if /usr/sbin/ioreg exists and its output contains pci1ab8,4000" do + it "sets parallels guest if /usr/sbin/ioreg exists and its output contains pci1ab8,4000" do allow(plugin).to receive(:ioreg_exists?).and_return(true) ioreg = <<-IOREG | | +-o pci1ab8,4000@3 <class IOPCIDevice, id 0x1000001d1, registered, matched, active, busy 0 (40 ms), retain 9> @@ -122,7 +122,7 @@ describe Ohai::System, "Darwin virtualization platform" do expect(plugin[:virtualization][:systems][:parallels]).to eq("guest") end - it "should not set parallels guest if /usr/sbin/ioreg exists and its output not contain pci1ab8,4000" do + it "does not set parallels guest if /usr/sbin/ioreg exists and its output not contain pci1ab8,4000" do allow(plugin).to receive(:ioreg_exists?).and_return(true) ioreg = <<-IOREG | | +-o pci8086,2445@1F,4 <class IOPCIDevice, id 0x1000001d4, registered, matched, active, busy 0 (974 ms), retain 11> diff --git a/spec/unit/plugins/digital_ocean_spec.rb b/spec/unit/plugins/digital_ocean_spec.rb index 44354d68..280668c8 100644 --- a/spec/unit/plugins/digital_ocean_spec.rb +++ b/spec/unit/plugins/digital_ocean_spec.rb @@ -34,12 +34,12 @@ describe Ohai::System, "plugin digital_ocean" do } end - before(:each) do + before do allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false) end shared_examples_for "!digital_ocean" do - it "should NOT attempt to fetch the digital_ocean metadata" do + it "does not attempt to fetch the digital_ocean metadata" do expect(plugin).not_to receive(:http_client) expect(plugin[:digital_ocean]).to be_nil plugin.run @@ -47,7 +47,7 @@ describe Ohai::System, "plugin digital_ocean" do end shared_examples_for "digital_ocean" do - before(:each) do + before do @http_client = double("Net::HTTP client") allow(plugin).to receive(:http_client).and_return(@http_client) allow(IO).to receive(:select).and_return([[], [1], []]) @@ -61,7 +61,7 @@ describe Ohai::System, "plugin digital_ocean" do '{"droplet_id":2756924,"hostname":"sample-droplet","vendor_data":"#cloud-config\ndisable_root: false\nmanage_etc_hosts: true\n\n# The modules that run in the \'init\' stage\ncloud_init_modules:\n - migrator\n - ubuntu-init-switch\n - seed_random\n - bootcmd\n - write-files\n - growpart\n - resizefs\n - set_hostname\n - update_hostname\n - [ update_etc_hosts, once-per-instance ]\n - ca-certs\n - rsyslog\n - users-groups\n - ssh\n\n# The modules that run in the \'config\' stage\ncloud_config_modules:\n - disk_setup\n - mounts\n - ssh-import-id\n - locale\n - set-passwords\n - grub-dpkg\n - apt-pipelining\n - apt-configure\n - package-update-upgrade-install\n - landscape\n - timezone\n - puppet\n - chef\n - salt-minion\n - mcollective\n - disable-ec2-metadata\n - runcmd\n - byobu\n\n# The modules that run in the \'final\' stage\ncloud_final_modules:\n - rightscale_userdata\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n - ssh-authkey-fingerprints\n - keys-to-console\n - phone-home\n - final-message\n - power-state-change\n","public_keys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAkMD3PYKHaH0KbDiXrRE6KCBo/OKcFqhM+fmnnb0+LUh4RalJWX4edeJmnT5bxLeqmLV/Yggjlpfq73R+Dy7JB4pbBLuM959mSM9ohBCSnByAGoT2iUPev4aZFZZ/ahUzTCylNxXrhZV/bopD399CvYREt7Q+FlauBv0O8MMuMGR8aC69Z3jNL+r+fGWNq98JVHGFO/UgoNL15wGCaidMhzfRqkt1u+m1nY77SFM5qWJz2R0CEC4fMlOiCg8mWBklnryV4yDEPgiXp2I8Rli1Eu2GHwuY1YX9elMeQS7n3Pzq7l6aIQmSgvcEWx6TgMD2V7nQUWpfcud/8dpp/t7z9UyfzLmNwnULHNmUeEp52sejcH5lYzISnkkWa1LzlKSeIrhF3y45m9AyxIfjEqyh/mlKQtUaW3NVXXLPwrNitxHtMIZPU5b16BODn0wb8bqPxpDNpUYrQd/BS7mWDxNpICP2ObLPhd9LW9KIYRNTzryE+uKwxm9NkMlhRku2fu415fH0G0+7aURsHviNN9SO4zct3Pj6QE5rnbVHqxt3biplUTOScdWxSk2Nv3V2dGdt/lBfu6iRPAV9IAS31s7Po3qK1t2jpEPCJwstaCBOM80kmoi3zAgotiAW50X8CelaWsHNrq5jBBgeHUZWgn/c8BkcI61pUE9l34Q6gsiEMQ== tsmith84@gmail.com"],"region":"nyc3","interfaces":{"public":[{"ipv4":{"ip_address":"159.203.92.161","netmask":"255.255.240.0","gateway":"159.203.80.1"},"ipv6":{"ip_address":"2604:A880:0800:00A1:0000:0000:0201:0001","cidr":64,"gateway":"2604:A880:0800:00A1:0000:0000:0000:0001"},"anchor_ipv4":{"ip_address":"10.17.0.5","netmask":"255.255.0.0","gateway":"10.17.0.1"},"mac":"04:01:e5:14:03:01","type":"public"}]},"floating_ip":{"ipv4":{"active":false}},"dns":{"nameservers":["2001:4860:4860::8844","2001:4860:4860::8888","8.8.8.8"]}}' end - it "should fetch and properly parse json metadata" do + it "fetches and properly parse json metadata" do expect(@http_client).to receive(:get) .with("/metadata/v1.json") .and_return(double("Net::HTTP Response", body: body, code: "200")) @@ -72,7 +72,7 @@ describe Ohai::System, "plugin digital_ocean" do expect(plugin[:digital_ocean]["hostname"]).to eq("sample-droplet") end - it "should complete the run despite unavailable metadata" do + it "completes the run despite unavailable metadata" do expect(@http_client).to receive(:get) .with("/metadata/v1.json") .and_return(double("Net::HTTP Response", body: "", code: "404")) @@ -83,22 +83,24 @@ describe Ohai::System, "plugin digital_ocean" do end describe "without hint or dmi data" do - it_should_behave_like "!digital_ocean" + it_behaves_like "!digital_ocean" end describe "with digital_ocean hint file" do - it_should_behave_like "digital_ocean" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("digital_ocean").and_return(true) end + + it_behaves_like "digital_ocean" + end describe "with digital_ocean DMI data" do - it_should_behave_like "digital_ocean" - - before(:each) do + before do plugin[:dmi] = { bios: { all_records: [ { Vendor: "DigitalOcean" } ] } } end + + it_behaves_like "digital_ocean" + end end diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index fb5e6a5c..63826f82 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -104,7 +104,7 @@ describe Ohai::System, "plugin dmi" do let(:plugin) { get_plugin("dmi") } let(:stdout) { DMI_OUT } - before(:each) do + before do allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, stdout, "")) end diff --git a/spec/unit/plugins/docker_spec.rb b/spec/unit/plugins/docker_spec.rb index 90610426..4287ffc1 100644 --- a/spec/unit/plugins/docker_spec.rb +++ b/spec/unit/plugins/docker_spec.rb @@ -78,7 +78,7 @@ describe Ohai::System, "plugin docker" do let(:plugin) { get_plugin("docker") } context "if the machine does not have docker installed" do - it "should not create a docker attribute" do + it "does not create a docker attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new plugin.run @@ -87,7 +87,7 @@ describe Ohai::System, "plugin docker" do end context "if the machine has docker installed" do - it "should create a docker attribute with correct data" do + it "creates a docker attribute with correct data" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new plugin[:virtualization][:systems][:docker] = "host" diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb index bcbaeac3..823d5ed3 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -25,7 +25,7 @@ describe Ohai::System, "plugin ec2" do let(:plugin) { get_plugin("ec2") } - before(:each) do + before do allow(plugin).to receive(:hint?).with("ec2").and_return(false) allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false) allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false) @@ -41,7 +41,7 @@ describe Ohai::System, "plugin ec2" do end shared_examples_for "ec2" do - before(:each) do + before do @http_client = double("Net::HTTP client") allow(plugin).to receive(:http_client).and_return(@http_client) allow(IO).to receive(:select).and_return([[], [1], []]) @@ -335,62 +335,66 @@ describe Ohai::System, "plugin ec2" do end # shared examples for ec2 describe "with amazon dmi bios version data" do - it_behaves_like "ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true) allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n") end + + it_behaves_like "ec2" + end describe "with non-amazon dmi bios version data" do - it_behaves_like "!ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true) allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n") end + + it_behaves_like "!ec2" + end describe "with amazon dmi bios vendor data" do - it_behaves_like "ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true) allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n") end + + it_behaves_like "ec2" + end describe "with non-amazon dmi bios vendor data" do - it_behaves_like "!ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true) allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n") end + + it_behaves_like "!ec2" + end describe "with EC2 Xen UUID" do - it_behaves_like "ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true) allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n") end + + it_behaves_like "ec2" + end describe "with non-EC2 Xen UUID" do - it_behaves_like "!ec2" - - before(:each) do + before do allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true) allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n") end + + it_behaves_like "!ec2" + end describe "with EC2 Identifying Number", :windows_only do - it_behaves_like "ec2" - before do allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return( { "caption" => "Computer System Product", @@ -403,11 +407,12 @@ describe Ohai::System, "plugin ec2" do "version" => "4.2.amazon" } ) end + + it_behaves_like "ec2" + end describe "without EC2 Identifying Number", :windows_only do - it_behaves_like "!ec2" - before do allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return( { "caption" => "Computer System Product", @@ -420,22 +425,28 @@ describe Ohai::System, "plugin ec2" do "version" => "1.2.3" } ) end + + it_behaves_like "!ec2" + end describe "with ec2 hint file" do - it_behaves_like "ec2" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("ec2").and_return({}) end + + it_behaves_like "ec2" + end - describe "without any hints that it is an ec2 system" do - it_behaves_like "!ec2" - before(:each) do + describe "without any hints that it is an ec2 system" do + before do allow(plugin).to receive(:hint?).with("ec2").and_return(false) plugin[:dmi] = nil end + + it_behaves_like "!ec2" + end end diff --git a/spec/unit/plugins/elixir_spec.rb b/spec/unit/plugins/elixir_spec.rb index 35c46490..371f8b0f 100644 --- a/spec/unit/plugins/elixir_spec.rb +++ b/spec/unit/plugins/elixir_spec.rb @@ -19,11 +19,11 @@ require "spec_helper" describe Ohai::System, "plugin elixir" do let(:plugin) { get_plugin("elixir") } - before(:each) do + before do plugin[:languages] = Mash.new end - it "should shellout to elixir -v" do + it "shellouts to elixir -v" do expect(plugin).to receive(:shell_out).with("elixir -v").and_return(mock_shell_out(0, "Elixir 1.0.2", "")) plugin.run end diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb index 29515b0d..76309225 100644 --- a/spec/unit/plugins/erlang_spec.rb +++ b/spec/unit/plugins/erlang_spec.rb @@ -22,7 +22,7 @@ require "spec_helper" describe Ohai::System, "plugin erlang" do let(:plugin) { get_plugin("erlang") } - before(:each) do + before do plugin[:languages] = Mash.new erl_v_output = "Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 7.3\n" erl_systeminfo_output = "19.1,8.1,2.11" diff --git a/spec/unit/plugins/eucalyptus_spec.rb b/spec/unit/plugins/eucalyptus_spec.rb index a9d7ed52..c4a4d628 100644 --- a/spec/unit/plugins/eucalyptus_spec.rb +++ b/spec/unit/plugins/eucalyptus_spec.rb @@ -31,7 +31,7 @@ describe Ohai::System, "plugin eucalyptus" do end shared_examples_for "eucalyptus" do - before(:each) do + before do @http_client = double("Net::HTTP client") allow(plugin).to receive(:http_client).and_return(@http_client) @@ -69,37 +69,41 @@ describe Ohai::System, "plugin eucalyptus" do end describe "with eucalyptus mac and metadata address connected" do - it_behaves_like "eucalyptus" - - before(:each) do + before do allow(IO).to receive(:select).and_return([[], [1], []]) plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED" => { "family" => "lladdr" } } } } } end + + it_behaves_like "eucalyptus" + end describe "without eucalyptus mac and metadata address connected" do - it_behaves_like "!eucalyptus" - - before(:each) do + before do plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED" => { "family" => "lladdr" } } } } } end + + it_behaves_like "!eucalyptus" + end describe "with eucalyptus hint file" do - it_behaves_like "eucalyptus" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("eucalyptus").and_return(true) end + + it_behaves_like "eucalyptus" + end describe "without hint file" do - it_behaves_like "!eucalyptus" - - before(:each) do + before do plugin[:network] = { interfaces: {} } allow(plugin).to receive(:hint?).with("eucalyptus").and_return(false) end + + it_behaves_like "!eucalyptus" + end end diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb index 00ee8ee3..35a0643a 100644 --- a/spec/unit/plugins/fail_spec.rb +++ b/spec/unit/plugins/fail_spec.rb @@ -30,13 +30,13 @@ shared_examples "a v7 loading failure" do end - before(:each) do + before do fail_file = File.open("#{tmp}/plugins/fail.rb", "w+") fail_file.write(failstr) fail_file.close end - after(:each) do + after do File.delete("#{tmp}/plugins/fail.rb") end @@ -48,18 +48,18 @@ shared_examples "a v7 loading failure" do end - before(:each) do + before do @ohai = Ohai::System.new @loader = Ohai::Loader.new(@ohai) end - it "should not have attribute keys" do + it "does not have attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb") # @ohai.attributes.should_not have_key("fail") expect { @ohai.provides_map.find_providers_for(["fail"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound) end - it "should write to Ohai::Log" do + it "writes to Ohai::Log" do expect(@loader.logger).to receive(:warn).once @loader.load_plugin("#{tmp}/plugins/fail.rb") end @@ -74,13 +74,13 @@ shared_examples "a v7 loading success" do end - before(:each) do + before do fail_file = File.open("#{tmp}/plugins/fail.rb", "w+") fail_file.write(failstr) fail_file.close end - after(:each) do + after do File.delete("#{tmp}/plugins/fail.rb") end @@ -92,17 +92,17 @@ shared_examples "a v7 loading success" do end - before(:each) do + before do @ohai = Ohai::System.new @loader = Ohai::Loader.new(@ohai) end - it "should have attribute keys" do + it "has attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb") expect(@ohai.provides_map).to have_key("fail") end - it "should not write to Ohai::Log" do + it "does not write to Ohai::Log" do expect(@loader.logger).not_to receive(:warn) @loader.load_plugin("#{tmp}/plugins/fail.rb") end @@ -117,13 +117,13 @@ shared_examples "a v7 run failure" do end - before(:each) do + before do fail_file = File.open("#{tmp}/plugins/fail.rb", "w+") fail_file.write(failstr) fail_file.close end - after(:each) do + after do File.delete("#{tmp}/plugins/fail.rb") end @@ -135,17 +135,17 @@ shared_examples "a v7 run failure" do end - before(:each) do + before do @ohai = Ohai::System.new @loader = Ohai::Loader.new(@ohai) end - it "should not have new attribute keys" do + it "does not have new attribute keys" do @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run expect(@ohai.provides_map).not_to have_key("other") end - it "should write to Ohai::Log" do + it "writes to Ohai::Log" do expect(@loader.logger).to receive(:warn).once @loader.load_plugin("#{tmp}/plugins/fail.rb").new(@ohai).run end diff --git a/spec/unit/plugins/freebsd/cpu_spec.rb b/spec/unit/plugins/freebsd/cpu_spec.rb index b4354904..b6dd27f1 100644 --- a/spec/unit/plugins/freebsd/cpu_spec.rb +++ b/spec/unit/plugins/freebsd/cpu_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "FreeBSD cpu plugin on FreeBSD >=10.2" do - before(:each) do + before do @plugin = get_plugin("cpu") allow(@plugin).to receive(:collect_os).and_return(:freebsd) @double_file = double("/var/run/dmesg.boot") @@ -94,7 +94,7 @@ describe Ohai::System, "FreeBSD cpu plugin on FreeBSD >=10.2" do end describe Ohai::System, "FreeBSD cpu plugin on FreeBSD <=10.1" do - before(:each) do + before do @plugin = get_plugin("cpu") allow(@plugin).to receive(:collect_os).and_return(:freebsd) allow(@plugin).to receive(:shell_out).with("sysctl -n hw.ncpu").and_return(mock_shell_out(0, "2", "")) diff --git a/spec/unit/plugins/freebsd/hostname_spec.rb b/spec/unit/plugins/freebsd/hostname_spec.rb index e0cf0012..3f8a8db4 100644 --- a/spec/unit/plugins/freebsd/hostname_spec.rb +++ b/spec/unit/plugins/freebsd/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "FreeBSD hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:freebsd) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", "")) diff --git a/spec/unit/plugins/freebsd/kernel_spec.rb b/spec/unit/plugins/freebsd/kernel_spec.rb index 59c210c9..91291b39 100644 --- a/spec/unit/plugins/freebsd/kernel_spec.rb +++ b/spec/unit/plugins/freebsd/kernel_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "FreeBSD kernel plugin" do - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:freebsd) allow(@plugin).to receive(:init_kernel).and_return({ name: "freebsd" }) @@ -28,7 +28,7 @@ describe Ohai::System, "FreeBSD kernel plugin" do allow(@plugin).to receive(:shell_out).with( Ohai.abs_path( "/sbin/kldstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) end - it "should set the kernel_os to the kernel_name value" do + it "sets the kernel_os to the kernel_name value" do @plugin.run expect(@plugin[:kernel][:os]).to eq(@plugin[:kernel][:name]) end diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb index 42719fdc..58a0fdfa 100644 --- a/spec/unit/plugins/freebsd/platform_spec.rb +++ b/spec/unit/plugins/freebsd/platform_spec.rb @@ -19,19 +19,19 @@ require "spec_helper" describe Ohai::System, "FreeBSD plugin platform" do - before(:each) do + before do @plugin = get_plugin("freebsd/platform") allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "FreeBSD\n", "")) allow(@plugin).to receive(:shell_out).with("uname -r").and_return(mock_shell_out(0, "7.1\n", "")) allow(@plugin).to receive(:collect_os).and_return(:freebsd) end - it "should set platform to lowercased lsb[:id]" do + it "sets platform to lowercased lsb[:id]" do @plugin.run expect(@plugin[:platform]).to eq("freebsd") end - it "should set platform_version to lsb[:release]" do + it "sets platform_version to lsb[:release]" do @plugin.run expect(@plugin[:platform_version]).to eq("7.1") end diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb index 0e015e35..3af55d6b 100644 --- a/spec/unit/plugins/gce_spec.rb +++ b/spec/unit/plugins/gce_spec.rb @@ -34,7 +34,7 @@ describe Ohai::System, "plugin gce" do end shared_examples_for "gce" do - before(:each) do + before do @http_get = double("Net::HTTP client") allow(plugin).to receive(:http_get).and_return(double("Net::HTTP Response", body: '{"instance":{"hostname":"test-host"}}', code: "200")) allow(IO).to receive(:select).and_return([[], [1], []]) @@ -54,17 +54,16 @@ describe Ohai::System, "plugin gce" do end describe "with hint file and with metadata connection" do - it_behaves_like "gce" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("gce").and_return({}) end + + it_behaves_like "gce" + end describe "without hint file and without metadata connection" do - it_behaves_like "!gce" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("gce").and_return(false) # Raise Errno::ENOENT to simulate the scenario in which metadata server @@ -74,6 +73,9 @@ describe Ohai::System, "plugin gce" do allow(Socket).to receive(:new).and_return(t) allow(Socket).to receive(:pack_sockaddr_in).and_return(nil) end + + it_behaves_like "!gce" + end end diff --git a/spec/unit/plugins/go_spec.rb b/spec/unit/plugins/go_spec.rb index 1aeee50e..ce3a0e65 100644 --- a/spec/unit/plugins/go_spec.rb +++ b/spec/unit/plugins/go_spec.rb @@ -18,13 +18,13 @@ require "spec_helper" describe Ohai::System, "plugin go" do let(:plugin) { get_plugin("go") } - before(:each) do + before do plugin[:languages] = Mash.new stdout = "go version go1.6.1 darwin/amd64\n" allow(plugin).to receive(:shell_out).with("go version").and_return(mock_shell_out(0, stdout, "")) end - it "it shells out to get the go version" do + it "shells out to get the go version" do expect(plugin).to receive(:shell_out).with("go version") plugin.run end diff --git a/spec/unit/plugins/groovy_spec.rb b/spec/unit/plugins/groovy_spec.rb index 6178612d..24ded5f2 100644 --- a/spec/unit/plugins/groovy_spec.rb +++ b/spec/unit/plugins/groovy_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "plugin groovy" do let(:plugin) { get_plugin("groovy") } - before(:each) do + before do plugin[:languages] = Mash.new end diff --git a/spec/unit/plugins/haskell_spec.rb b/spec/unit/plugins/haskell_spec.rb index 54658513..f3623039 100644 --- a/spec/unit/plugins/haskell_spec.rb +++ b/spec/unit/plugins/haskell_spec.rb @@ -47,7 +47,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell/ghc is installed" do - before(:each) do + before do setup_plugin plugin.run end @@ -63,7 +63,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell/ghci is installed" do - before(:each) do + before do setup_plugin plugin.run end @@ -79,7 +79,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell/cabal is installed" do - before(:each) do + before do setup_plugin plugin.run end @@ -95,7 +95,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell/stack is installed" do - before(:each) do + before do setup_plugin plugin.run end @@ -111,7 +111,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell/stack prerelease is installed" do - before(:each) do + before do setup_plugin allow(plugin).to receive(:shell_out) .with("stack --version") @@ -130,7 +130,7 @@ describe Ohai::System, "plugin haskell" do context "if haskell is NOT installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .and_raise( Ohai::Exceptions::Exec ) plugin.run @@ -142,7 +142,7 @@ describe Ohai::System, "plugin haskell" do end context "if haskell/ghc is NOT installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .with("ghc --version") .and_raise( Ohai::Exceptions::Exec ) @@ -164,7 +164,7 @@ describe Ohai::System, "plugin haskell" do end context "if haskell/ghci is NOT installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .with("ghc --version") .and_return(mock_shell_out(0, ghc_out, "")) @@ -186,7 +186,7 @@ describe Ohai::System, "plugin haskell" do end context "if haskell/cabal is NOT installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .with("ghc --version") .and_return(mock_shell_out(0, ghc_out, "")) @@ -208,7 +208,7 @@ describe Ohai::System, "plugin haskell" do end context "if haskell/stack is NOT installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .with("ghc --version") .and_return(mock_shell_out(0, ghc_out, "")) diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb index dfc666d1..c7e00f8b 100644 --- a/spec/unit/plugins/hostname_spec.rb +++ b/spec/unit/plugins/hostname_spec.rb @@ -21,47 +21,48 @@ require "wmi-lite/wmi" require "socket" describe Ohai::System, "hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:default) allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.local", "")) end context "default behavior" - before(:each) do + before do allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell") end + it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - it "should use #resolve_fqdn to find the fqdn" do + it "uses #resolve_fqdn to find the fqdn" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.bethell") end - it "should set the domain to everything after the first dot of the fqdn" do + it "sets the domain to everything after the first dot of the fqdn" do @plugin.run expect(@plugin[:domain]).to eq("bethell") end - it "should set the [short] hostname to everything before the first dot of the fqdn" do + it "sets the [short] hostname to everything before the first dot of the fqdn" do @plugin.run expect(@plugin[:hostname]).to eq("katie") end context "when a system has a bare hostname without a FQDN" do - before(:each) do + before do allow(@plugin).to receive(:collect_os).and_return(:default) allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie", "")) end - it "should correctly set the [short] hostname" do + it "correctlies set the [short] hostname" do @plugin.run expect(@plugin[:hostname]).to eq("katie") end end context "hostname --fqdn when it returns empty string" do - before(:each) do + before do allow(@plugin).to receive(:collect_os).and_return(:linux) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return( mock_shell_out(0, "katie", "") @@ -71,14 +72,14 @@ describe Ohai::System, "hostname plugin" do ) end - it "should be called twice" do + it "is called twice" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.local") end end context "hostname --fqdn when it works" do - before(:each) do + before do allow(@plugin).to receive(:collect_os).and_return(:linux) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return( mock_shell_out(0, "katie", "") @@ -88,7 +89,7 @@ describe Ohai::System, "hostname plugin" do ) end - it "should be not be called twice" do + it "is not be called twice" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.local") end @@ -135,7 +136,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do ] end - before(:each) do + before do @plugin = get_plugin("hostname") allow(WmiLite::Wmi).to receive(:new).and_return(success) allow(success).to receive(:first_of).with("Win32_ComputerSystem").and_return(host) @@ -144,7 +145,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do end context "when hostname is not set for the machine" do - it "should return short machine name" do + it "returns short machine name" do allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(local_hostent) @plugin.run expect(@plugin[:fqdn]).to eq("local") @@ -152,7 +153,7 @@ describe Ohai::System, "hostname plugin for windows", :windows_only do end context "when hostname is set for the machine" do - it "should return the fqdn of the machine" do + it "returns the fqdn of the machine" do allow(Socket).to receive(:gethostbyaddr).with(anything).and_return(fqdn_hostent) @plugin.run expect(@plugin[:fqdn]).to eq("local.dx.internal.cloudapp.net") diff --git a/spec/unit/plugins/init_package_spec.rb b/spec/unit/plugins/init_package_spec.rb index fa72a0c9..a89aefdf 100644 --- a/spec/unit/plugins/init_package_spec.rb +++ b/spec/unit/plugins/init_package_spec.rb @@ -30,12 +30,12 @@ describe Ohai::System, "Init package" do let(:proc_1_file_path) { "/proc/1/comm" } let(:proc_1_file) { double(proc_1_file_path, gets: proc1_content) } - before(:each) do + before do allow(File).to receive(:exist?).with(proc_1_file_path).and_return(proc1_exists) allow(File).to receive(:open).with(proc_1_file_path).and_return(proc_1_file) end - it "should set init_package to init" do + it "sets init_package to init" do plugin.run expect(plugin[:init_package]).to eq("init") end @@ -43,7 +43,7 @@ describe Ohai::System, "Init package" do describe "when init_package is systemd" do let(:proc1_content) { "systemd\n" } - it "should set init_package to systemd" do + it "sets init_package to systemd" do plugin.run expect(plugin[:init_package]).to eq("systemd") end @@ -52,7 +52,7 @@ describe Ohai::System, "Init package" do describe "when /proc/1/comm doesn't exist" do let(:proc1_exists) { false } - it "should set init_package to init" do + it "sets init_package to init" do plugin.run expect(plugin[:init_package]).to eq("init") end diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb index 9927eaf2..1352bd1e 100644 --- a/spec/unit/plugins/java_spec.rb +++ b/spec/unit/plugins/java_spec.rb @@ -22,7 +22,7 @@ require "spec_helper" describe Ohai::System, "plugin java (Java5 Client VM)" do let(:plugin) { get_plugin("java") } - before(:each) do + before do plugin[:languages] = Mash.new end @@ -78,7 +78,7 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do shared_examples_for "when the Server JRE is installed" do - before(:each) do + before do stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)" allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) end @@ -123,7 +123,7 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do shared_examples_for "when the openjdk 1.8 is installed" do - before(:each) do + before do stderr = "openjdk version \"1.8.0_71\"\nOpenJDK Runtime Environment (build 1.8.0_71-b15)\nOpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)" allow(plugin).to receive(:shell_out).with("java -mx64m -version").and_return(mock_shell_out(0, "", stderr)) end @@ -174,9 +174,11 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do context "and the client JRE is installed" do include_examples "when the JRE is installed" end + context "and the server JRE is installed" do include_examples "when the Server JRE is installed" end + context "and the openjdk 1.8 is installed" do include_examples "when the openjdk 1.8 is installed" end @@ -201,9 +203,11 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do context "and the client JRE is installed" do include_examples "when the JRE is installed" end + context "and the server JRE is installed" do include_examples "when the Server JRE is installed" end + context "and the openjdk 1.8 is installed" do include_examples "when the openjdk 1.8 is installed" end diff --git a/spec/unit/plugins/joyent_spec.rb b/spec/unit/plugins/joyent_spec.rb index b4cd1c5f..516cd90e 100644 --- a/spec/unit/plugins/joyent_spec.rb +++ b/spec/unit/plugins/joyent_spec.rb @@ -20,7 +20,7 @@ describe Ohai::System, "plugin joyent" do let(:plugin) { get_plugin("joyent") } describe "without joyent" do - before(:each) do + before do allow(plugin).to receive(:is_smartos?).and_return(false) end @@ -31,7 +31,7 @@ describe Ohai::System, "plugin joyent" do end describe "with joyent" do - before(:each) do + before do allow(plugin).to receive(:is_smartos?).and_return(true) plugin[:virtualization] = Mash.new plugin[:virtualization][:guest_uuid] = "global" @@ -43,7 +43,7 @@ describe Ohai::System, "plugin joyent" do end describe "under global zone" do - before(:each) do + before do plugin.run end @@ -57,7 +57,7 @@ describe Ohai::System, "plugin joyent" do end describe "under smartmachine" do - before(:each) do + before do plugin[:virtualization][:guest_uuid] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" plugin[:virtualization][:guest_id] = "30" diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb index 5cd8e2c5..1ca765d1 100644 --- a/spec/unit/plugins/kernel_spec.rb +++ b/spec/unit/plugins/kernel_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "plugin kernel" do - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:default) # for debugging allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "Darwin\n", "")) diff --git a/spec/unit/plugins/linux/block_device_spec.rb b/spec/unit/plugins/linux/block_device_spec.rb index 888b3c4b..9a75c12f 100644 --- a/spec/unit/plugins/linux/block_device_spec.rb +++ b/spec/unit/plugins/linux/block_device_spec.rb @@ -41,7 +41,7 @@ describe Ohai::System, "Linux Block Device Plugin" do tmp_double end - before(:each) do + before do @plugin = get_plugin("linux/block_device") allow(@plugin).to receive(:collect_os).and_return(:linux) @@ -66,7 +66,7 @@ describe Ohai::System, "Linux Block Device Plugin" do end end - it "should collect all relevant data from disks" do + it "collects all relevant data from disks" do @plugin.run DISKS.each do |disk, checks| expect(@plugin[:block_device][disk.to_sym]).to include(checks) diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb index 9611ab33..38de38a3 100644 --- a/spec/unit/plugins/linux/cpu_spec.rb +++ b/spec/unit/plugins/linux/cpu_spec.rb @@ -86,12 +86,12 @@ describe Ohai::System, "General Linux cpu plugin" do tempfile end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(File).to receive(:open).with("/proc/cpuinfo").and_return(tempfile_handle) end - after(:each) do + after do tempfile.close tempfile.unlink @@ -154,15 +154,15 @@ describe Ohai::System, "General Linux cpu plugin" do EOF end - it_behaves_like "Common cpu info", 1, 1 - - before(:each) do + before do allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(0, lscpu, "")) end + it_behaves_like "Common cpu info", 1, 1 + it "gets total cores" do plugin.run - expect(plugin[:cpu][:cores]).to eql(1) + expect(plugin[:cpu][:cores]).to be(1) end it "doesn't have a cpu 1" do @@ -233,6 +233,7 @@ describe Ohai::System, "General Linux cpu plugin" do expect(plugin[:cpu]["0"]["flags"]).to eq(%w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}) end end + context "with a dual-core hyperthreaded /proc/cpuinfo" do let(:cpuinfo_contents) do <<~EOF @@ -363,7 +364,7 @@ end describe Ohai::System, "S390 linux cpu plugin" do let(:plugin) { get_plugin("cpu") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(1, "", "")) @@ -410,7 +411,7 @@ end describe Ohai::System, "arm64 linux cpu plugin" do let(:plugin) { get_plugin("cpu") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(1, "", "")) diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb index a60e5879..1e0ee544 100644 --- a/spec/unit/plugins/linux/filesystem_spec.rb +++ b/spec/unit/plugins/linux/filesystem_spec.rb @@ -20,7 +20,8 @@ require "spec_helper" describe Ohai::System, "Linux filesystem plugin" do let(:plugin) { get_plugin("filesystem") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, "", "")) @@ -56,7 +57,7 @@ describe Ohai::System, "Linux filesystem plugin" do end describe "when gathering filesystem usage data from df" do - before(:each) do + before do @stdout = <<~DF Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / @@ -83,55 +84,55 @@ describe Ohai::System, "Linux filesystem plugin" do allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) end - it "should run df -P and df -iP" do + it "runs df -P and df -iP" do expect(plugin).to receive(:shell_out).ordered.with("df -P").and_return(mock_shell_out(0, @stdout, "")) expect(plugin).to receive(:shell_out).ordered.with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) plugin.run end - it "should set kb_size to value from df -P" do + it "sets kb_size to value from df -P" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_size]).to eq("97605057") end - it "should set kb_used to value from df -P" do + it "sets kb_used to value from df -P" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_used]).to eq("53563253") end - it "should set kb_available to value from df -P" do + it "sets kb_available to value from df -P" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_available]).to eq("44041805") end - it "should set percent_used to value from df -P" do + it "sets percent_used to value from df -P" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:percent_used]).to eq("56%") end - it "should set mount to value from df -P" do + it "sets mount to value from df -P" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end - it "should set total_inodes to value from df -iP" do + it "sets total_inodes to value from df -iP" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:total_inodes]).to eq("124865") end - it "should set inodes_used to value from df -iP" do + it "sets inodes_used to value from df -iP" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_used]).to eq("380") end - it "should set inodes_available to value from df -iP" do + it "sets inodes_available to value from df -iP" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_available]).to eq("124485") end end describe "when gathering mounted filesystem data from mount" do - before(:each) do + before do @stdout = <<~MOUNT /dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) @@ -152,29 +153,29 @@ describe Ohai::System, "Linux filesystem plugin" do allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) end - it "should run mount" do + it "runs mount" do expect(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) plugin.run end - it "should set mount to value from mount" do + it "sets mount to value from mount" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end - it "should set fs_type to value from mount" do + it "sets fs_type to value from mount" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") end - it "should set mount_options to an array of values from mount" do + it "sets mount_options to an array of values from mount" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime}) end end describe "when gathering filesystem type data from blkid" do - before(:each) do + before do # blkid and lsblk output are coorelated with df/mount output, so the # most full test of them actually requires we have both @dfstdout = <<~DF @@ -219,11 +220,11 @@ describe Ohai::System, "Linux filesystem plugin" do allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, "")) end - it "should run blkid" do + it "runs blkid" do plugin.run end - it "should set kb_size to value from blkid" do + it "sets kb_size to value from blkid" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") @@ -232,7 +233,7 @@ describe Ohai::System, "Linux filesystem plugin" do end describe "when gathering filesystem type data from lsblk" do - before(:each) do + before do @dfstdout = <<~DF Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / @@ -280,18 +281,18 @@ describe Ohai::System, "Linux filesystem plugin" do .and_return(mock_shell_out(0, @stdout, "")) end - it "should run lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do + it "runs lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run end - it "should set kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do + it "sets kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") expect(plugin[:filesystem]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot") end - it "should ignore extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do + it "ignores extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/debian--7-root,"][:label]).to eq("root") end @@ -299,7 +300,7 @@ describe Ohai::System, "Linux filesystem plugin" do end describe "when gathering filesystem type data from both lsblk and blkid" do - before(:each) do + before do @dfstdout = <<~DF Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / @@ -362,21 +363,21 @@ describe Ohai::System, "Linux filesystem plugin" do allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, "")) end - it "should fill in missing FS data from lsblk using blkid" do + it "fills in missing FS data from lsblk using blkid" do plugin.run pairs = plugin[:filesystem]["by_pair"] expect(pairs["/dev/mapper/sys.vg-root.lv,/"]["fs_type"]).to eq("ext4") expect(pairs["/dev/mapper/sys.vg-usr.lv,/usr"]["fs_type"]).to eq("ext4") end - it "should fill in missing FS data from blkid using lsblk" do + it "fills in missing FS data from blkid using lsblk" do plugin.run pairs = plugin[:filesystem]["by_pair"] expect(pairs["/dev/sdb1,"]["uuid"]).to eq("bd1197e0-6997-1f3a-e27e-7801388308b5") expect(pairs["/dev/sdb2,"]["uuid"]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") end - it "should prefer lsblk data to blkid data when they conflict" do + it "prefers lsblk data to blkid data when they conflict" do plugin.run pairs = plugin[:filesystem]["by_pair"] expect(pairs["/dev/mapper/sys.vg-home.lv,/home"]["label"]).to eq("/home") @@ -385,7 +386,7 @@ describe Ohai::System, "Linux filesystem plugin" do end describe "when gathering data from /proc/mounts" do - before(:each) do + before do allow(File).to receive(:exist?).with("/proc/mounts").and_return(true) @double_file = double("/proc/mounts") @mounts = <<~MOUNTS @@ -417,24 +418,24 @@ describe Ohai::System, "Linux filesystem plugin" do allow(File).to receive(:open).with("/proc/mounts").and_return(@double_file) end - it "should set mount to value from /proc/mounts" do + it "sets mount to value from /proc/mounts" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end - it "should set fs_type to value from /proc/mounts" do + it "sets fs_type to value from /proc/mounts" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") end - it "should set mount_options to an array of values from /proc/mounts" do + it "sets mount_options to an array of values from /proc/mounts" do plugin.run expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime attr2 noquota}) end end describe "when gathering filesystem data with devices mounted more than once" do - before(:each) do + before do # there's a few different examples one can run into in this output: # 1. A device physically mounted in more than one place: /home and /home2 # 2. A bind-mounted directory, which shows up as the same device in a @@ -475,7 +476,7 @@ describe Ohai::System, "Linux filesystem plugin" do .and_return(mock_shell_out(0, @stdout, "")) end - it "should provide a devices view with all mountpoints" do + it "provides a devices view with all mountpoints" do plugin.run expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-root.lv"][:mounts]).to eq(["/", "/var/chroot"]) expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-home.lv"][:mounts]).to eq(["/home", "/home2"]) @@ -484,7 +485,7 @@ describe Ohai::System, "Linux filesystem plugin" do end describe "when gathering filesystem data with double-mounts" do - before(:each) do + before do @dfstdout = <<~DF Filesystem 1024-blocks Used Available Capacity Mounted on /dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / @@ -522,7 +523,7 @@ describe Ohai::System, "Linux filesystem plugin" do .and_return(mock_shell_out(0, @stdout, "")) end - it "should provide a mounts view with all devices" do + it "provides a mounts view with all devices" do plugin.run expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/sdb1", "/dev/sdc1"]) end diff --git a/spec/unit/plugins/linux/fips_spec.rb b/spec/unit/plugins/linux/fips_spec.rb index 62340a6f..cfc6c711 100644 --- a/spec/unit/plugins/linux/fips_spec.rb +++ b/spec/unit/plugins/linux/fips_spec.rb @@ -20,16 +20,16 @@ require "spec_helper" require "openssl" describe Ohai::System, "plugin fips" do - let(:enabled) { "0" } - let(:plugin) { get_plugin("linux/fips") } - let(:openssl_test_mode) { false } - subject do plugin.run plugin["fips"]["kernel"]["enabled"] end - before(:each) do + let(:enabled) { "0" } + let(:plugin) { get_plugin("linux/fips") } + let(:openssl_test_mode) { false } + + before do allow(plugin).to receive(:collect_os).and_return(:linux) end @@ -44,6 +44,7 @@ describe Ohai::System, "plugin fips" do context "with OpenSSL.fips_mode == false" do before { allow(OpenSSL).to receive(:fips_mode).and_return(false) } + it "does not set fips plugin" do expect(subject).to be(false) end @@ -51,6 +52,7 @@ describe Ohai::System, "plugin fips" do context "with OpenSSL.fips_mode == true" do before { allow(OpenSSL).to receive(:fips_mode).and_return(true) } + it "sets fips plugin" do expect(subject).to be(true) end diff --git a/spec/unit/plugins/linux/hostname_spec.rb b/spec/unit/plugins/linux/hostname_spec.rb index fcf4abec..0fe198ca 100644 --- a/spec/unit/plugins/linux/hostname_spec.rb +++ b/spec/unit/plugins/linux/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Linux hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:linux) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", "")) @@ -34,15 +34,15 @@ describe Ohai::System, "Linux hostname plugin" do it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") describe "when domain name is unset" do - before(:each) do + before do expect(@plugin).to receive(:shell_out).with("hostname --fqdn").and_raise("Ohai::Exception::Exec") end - it "should not raise an error" do + it "does not raise an error" do expect { @plugin.run }.not_to raise_error end - it "should not set fqdn" do + it "does not set fqdn" do @plugin.run expect(@plugin.fqdn).to eq(nil) end diff --git a/spec/unit/plugins/linux/hostnamectl_spec.rb b/spec/unit/plugins/linux/hostnamectl_spec.rb index 799bff82..5dd7e052 100644 --- a/spec/unit/plugins/linux/hostnamectl_spec.rb +++ b/spec/unit/plugins/linux/hostnamectl_spec.rb @@ -21,11 +21,11 @@ require "spec_helper" describe Ohai::System, "Linux hostnamectl plugin" do let(:plugin) { get_plugin("linux/hostnamectl") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) end - it "should populate hostnamectl if hostnamectl is available" do + it "populates hostnamectl if hostnamectl is available" do hostnamectl_out = <<-HOSTNAMECTL_OUT Static hostname: foo Icon name: computer-laptop @@ -52,7 +52,7 @@ describe Ohai::System, "Linux hostnamectl plugin" do }) end - it "should not populate hostnamectl if hostnamectl is not available" do + it "does not populate hostnamectl if hostnamectl is not available" do allow(plugin).to receive(:which).with("hostnamectl").and_return(false) expect(plugin[:hostnamectl]).to eq(nil) end diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb index 241adc05..79d2af9c 100644 --- a/spec/unit/plugins/linux/kernel_spec.rb +++ b/spec/unit/plugins/linux/kernel_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai::System, "Linux kernel plugin" do - before(:each) do + before do @env_lsmod = <<~ENV_LSMOD Module Size Used by dm_crypt 22321 0 diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb index eab7a1ab..4ce9a113 100644 --- a/spec/unit/plugins/linux/lsb_spec.rb +++ b/spec/unit/plugins/linux/lsb_spec.rb @@ -21,13 +21,13 @@ require "spec_helper" # We do not alter case for lsb attributes and consume them as provided describe Ohai::System, "Linux lsb plugin" do - before(:each) do + before do @plugin = get_plugin("linux/lsb") allow(@plugin).to receive(:collect_os).and_return(:linux) end describe "on systems with /etc/lsb-release" do - before(:each) do + before do @double_file = double("/etc/lsb-release") allow(@double_file).to receive(:each) .and_yield("DISTRIB_ID=Ubuntu") @@ -39,29 +39,29 @@ describe Ohai::System, "Linux lsb plugin" do allow(File).to receive(:exist?).with("/etc/lsb-release").and_return(true) end - it "should set lsb[:id]" do + it "sets lsb[:id]" do @plugin.run expect(@plugin[:lsb][:id]).to eq("Ubuntu") end - it "should set lsb[:release]" do + it "sets lsb[:release]" do @plugin.run expect(@plugin[:lsb][:release]).to eq("8.04") end - it "should set lsb[:codename]" do + it "sets lsb[:codename]" do @plugin.run expect(@plugin[:lsb][:codename]).to eq("hardy") end - it "should set lsb[:description]" do + it "sets lsb[:description]" do @plugin.run expect(@plugin[:lsb][:description]).to eq("Ubuntu 8.04") end end describe "on systems with /usr/bin/lsb_release" do - before(:each) do + before do allow(File).to receive(:exist?).with("/usr/bin/lsb_release").and_return(true) @stdin = double("STDIN", { close: true }) @@ -73,7 +73,7 @@ describe Ohai::System, "Linux lsb plugin" do end describe "on Centos 5.4 correctly" do - before(:each) do + before do @stdout = <<~LSB_RELEASE LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch Distributor ID: CentOS @@ -84,29 +84,29 @@ describe Ohai::System, "Linux lsb plugin" do allow(@plugin).to receive(:shell_out).with("lsb_release -a").and_return(mock_shell_out(0, @stdout, "")) end - it "should set lsb[:id]" do + it "sets lsb[:id]" do @plugin.run expect(@plugin[:lsb][:id]).to eq("CentOS") end - it "should set lsb[:release]" do + it "sets lsb[:release]" do @plugin.run expect(@plugin[:lsb][:release]).to eq("5.4") end - it "should set lsb[:codename]" do + it "sets lsb[:codename]" do @plugin.run expect(@plugin[:lsb][:codename]).to eq("Final") end - it "should set lsb[:description]" do + it "sets lsb[:description]" do @plugin.run expect(@plugin[:lsb][:description]).to eq("CentOS release 5.4 (Final)") end end describe "on Fedora 14 correctly" do - before(:each) do + before do @stdout = <<~LSB_RELEASE LSB Version: :core-4.0-ia32:core-4.0-noarch Distributor ID: Fedora @@ -117,29 +117,29 @@ describe Ohai::System, "Linux lsb plugin" do allow(@plugin).to receive(:shell_out).with("lsb_release -a").and_return(mock_shell_out(0, @stdout, "")) end - it "should set lsb[:id]" do + it "sets lsb[:id]" do @plugin.run expect(@plugin[:lsb][:id]).to eq("Fedora") end - it "should set lsb[:release]" do + it "sets lsb[:release]" do @plugin.run expect(@plugin[:lsb][:release]).to eq("14") end - it "should set lsb[:codename]" do + it "sets lsb[:codename]" do @plugin.run expect(@plugin[:lsb][:codename]).to eq("Laughlin") end - it "should set lsb[:description]" do + it "sets lsb[:description]" do @plugin.run expect(@plugin[:lsb][:description]).to eq("Fedora release 14 (Laughlin)") end end end - it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do + it "does not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do allow(File).to receive(:exist?).with("/etc/lsb-release").and_return(false) allow(File).to receive(:exist?).with("/usr/bin/lsb_release").and_return(false) expect(@plugin.attribute?(:lsb)).to be(false) diff --git a/spec/unit/plugins/linux/lspci_spec.rb b/spec/unit/plugins/linux/lspci_spec.rb index 93cf0205..6df3399e 100644 --- a/spec/unit/plugins/linux/lspci_spec.rb +++ b/spec/unit/plugins/linux/lspci_spec.rb @@ -20,7 +20,8 @@ require "spec_helper" describe Ohai::System, "Linux lspci plugin" do let(:plugin) { get_plugin("linux/lspci") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:linux) @stdout = <<~LSPCI Device: 00:1f.3 diff --git a/spec/unit/plugins/linux/machineid_spec.rb b/spec/unit/plugins/linux/machineid_spec.rb index b953f4d5..e751def0 100644 --- a/spec/unit/plugins/linux/machineid_spec.rb +++ b/spec/unit/plugins/linux/machineid_spec.rb @@ -21,11 +21,11 @@ require "spec_helper" describe Ohai::System, "Machine id plugin" do let(:plugin) { get_plugin("linux/machineid") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) end - it "should read /etc/machine-id if available" do + it "reads /etc/machine-id if available" do machine_id = "6f702523e2fc7499eb1dc68e5314dacf" allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(true) @@ -34,7 +34,7 @@ describe Ohai::System, "Machine id plugin" do expect(plugin[:machine_id]).to eq(machine_id) end - it "should read /var/lib/dbus/machine-id if available" do + it "reads /var/lib/dbus/machine-id if available" do machine_id = "6f702523e2fc7499eb1dc68e5314dacf" allow(::File).to receive(:exist?).with("/etc/machine-id").and_return(false) diff --git a/spec/unit/plugins/linux/mdadm_spec.rb b/spec/unit/plugins/linux/mdadm_spec.rb index a4564077..b7b67b83 100644 --- a/spec/unit/plugins/linux/mdadm_spec.rb +++ b/spec/unit/plugins/linux/mdadm_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Linux Mdadm Plugin" do - before(:each) do + before do @md0 = <<~MD /dev/md0: Version : 1.2 @@ -67,46 +67,46 @@ describe Ohai::System, "Linux Mdadm Plugin" do describe "gathering Mdadm information via /proc/mdstat and mdadm" do - it "should not raise an error" do + it "does not raise an error" do expect { @plugin.run }.not_to raise_error end - it "should detect raid level" do + it "detects raid level" do @plugin.run expect(@plugin[:mdadm][:md0][:level]).to eq(10) end - it "should detect raid state" do + it "detects raid state" do @plugin.run expect(@plugin[:mdadm][:md0][:state]).to eq("clean") end - it "should detect raid size" do + it "detects raid size" do @plugin.run expect(@plugin[:mdadm][:md0][:size]).to eq(2794.16) end - it "should detect raid metadata level" do + it "detects raid metadata level" do @plugin.run expect(@plugin[:mdadm][:md0][:version]).to eq(1.2) end device_counts = { raid: 6, total: 6, active: 6, working: 6, failed: 0, spare: 0 } device_counts.each_pair do |item, expected_value| - it "should detect device count of \"#{item}\"" do + it "detects device count of \"#{item}\"" do @plugin.run expect(@plugin[:mdadm][:md0][:device_counts][item]).to eq(expected_value) end end - it "should detect member devices" do + it "detects member devices" do @plugin.run expect(@plugin[:mdadm][:md0][:members].sort).to eq( %w{sdc sdd sde sdf sdg sdh} ) end - it "should detect member devices even if there are multi-digit numbers" do + it "detects member devices even if there are multi-digit numbers" do new_mdstat = double("/proc/mdstat2") allow(new_mdstat).to receive(:each) .and_yield("Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]") @@ -120,7 +120,7 @@ describe Ohai::System, "Linux Mdadm Plugin" do ) end - it "should detect member devices even if mdstat has extra entries" do + it "detects member devices even if mdstat has extra entries" do new_mdstat = double("/proc/mdstat2") allow(new_mdstat).to receive(:each) .and_yield("Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]") @@ -134,7 +134,7 @@ describe Ohai::System, "Linux Mdadm Plugin" do ) end - it "should accurately report inactive arrays" do + it "accuratelies report inactive arrays" do new_mdstat = double("/proc/mdstat_inactive") allow(new_mdstat).to receive(:each) .and_yield("Personalities :") @@ -145,7 +145,7 @@ describe Ohai::System, "Linux Mdadm Plugin" do expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{nvme2n1p3}) end - it "should report journal devices" do + it "reports journal devices" do new_mdstat = double("/proc/mdstat_journal") allow(new_mdstat).to receive(:each) .and_yield("Personalies : [raid6]") @@ -156,7 +156,7 @@ describe Ohai::System, "Linux Mdadm Plugin" do expect(@plugin[:mdadm][:md0][:journal]).to eq("nvme2n1p3") end - it "should report spare devices" do + it "reports spare devices" do new_mdstat = double("/proc/mdstat_spare") allow(new_mdstat).to receive(:each) .and_yield("Personalies : [raid6]") diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb index 23c95b9a..49ca6362 100644 --- a/spec/unit/plugins/linux/memory_spec.rb +++ b/spec/unit/plugins/linux/memory_spec.rb @@ -17,7 +17,7 @@ require "spec_helper" describe Ohai::System, "Linux memory plugin" do - before(:each) do + before do @plugin = get_plugin("linux/memory") allow(@plugin).to receive(:collect_os).and_return(:linux) @double_file = double("/proc/meminfo") @@ -64,192 +64,192 @@ describe Ohai::System, "Linux memory plugin" do allow(File).to receive(:open).with("/proc/meminfo").and_return(@double_file) end - it "should get total memory" do + it "gets total memory" do @plugin.run expect(@plugin[:memory][:total]).to eql("131932120kB") end - it "should get free memory" do + it "gets free memory" do @plugin.run expect(@plugin[:memory][:free]).to eql("2269032kB") end - it "should get available memory" do + it "gets available memory" do @plugin.run expect(@plugin[:memory][:available]).to eql("9208922kB") end - it "should get memory used for file buffers" do + it "gets memory used for file buffers" do @plugin.run expect(@plugin[:memory][:buffers]).to eql("646368kB") end - it "should get cache memory" do + it "gets cache memory" do @plugin.run expect(@plugin[:memory][:cached]).to eql("32346556kB") end - it "should get active memory" do + it "gets active memory" do @plugin.run expect(@plugin[:memory][:active]).to eql("98595796kB") end - it "should get inactive memory" do + it "gets inactive memory" do @plugin.run expect(@plugin[:memory][:inactive]).to eql("18477320kB") end - it "should get high_total memory" do + it "gets high_total memory" do @plugin.run expect(@plugin[:memory][:high_total]).to eql("0kB") end - it "should get high_free memory" do + it "gets high_free memory" do @plugin.run expect(@plugin[:memory][:high_free]).to eql("0kB") end - it "should get low_total memory" do + it "gets low_total memory" do @plugin.run expect(@plugin[:memory][:low_total]).to eql("131932120kB") end - it "should get low_free memory" do + it "gets low_free memory" do @plugin.run expect(@plugin[:memory][:low_free]).to eql("2269032kB") end - it "should get dirty memory" do + it "gets dirty memory" do @plugin.run expect(@plugin[:memory][:dirty]).to eql("3212kB") end - it "should get writeback memory" do + it "gets writeback memory" do @plugin.run expect(@plugin[:memory][:writeback]).to eql("0kB") end - it "should get anon_pages memory" do + it "gets anon_pages memory" do @plugin.run expect(@plugin[:memory][:anon_pages]).to eql("84082132kB") end - it "should get mapped memory" do + it "gets mapped memory" do @plugin.run expect(@plugin[:memory][:mapped]).to eql("3445224kB") end - it "should get slab memory" do + it "gets slab memory" do @plugin.run expect(@plugin[:memory][:slab]).to eql("9892096kB") end - it "should get slab_reclaimable memory" do + it "gets slab_reclaimable memory" do @plugin.run expect(@plugin[:memory][:slab_reclaimable]).to eql("362636kB") end - it "should get slab_reclaimable memory" do + it "gets slab_reclaimable memory" do @plugin.run expect(@plugin[:memory][:slab_unreclaim]).to eql("18860kB") end - it "should get page_tables memory" do + it "gets page_tables memory" do @plugin.run expect(@plugin[:memory][:page_tables]).to eql("1759332kB") end - it "should get nfs_unstable memory" do + it "gets nfs_unstable memory" do @plugin.run expect(@plugin[:memory][:nfs_unstable]).to eql("0kB") end - it "should get bounce memory" do + it "gets bounce memory" do @plugin.run expect(@plugin[:memory][:bounce]).to eql("0kB") end - it "should get commit_limit memory" do + it "gets commit_limit memory" do @plugin.run expect(@plugin[:memory][:commit_limit]).to eql("148709328kB") end - it "should get committed_as memory" do + it "gets committed_as memory" do @plugin.run expect(@plugin[:memory][:committed_as]).to eql("333717060kB") end - it "should get vmalloc_total memory" do + it "gets vmalloc_total memory" do @plugin.run expect(@plugin[:memory][:vmalloc_total]).to eql("34359738367kB") end - it "should get vmalloc_used memory" do + it "gets vmalloc_used memory" do @plugin.run expect(@plugin[:memory][:vmalloc_used]).to eql("276796kB") end - it "should get vmalloc_chunk memory" do + it "gets vmalloc_chunk memory" do @plugin.run expect(@plugin[:memory][:vmalloc_chunk]).to eql("34359461515kB") end - it "should get total swap" do + it "gets total swap" do @plugin.run expect(@plugin[:memory][:swap][:total]).to eql("16777208kB") end - it "should get cached swap" do + it "gets cached swap" do @plugin.run expect(@plugin[:memory][:swap][:cached]).to eql("312kB") end - it "should get free swap" do + it "gets free swap" do @plugin.run expect(@plugin[:memory][:swap][:free]).to eql("14127356kB") end - it "should get total hugepages" do + it "gets total hugepages" do @plugin.run expect(@plugin[:memory][:hugepages][:total]).to eql("11542") end - it "should get free hugepages" do + it "gets free hugepages" do @plugin.run expect(@plugin[:memory][:hugepages][:free]).to eql("11235") end - it "should get reserved hugepages" do + it "gets reserved hugepages" do @plugin.run expect(@plugin[:memory][:hugepages][:reserved]).to eql("11226") end - it "should get surplus hugepages" do + it "gets surplus hugepages" do @plugin.run expect(@plugin[:memory][:hugepages][:surplus]).to eql("0") end - it "should get hugepage size" do + it "gets hugepage size" do @plugin.run expect(@plugin[:memory][:hugepage_size]).to eql("2048kB") end - it "should get hugetlb memory" do + it "gets hugetlb memory" do @plugin.run expect(@plugin[:memory][:hugetlb]).to eql("0kB") end - it "should get directmap 4k memory" do + it "gets directmap 4k memory" do @plugin.run expect(@plugin[:memory][:directmap][:'4k']).to eql("3720736kB") end - it "should get directmap 2M memory" do + it "gets directmap 2M memory" do @plugin.run expect(@plugin[:memory][:directmap][:'2M']).to eql("12795904kB") end - it "should get directmap 1G memory" do + it "gets directmap 1G memory" do @plugin.run expect(@plugin[:memory][:directmap][:'1G']).to eql("0kB") end diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index 3d0cdec0..38877783 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -371,7 +371,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("ip addr").and_return(mock_shell_out(0, linux_ip_addr, "")) @@ -545,7 +545,7 @@ describe Ohai::System, "Linux Network Plugin" do %w{ifconfig iproute2}.each do |network_method| describe "gathering IP layer address info via #{network_method}" do - before(:each) do + before do allow(plugin).to receive(:which).with("ip").and_return( network_method == "iproute2" ? "/sbin/ip" : false ) allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" ) plugin.run @@ -688,7 +688,7 @@ describe Ohai::System, "Linux Network Plugin" do end describe "gathering interface counters via #{network_method}" do - before(:each) do + before do allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false) allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool") plugin.run @@ -727,7 +727,7 @@ describe Ohai::System, "Linux Network Plugin" do end describe "setting the node's default IP address attribute with #{network_method}" do - before(:each) do + before do allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false) allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool") plugin.run @@ -760,7 +760,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -790,7 +790,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -806,7 +806,7 @@ describe Ohai::System, "Linux Network Plugin" do end describe "for newer network features using iproute2 only" do - before(:each) do + before do allow(plugin).to receive(:which).with("ip").and_return("/sbin/ip") allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" ) allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(true) # ipv6 is enabled @@ -860,7 +860,7 @@ describe Ohai::System, "Linux Network Plugin" do end describe "when IPv6 is disabled" do - before :each do + before do allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(false) plugin.run end @@ -891,7 +891,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -929,7 +929,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -970,7 +970,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1013,7 +1013,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1114,7 +1114,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1135,7 +1135,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1160,7 +1160,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1185,7 +1185,8 @@ describe Ohai::System, "Linux Network Plugin" do default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024 EOM end - before(:each) do + + before do plugin.run end @@ -1219,7 +1220,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end @@ -1258,7 +1259,7 @@ describe Ohai::System, "Linux Network Plugin" do let(:linux_ip_route_inet6) { "" } let(:linux_ip_inet6_neighbor_show) { "" } - before(:each) do + before do allow(plugin).to receive(:is_openvz?).and_return true allow(plugin).to receive(:is_openvz_host?).and_return false plugin.run @@ -1303,7 +1304,7 @@ describe Ohai::System, "Linux Network Plugin" do EOM end - before(:each) do + before do plugin.run end diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 3255192c..8c81d5a6 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -23,6 +23,7 @@ describe Ohai::System, "Linux plugin platform" do describe "#read_os_release_info" do let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" } + it "returns nil if the file does not exist" do allow(File).to receive(:exist?).with("/etc/test-release").and_return(false) expect(plugin.read_os_release_info("/etc/test-release")).to be nil @@ -211,7 +212,7 @@ describe Ohai::System, "Linux plugin platform" do end describe "on system with /etc/os-release" do - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(::File).to receive(:exist?).with("/etc/os-release").and_return(true) end @@ -228,11 +229,11 @@ describe Ohai::System, "Linux plugin platform" do OS_DATA end - before(:each) do + before do expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) end - it "should set platform, platform_family, and platform_version from os-release" do + it "sets platform, platform_family, and platform_version from os-release" do plugin.run expect(plugin[:platform]).to eq("ubuntu") expect(plugin[:platform_family]).to eq("debian") @@ -250,11 +251,11 @@ describe Ohai::System, "Linux plugin platform" do OS_DATA end - before(:each) do + before do expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) end - it "should set platform_version using kernel version from uname" do + it "sets platform_version using kernel version from uname" do allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", "")) plugin.run expect(plugin[:platform]).to eq("arch") @@ -275,11 +276,11 @@ describe Ohai::System, "Linux plugin platform" do OS_DATA end - before(:each) do + before do expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) end - it "should set platform, platform_family, and platform_version from os-release" do + it "sets platform, platform_family, and platform_version from os-release" do plugin.run expect(plugin[:platform]).to eq("opensuseleap") expect(plugin[:platform_family]).to eq("suse") @@ -299,12 +300,12 @@ describe Ohai::System, "Linux plugin platform" do OS_DATA end - before(:each) do + before do expect(File).to receive(:read).with("/etc/os-release").and_return(os_data) expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)") end - it "should set platform, platform_family, and platform_version from os-release" do + it "sets platform, platform_family, and platform_version from os-release" do plugin.run expect(plugin[:platform]).to eq("centos") expect(plugin[:platform_family]).to eq("rhel") @@ -330,7 +331,7 @@ describe Ohai::System, "Linux plugin platform" do let(:have_cisco_release) { false } let(:have_f5_release) { false } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) plugin[:lsb] = Mash.new allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version) @@ -352,36 +353,36 @@ describe Ohai::System, "Linux plugin platform" do end describe "on lsb compliant distributions" do - before(:each) do + before do plugin[:lsb][:id] = "Ubuntu" plugin[:lsb][:release] = "18.04" end - it "should set platform to lowercased lsb[:id]" do + it "sets platform to lowercased lsb[:id]" do plugin.run expect(plugin[:platform]).to eq("ubuntu") end - it "should set platform_version to lsb[:release]" do + it "sets platform_version to lsb[:release]" do plugin.run expect(plugin[:platform_version]).to eq("18.04") end - it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do + it "sets platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do plugin[:lsb][:id] = "Ubuntu" plugin.run expect(plugin[:platform]).to eq("ubuntu") expect(plugin[:platform_family]).to eq("debian") end - it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do + it "sets platform to debian and platform_family to debian [:lsb][:id] contains Debian" do plugin[:lsb][:id] = "Debian" plugin.run expect(plugin[:platform]).to eq("debian") expect(plugin[:platform_family]).to eq("debian") end - it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do + it "sets platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do plugin[:lsb][:id] = "RedHatEnterpriseServer" plugin[:lsb][:release] = "7.5" plugin.run @@ -389,7 +390,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_family]).to eq("rhel") end - it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do + it "sets platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do plugin[:lsb][:id] = "AmazonAMI" plugin[:lsb][:release] = "2018.03" plugin.run @@ -397,14 +398,14 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_family]).to eq("amazon") end - it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do + it "sets platform to scientific when [:lsb][:id] contains ScientificSL" do plugin[:lsb][:id] = "ScientificSL" plugin[:lsb][:release] = "7.5" plugin.run expect(plugin[:platform]).to eq("scientific") end - it "should set platform to ibm_powerkvm and platform_family to rhel when [:lsb][:id] contains IBM_PowerKVM" do + it "sets platform to ibm_powerkvm and platform_family to rhel when [:lsb][:id] contains IBM_PowerKVM" do plugin[:lsb][:id] = "IBM_PowerKVM" plugin[:lsb][:release] = "2.1" plugin.run @@ -417,24 +418,24 @@ describe Ohai::System, "Linux plugin platform" do let(:have_debian_version) { true } - before(:each) do + before do plugin.lsb = nil end - it "should read the version from /etc/debian_version" do + it "reads the version from /etc/debian_version" do expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5") plugin.run expect(plugin[:platform_version]).to eq("9.5") end - it "should correctly strip any newlines" do + it "correctlies strip any newlines" do expect(File).to receive(:read).with("/etc/debian_version").and_return("9.5\n") plugin.run expect(plugin[:platform_version]).to eq("9.5") end # Ubuntu has /etc/debian_version as well - it "should detect Ubuntu as itself rather than debian" do + it "detects Ubuntu as itself rather than debian" do plugin[:lsb][:id] = "Ubuntu" plugin[:lsb][:release] = "18.04" plugin.run @@ -446,18 +447,18 @@ describe Ohai::System, "Linux plugin platform" do let(:have_slackware_version) { true } - before(:each) do + before do plugin.lsb = nil end - it "should set platform and platform_family to slackware" do + it "sets platform and platform_family to slackware" do expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0") plugin.run expect(plugin[:platform]).to eq("slackware") expect(plugin[:platform_family]).to eq("slackware") end - it "should set platform_version on slackware" do + it "sets platform_version on slackware" do expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0") plugin.run expect(plugin[:platform_version]).to eq("12.0.0") @@ -470,11 +471,11 @@ describe Ohai::System, "Linux plugin platform" do let(:have_redhat_release) { true } let(:have_eos_release) { true } - before(:each) do + before do plugin.lsb = nil end - it "should set platform to arista_eos" do + it "sets platform to arista_eos" do expect(File).to receive(:read).with("/etc/Eos-release").and_return("Arista Networks EOS 4.21.1.1F") plugin.run expect(plugin[:platform]).to eq("arista_eos") @@ -487,11 +488,11 @@ describe Ohai::System, "Linux plugin platform" do let(:have_f5_release) { true } - before(:each) do + before do plugin.lsb = nil end - it "should set platform to bigip" do + it "sets platform to bigip" do expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)") plugin.run expect(plugin[:platform]).to eq("bigip") @@ -504,18 +505,18 @@ describe Ohai::System, "Linux plugin platform" do let(:have_exherbo_release) { true } - before(:each) do + before do allow(plugin).to receive(:shell_out).with("/bin/uname -r").and_return(mock_shell_out(0, "3.18.2-2-ARCH\n", "")) plugin.lsb = nil end - it "should set platform and platform_family to exherbo" do + it "sets platform and platform_family to exherbo" do plugin.run expect(plugin[:platform]).to eq("exherbo") expect(plugin[:platform_family]).to eq("exherbo") end - it "should set platform_version to kernel release" do + it "sets platform_version to kernel release" do plugin.run expect(plugin[:platform_version]).to eq("3.18.2-2-ARCH") end @@ -524,7 +525,7 @@ describe Ohai::System, "Linux plugin platform" do describe "on redhat breeds" do describe "with lsb_release results" do - it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do + it "sets the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do plugin[:lsb][:id] = "RedHatEnterpriseServer" plugin[:lsb][:release] = "7.5" plugin.run @@ -533,7 +534,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_family]).to eq("rhel") end - it "should set the platform to centos and platform_family to rhel" do + it "sets the platform to centos and platform_family to rhel" do plugin[:lsb][:id] = "CentOS" plugin[:lsb][:release] = "7.5" plugin.run @@ -547,11 +548,11 @@ describe Ohai::System, "Linux plugin platform" do let(:have_redhat_release) { true } - before(:each) do + before do plugin.lsb = nil end - it "should read the platform as centos and version as 7.5" do + it "reads the platform as centos and version as 7.5" do expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS Linux release 7.5.1804 (Core)") plugin.run expect(plugin[:platform]).to eq("centos") @@ -564,7 +565,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform]).to eq("redhat") end - it "should read the platform as redhat without a space" do + it "reads the platform as redhat without a space" do expect(File).to receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3") plugin.run expect(plugin[:platform]).to eq("redhat") @@ -581,7 +582,7 @@ describe Ohai::System, "Linux plugin platform" do describe "with lsb_result" do - it "should read the platform as parallels and version as 6.0.5" do + it "reads the platform as parallels and version as 6.0.5" do plugin[:lsb][:id] = "CloudLinuxServer" plugin[:lsb][:release] = "6.5" allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)") @@ -595,11 +596,11 @@ describe Ohai::System, "Linux plugin platform" do describe "without lsb_results" do - before(:each) do + before do plugin.lsb = nil end - it "should read the platform as parallels and version as 6.0.5" do + it "reads the platform as parallels and version as 6.0.5" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("CloudLinux Server release 6.5 (Pavel Popovich)") expect(File).to receive(:read).with("/etc/parallels-release").and_return("Parallels Cloud Server 6.0.5 (20007)") plugin.run @@ -620,7 +621,7 @@ describe Ohai::System, "Linux plugin platform" do let(:have_enterprise_release) { true } - it "should read the platform as oracle and version as 5.7" do + it "reads the platform as oracle and version as 5.7" do plugin[:lsb][:id] = "EnterpriseEnterpriseServer" plugin[:lsb][:release] = "5.7" allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)") @@ -635,7 +636,7 @@ describe Ohai::System, "Linux plugin platform" do let(:have_oracle_release) { true } - it "should read the platform as oracle and version as 6.1" do + it "reads the platform as oracle and version as 6.1" do plugin[:lsb][:id] = "OracleServer" plugin[:lsb][:release] = "6.1" allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)") @@ -649,7 +650,7 @@ describe Ohai::System, "Linux plugin platform" do end context "without lsb_results" do - before(:each) do + before do plugin.lsb = nil end @@ -657,7 +658,7 @@ describe Ohai::System, "Linux plugin platform" do let(:have_enterprise_release) { true } - it "should read the platform as oracle and version as 5" do + it "reads the platform as oracle and version as 5" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)") expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)") plugin.run @@ -665,7 +666,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_version]).to eq("5") end - it "should read the platform as oracle and version as 5.1" do + it "reads the platform as oracle and version as 5.1" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)") expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)") plugin.run @@ -673,7 +674,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_version]).to eq("5.1") end - it "should read the platform as oracle and version as 5.7" do + it "reads the platform as oracle and version as 5.7" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)") expect(File).to receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)") plugin.run @@ -687,7 +688,7 @@ describe Ohai::System, "Linux plugin platform" do let(:have_oracle_release) { true } - it "should read the platform as oracle and version as 6.0" do + it "reads the platform as oracle and version as 6.0" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)") expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0") plugin.run @@ -695,7 +696,7 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_version]).to eq("6.0") end - it "should read the platform as oracle and version as 6.1" do + it "reads the platform as oracle and version as 6.1" do allow(File).to receive(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)") expect(File).to receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1") plugin.run @@ -712,11 +713,11 @@ describe Ohai::System, "Linux plugin platform" do let(:have_os_release) { false } describe "with lsb_release results" do - before(:each) do + before do plugin[:lsb][:id] = "SUSE LINUX" end - it "should read the platform as opensuse on openSUSE" do + it "reads the platform as opensuse on openSUSE" do plugin[:lsb][:release] = "12.1" expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n") plugin.run @@ -730,18 +731,18 @@ describe Ohai::System, "Linux plugin platform" do let(:have_suse_release) { true } describe "without lsb_release results" do - before(:each) do + before do plugin.lsb = nil end - it "should set platform and platform_family to suse and bogus verion to 10.0" do + it "sets platform and platform_family to suse and bogus verion to 10.0" do expect(File).to receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0") plugin.run expect(plugin[:platform]).to eq("suse") expect(plugin[:platform_family]).to eq("suse") end - it "should read the version as 11.2" do + it "reads the version as 11.2" do expect(File).to receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n") plugin.run expect(plugin[:platform]).to eq("suse") @@ -765,14 +766,14 @@ describe Ohai::System, "Linux plugin platform" do expect(plugin[:platform_family]).to eq("suse") end - it "should read the platform as opensuse on openSUSE" do + it "reads the platform as opensuse on openSUSE" do expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.2 (x86_64)\nVERSION = 12.2\nCODENAME = Mantis\n") plugin.run expect(plugin[:platform]).to eq("opensuse") expect(plugin[:platform_family]).to eq("suse") end - it "should read the platform as opensuseleap on openSUSE Leap" do + it "reads the platform as opensuseleap on openSUSE Leap" do expect(File).to receive(:read).with("/etc/SuSE-release").and_return("openSUSE 42.1 (x86_64)\nVERSION = 42.1\nCODENAME = Malachite\n") plugin.run expect(plugin[:platform]).to eq("opensuseleap") @@ -794,10 +795,12 @@ describe Ohai::System, "Linux plugin platform" do PRETTY_NAME="Clear Linux OS" CLEARLINUX_RELEASE end + before do expect(File).to receive(:read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content) end - it "should set platform to clearlinux and platform_family to clearlinux" do + + it "sets platform to clearlinux and platform_family to clearlinux" do plugin.lsb = nil plugin.run expect(plugin[:platform]).to eq("clearlinux") diff --git a/spec/unit/plugins/linux/sessions_spec.rb b/spec/unit/plugins/linux/sessions_spec.rb index 7b7a613a..a0170a65 100644 --- a/spec/unit/plugins/linux/sessions_spec.rb +++ b/spec/unit/plugins/linux/sessions_spec.rb @@ -21,11 +21,11 @@ require "spec_helper" describe Ohai::System, "Linux sessions plugin" do let(:plugin) { get_plugin("linux/sessions") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) end - it "should populate sessions if loginctl is found" do + it "populates sessions if loginctl is found" do loginctl_out = <<-LOGINCTL_OUT c1 118 Debian-gdm seat0 318 0 root @@ -90,7 +90,7 @@ describe Ohai::System, "Linux sessions plugin" do }) end - it "should not populate sessions if loginctl is not found" do + it "does not populate sessions if loginctl is not found" do allow(plugin).to receive(:which).with("loginctl").and_return(false) plugin.run expect(plugin[:sessions]).to be(nil) diff --git a/spec/unit/plugins/linux/systemd_paths_spec.rb b/spec/unit/plugins/linux/systemd_paths_spec.rb index 91f55e59..04bf4ade 100644 --- a/spec/unit/plugins/linux/systemd_paths_spec.rb +++ b/spec/unit/plugins/linux/systemd_paths_spec.rb @@ -21,11 +21,11 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") describe Ohai::System, "Linux systemd paths plugin" do let(:plugin) { get_plugin("linux/systemd_paths") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) end - it "should populate systemd_paths if systemd-path is found" do + it "populates systemd_paths if systemd-path is found" do systemd_path_out = <<~SYSTEMD_PATH_OUT temporary: /tmp temporary-large: /var/tmp @@ -114,7 +114,7 @@ describe Ohai::System, "Linux systemd paths plugin" do }) end - it "should not populate systemd paths if systemd-path is not found" do + it "does not populate systemd paths if systemd-path is not found" do allow(plugin).to receive(:which).with("systemd-path").and_return(false) plugin.run expect(plugin[:systemd_paths]).to be(nil) diff --git a/spec/unit/plugins/linux/uptime_spec.rb b/spec/unit/plugins/linux/uptime_spec.rb index a70042b3..91132ae5 100644 --- a/spec/unit/plugins/linux/uptime_spec.rb +++ b/spec/unit/plugins/linux/uptime_spec.rb @@ -19,29 +19,29 @@ require "spec_helper" describe Ohai::System, "Linux plugin uptime" do - before(:each) do + before do @plugin = get_plugin("uptime") allow(@plugin).to receive(:collect_os).and_return(:linux) @double_file = double("/proc/uptime", { gets: "18423 989" }) allow(File).to receive(:open).with("/proc/uptime").and_return(@double_file) end - it "should set uptime_seconds to uptime" do + it "sets uptime_seconds to uptime" do @plugin.run expect(@plugin[:uptime_seconds]).to eq(18423) end - it "should set uptime to a human readable date" do + it "sets uptime to a human readable date" do @plugin.run expect(@plugin[:uptime]).to eq("5 hours 07 minutes 03 seconds") end - it "should set idletime_seconds to uptime" do + it "sets idletime_seconds to uptime" do @plugin.run expect(@plugin[:idletime_seconds]).to eq(989) end - it "should set idletime to a human readable date" do + it "sets idletime to a human readable date" do @plugin.run expect(@plugin[:idletime]).to eq("16 minutes 29 seconds") end diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 07668d5e..a851b88d 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "Linux virtualization platform" do let(:plugin) { get_plugin("linux/virtualization") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) # default to all requested Files not existing @@ -396,7 +396,7 @@ describe Ohai::System, "Linux virtualization platform" do end context "/proc/self/cgroup only has / mounts" do - before(:each) do + before do self_cgroup = <<~CGROUP 8:blkio:/ 7:net_cls:/ @@ -539,7 +539,7 @@ describe Ohai::System, "Linux virtualization platform" do # Relevant at least starting docker 1.6.2, kernel 4.0.5 & systemd 224-1. # Doi not exactly know which software/version really matters here. - it "should set docker guest if /proc/self/cgroup exists and there are /system.slice/docker-<hexadecimal> mounts (systemd managed cgroup)" do + it "sets docker guest if /proc/self/cgroup exists and there are /system.slice/docker-<hexadecimal> mounts (systemd managed cgroup)" do self_cgroup = <<~CGROUP 8:devices:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope 7:cpuset:/system.slice/docker-47341c91be8d491cb3b8a475ad5b4aef6e79bf728cbb351c384e4a6c410f172f.scope @@ -577,7 +577,7 @@ describe Ohai::System, "Linux virtualization platform" do end context "/proc/self/cgroup only has / mounts" do - before(:each) do + before do self_cgroup = <<~CGROUP 8:blkio:/ 7:net_cls:/ diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index e2726e9c..9d98109b 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -24,7 +24,7 @@ describe Ohai::System, "plugin lua" do let(:plugin) { get_plugin("lua") } - before(:each) do + before do plugin[:languages] = Mash.new @message = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @message)) diff --git a/spec/unit/plugins/mono_spec.rb b/spec/unit/plugins/mono_spec.rb index 3cccd41d..87cab1a9 100644 --- a/spec/unit/plugins/mono_spec.rb +++ b/spec/unit/plugins/mono_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "plugin mono" do let(:plugin) { get_plugin("mono") } - before(:each) do + before do plugin[:languages] = Mash.new @stdout = <<~OUT Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016) diff --git a/spec/unit/plugins/netbsd/hostname_spec.rb b/spec/unit/plugins/netbsd/hostname_spec.rb index 7d71fd35..713fddbe 100644 --- a/spec/unit/plugins/netbsd/hostname_spec.rb +++ b/spec/unit/plugins/netbsd/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "NetBSD hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:netbsd) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie\n", "")) @@ -31,12 +31,12 @@ describe Ohai::System, "NetBSD hostname plugin" do it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - it "should use #resolve_fqdn to find the fqdn" do + it "uses #resolve_fqdn to find the fqdn" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.bethell") end - it "should set the domain to everything after the first dot of the fqdn" do + it "sets the domain to everything after the first dot of the fqdn" do @plugin.run expect(@plugin[:domain]).to eq("bethell") end diff --git a/spec/unit/plugins/netbsd/kernel_spec.rb b/spec/unit/plugins/netbsd/kernel_spec.rb index 5e74b68c..d6029d6d 100644 --- a/spec/unit/plugins/netbsd/kernel_spec.rb +++ b/spec/unit/plugins/netbsd/kernel_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "NetBSD kernel plugin" do - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:netbsd) allow(@plugin).to receive(:init_kernel).and_return({}) @@ -28,7 +28,7 @@ describe Ohai::System, "NetBSD kernel plugin" do allow(@plugin).to receive(:shell_out).with((Ohai.abs_path( "/usr/bin/modstat" )).to_s).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) end - it "should set the kernel_os to the kernel_name value" do + it "sets the kernel_os to the kernel_name value" do @plugin.run expect(@plugin[:kernel][:os]).to eq(@plugin[:kernel][:name]) end diff --git a/spec/unit/plugins/netbsd/platform_spec.rb b/spec/unit/plugins/netbsd/platform_spec.rb index b5190a02..77524287 100644 --- a/spec/unit/plugins/netbsd/platform_spec.rb +++ b/spec/unit/plugins/netbsd/platform_spec.rb @@ -19,19 +19,19 @@ require "spec_helper" describe Ohai::System, "NetBSD plugin platform" do - before(:each) do + before do @plugin = get_plugin("netbsd/platform") allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "NetBSD\n", "")) allow(@plugin).to receive(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", "")) allow(@plugin).to receive(:collect_os).and_return(:netbsd) end - it "should set platform to lowercased lsb[:id]" do + it "sets platform to lowercased lsb[:id]" do @plugin.run expect(@plugin[:platform]).to eq("netbsd") end - it "should set platform_version to lsb[:release]" do + it "sets platform_version to lsb[:release]" do @plugin.run expect(@plugin[:platform_version]).to eq("4.5") end diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb index da4290c3..9ab12a90 100644 --- a/spec/unit/plugins/network_spec.rb +++ b/spec/unit/plugins/network_spec.rb @@ -329,7 +329,7 @@ describe Ohai::System, "Network Plugin" do } describe "on linux" do - before(:each) do + before do @plugin = get_plugin("network") @plugin["network"] = basic_data["linux"]["network"] end @@ -490,7 +490,7 @@ describe Ohai::System, "Network Plugin" do expect(@plugin["ip6address"]).to be_nil end - it "should warn about it" do + it "warns about it" do expect(@plugin.logger).to receive(:warn).with(/unable to detect ipaddress/).once expect(@plugin.logger).to receive(:trace).with(/unable to detect macaddress/).twice # for each family expect(@plugin.logger).to receive(:trace).with(/unable to detect ip6address/).once @@ -853,7 +853,7 @@ describe Ohai::System, "Network Plugin" do # specs using network plugin data for each mocked OS (freebsd,linux,windows) basic_data.keys.sort.each do |os| describe "the #{os}::network has already set some of the {ip,mac,ip6}address attributes" do - before(:each) do + before do @plugin["network"] = basic_data[os]["network"] end diff --git a/spec/unit/plugins/nodejs_spec.rb b/spec/unit/plugins/nodejs_spec.rb index 9b365b03..34768c74 100644 --- a/spec/unit/plugins/nodejs_spec.rb +++ b/spec/unit/plugins/nodejs_spec.rb @@ -24,7 +24,7 @@ describe Ohai::System, "plugin nodejs" do let(:plugin) { get_plugin("nodejs") } - before(:each) do + before do plugin[:languages] = Mash.new @stdout = "v0.8.11\n" allow(plugin).to receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) diff --git a/spec/unit/plugins/ohai_spec.rb b/spec/unit/plugins/ohai_spec.rb index efe41741..e95d1ac1 100644 --- a/spec/unit/plugins/ohai_spec.rb +++ b/spec/unit/plugins/ohai_spec.rb @@ -21,11 +21,11 @@ require "spec_helper" describe Ohai::System, "plugin ohai" do - before(:each) do + before do @plugin = get_plugin("ohai") end - it "should set [:chef_packages][:ohai][:version] to the current version" do + it "sets [:chef_packages][:ohai][:version] to the current version" do @plugin.run expect(@plugin[:chef_packages][:ohai][:version]).to eq(Ohai::VERSION) end diff --git a/spec/unit/plugins/ohai_time_spec.rb b/spec/unit/plugins/ohai_time_spec.rb index 1fea37cd..ea5f2d66 100644 --- a/spec/unit/plugins/ohai_time_spec.rb +++ b/spec/unit/plugins/ohai_time_spec.rb @@ -19,23 +19,23 @@ require "spec_helper" describe Ohai::System, "plugin ohai_time" do - before(:each) do + before do @plugin = get_plugin("ohai_time") end - it "should get the current time" do + it "gets the current time" do expect(Time).to receive(:now) @plugin.run end - it "should turn the time into a floating point number" do + it "turns the time into a floating point number" do time = Time.now expect(time).to receive(:to_f) allow(Time).to receive(:now).and_return(time) @plugin.run end - it "should set ohai_time to the current time" do + it "sets ohai_time to the current time" do time = Time.now allow(Time).to receive(:now).and_return(time) @plugin.run diff --git a/spec/unit/plugins/openbsd/hostname_spec.rb b/spec/unit/plugins/openbsd/hostname_spec.rb index b6fbffc2..495e116a 100644 --- a/spec/unit/plugins/openbsd/hostname_spec.rb +++ b/spec/unit/plugins/openbsd/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "OpenBSD hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:openbsd) allow(@plugin).to receive(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie\n", "")) @@ -31,12 +31,12 @@ describe Ohai::System, "OpenBSD hostname plugin" do it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - it "should use #resolve_fqdn to find the fqdn" do + it "uses #resolve_fqdn to find the fqdn" do @plugin.run expect(@plugin[:fqdn]).to eq("katie.bethell") end - it "should set the domain to everything after the first dot of the fqdn" do + it "sets the domain to everything after the first dot of the fqdn" do @plugin.run expect(@plugin[:domain]).to eq("bethell") end diff --git a/spec/unit/plugins/openbsd/kernel_spec.rb b/spec/unit/plugins/openbsd/kernel_spec.rb index 47302c52..89252563 100644 --- a/spec/unit/plugins/openbsd/kernel_spec.rb +++ b/spec/unit/plugins/openbsd/kernel_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "OpenBSD kernel plugin" do - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:openbsd) allow(@plugin).to receive(:init_kernel).and_return({}) @@ -28,7 +28,7 @@ describe Ohai::System, "OpenBSD kernel plugin" do allow(@plugin).to receive(:shell_out).with( Ohai.abs_path( "/usr/bin/modstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) end - it "should set the kernel_os to the kernel_name value" do + it "sets the kernel_os to the kernel_name value" do @plugin.run expect(@plugin[:kernel][:os]).to eq(@plugin[:kernel][:name]) end diff --git a/spec/unit/plugins/openbsd/platform_spec.rb b/spec/unit/plugins/openbsd/platform_spec.rb index d4f5e0ab..9a626f1f 100644 --- a/spec/unit/plugins/openbsd/platform_spec.rb +++ b/spec/unit/plugins/openbsd/platform_spec.rb @@ -19,14 +19,14 @@ require "spec_helper" describe Ohai::System, "OpenBSD plugin platform" do - before(:each) do + before do @plugin = get_plugin("openbsd/platform") allow(@plugin).to receive(:shell_out).with("uname -s").and_return(mock_shell_out(0, "OpenBSD\n", "")) allow(@plugin).to receive(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", "")) allow(@plugin).to receive(:collect_os).and_return(:openbsd) end - it "should set platform_version to lsb[:release]" do + it "sets platform_version to lsb[:release]" do @plugin.run expect(@plugin[:platform_version]).to eq("4.5") end diff --git a/spec/unit/plugins/openstack_spec.rb b/spec/unit/plugins/openstack_spec.rb index f8c0dafd..cff3980e 100644 --- a/spec/unit/plugins/openstack_spec.rb +++ b/spec/unit/plugins/openstack_spec.rb @@ -23,7 +23,7 @@ describe Ohai::System, "plugin openstack" do let(:plugin) { get_plugin("openstack") } let(:default_timeout) { 2 } - before(:each) do + before do allow(plugin).to receive(:hint?).with("openstack").and_return(false) plugin[:virtualization] = { system: {} } end @@ -86,9 +86,11 @@ describe Ohai::System, "plugin openstack" do end context "when timout was set" do let(:override_timout) { 10 } + before do Ohai::Config.ohai[:openstack_metadata_timeout] = override_timout end + after do Ohai::Config.ohai[:openstack_metadata_timeout] = nil end diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb index 23e4457e..69882b64 100644 --- a/spec/unit/plugins/os_spec.rb +++ b/spec/unit/plugins/os_spec.rb @@ -24,7 +24,7 @@ require "spec_helper" ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG["host_os"] describe Ohai::System, "plugin os" do - before(:each) do + before do @plugin = get_plugin("os") @plugin[:kernel] = Mash.new @plugin[:kernel][:release] = "kings of leon" @@ -34,28 +34,28 @@ describe Ohai::System, "plugin os" do ::RbConfig::CONFIG["host_os"] = ORIGINAL_CONFIG_HOST_OS end - it "should set os_version to kernel_release" do + it "sets os_version to kernel_release" do @plugin.run expect(@plugin[:os_version]).to eq(@plugin[:kernel][:release]) end describe "on linux" do - before(:each) do + before do ::RbConfig::CONFIG["host_os"] = "linux" end - it "should set the os to linux" do + it "sets the os to linux" do @plugin.run expect(@plugin[:os]).to eq("linux") end end describe "on darwin" do - before(:each) do + before do ::RbConfig::CONFIG["host_os"] = "darwin10.0" end - it "should set the os to darwin" do + it "sets the os to darwin" do @plugin.run expect(@plugin[:os]).to eq("darwin") end @@ -73,30 +73,30 @@ describe Ohai::System, "plugin os" do end describe "on AIX" do - before(:each) do + before do @plugin = get_plugin("os") allow(@plugin).to receive(:collect_os).and_return(:aix) allow(@plugin).to receive(:shell_out).with("oslevel -s").and_return(mock_shell_out(0, "7200-00-01-1543\n", nil)) @plugin.run end - it "should set the top-level os attribute" do - expect(@plugin[:os]).to eql(:aix) + it "sets the top-level os attribute" do + expect(@plugin[:os]).to be(:aix) end - it "should set the top-level os_level attribute" do + it "sets the top-level os_level attribute" do expect(@plugin[:os_version]).to eql("7200-00-01-1543") end end describe "on FreeBSD" do - before(:each) do + before do @plugin = get_plugin("os") allow(@plugin).to receive(:shell_out).with("sysctl -n kern.osreldate").and_return(mock_shell_out(0, "902001\n", "")) allow(@plugin).to receive(:collect_os).and_return(:freebsd) end - it "should set os_version to __FreeBSD_version" do + it "sets os_version to __FreeBSD_version" do @plugin.run expect(@plugin[:os_version]).to eq("902001") end diff --git a/spec/unit/plugins/packages_spec.rb b/spec/unit/plugins/packages_spec.rb index 6fc583d2..ee62b4d3 100644 --- a/spec/unit/plugins/packages_spec.rb +++ b/spec/unit/plugins/packages_spec.rb @@ -33,7 +33,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "dpkg-query.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out) .with("dpkg-query -W -f='#{format}'") @@ -72,7 +72,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "rpmquery.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("rpm -qa --qf '#{format}'").and_return(mock_shell_out(0, stdout, "")) plugin.run @@ -133,7 +133,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "pacman.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("LANG=C pacman -Qi").and_return(mock_shell_out(0, stdout, "")) plugin.run @@ -209,7 +209,7 @@ describe Ohai::System, "plugin packages" do end end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:windows) allow(win_reg_double).to receive(:open).with(win_reg_keys[0]).and_return(win_reg_output[0]) allow(win_reg_double).to receive(:open).with(win_reg_keys[1]).and_return(win_reg_output[1]) @@ -222,6 +222,7 @@ describe Ohai::System, "plugin packages" do allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', i386_reg_type).and_yield(win_reg_double) allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', i386_reg_type).and_yield(win_reg_double) end + it_behaves_like "windows_package_plugin" end @@ -231,6 +232,7 @@ describe Ohai::System, "plugin packages" do allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', x86_64_reg_type).and_yield(win_reg_double) allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', x86_64_reg_type).and_yield(win_reg_double) end + it_behaves_like "windows_package_plugin" end @@ -240,6 +242,7 @@ describe Ohai::System, "plugin packages" do allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Microsoft\Windows\CurrentVersion\Uninstall', Win32::Registry::KEY_READ).and_yield(win_reg_double) allow(Win32::Registry::HKEY_LOCAL_MACHINE).to receive(:open).with('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall', Win32::Registry::KEY_READ).and_yield(win_reg_double) end + it_behaves_like "windows_package_plugin" end end @@ -251,7 +254,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "lslpp.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:aix) allow(plugin).to receive(:shell_out).with("lslpp -L -q -c").and_return(mock_shell_out(0, stdout, "")) plugin.run @@ -280,7 +283,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "pkg-query.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:freebsd) allow(plugin).to receive(:shell_out).with('pkg query -a "%n %v"').and_return(mock_shell_out(0, stdout, "")) plugin.run @@ -309,7 +312,7 @@ describe Ohai::System, "plugin packages" do File.read(File.join(SPEC_PLUGIN_PATH, "pkginfo.output")) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:solaris2) allow(plugin).to receive(:shell_out).with("pkg list -H").and_return(mock_shell_out(0, pkglist_output, "")) allow(plugin).to receive(:shell_out).with("pkginfo -l").and_return(mock_shell_out(0, pkginfo_output, "")) diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb index 85932686..12400b42 100644 --- a/spec/unit/plugins/passwd_spec.rb +++ b/spec/unit/plugins/passwd_spec.rb @@ -17,14 +17,14 @@ require "spec_helper" describe Ohai::System, "plugin etc", :unix_only do - before(:each) do + before do @plugin = get_plugin("passwd") end PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos) GroupEntry = Struct.new(:name, :gid, :mem) - it "should include a list of all users" do + it "includes a list of all users" do expect(Etc).to receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, "/root", "/bin/zsh", "BOFH")) .and_yield(PasswdEntry.new("www", 800, 800, "/var/www", "/bin/false", "Serving the web since 1970")) @plugin.run @@ -32,21 +32,21 @@ describe Ohai::System, "plugin etc", :unix_only do expect(@plugin[:etc][:passwd]["www"]).to eq(Mash.new(shell: "/bin/false", gecos: "Serving the web since 1970", gid: 800, uid: 800, dir: "/var/www")) end - it "should ignore duplicate users" do + it "ignores duplicate users" do expect(Etc).to receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, "/root", "/bin/zsh", "BOFH")) .and_yield(PasswdEntry.new("root", 1, 1, "/", "/bin/false", "I do not belong")) @plugin.run expect(@plugin[:etc][:passwd]["root"]).to eq(Mash.new(shell: "/bin/zsh", gecos: "BOFH", gid: 1, uid: 1, dir: "/root")) end - it "should set the current user" do + it "sets the current user" do expect(Process).to receive(:euid).and_return("31337") expect(Etc).to receive(:getpwuid).and_return(PasswdEntry.new("chef", 31337, 31337, "/home/chef", "/bin/ksh", "Julia Child")) @plugin.run expect(@plugin[:current_user]).to eq("chef") end - it "should set the available groups" do + it "sets the available groups" do expect(Etc).to receive(:group).and_yield(GroupEntry.new("admin", 100, %w{root chef})).and_yield(GroupEntry.new("www", 800, %w{www deploy})) @plugin.run expect(@plugin[:etc][:group]["admin"]).to eq(Mash.new(gid: 100, members: %w{root chef})) diff --git a/spec/unit/plugins/perl_spec.rb b/spec/unit/plugins/perl_spec.rb index aecf5b17..5c55906e 100644 --- a/spec/unit/plugins/perl_spec.rb +++ b/spec/unit/plugins/perl_spec.rb @@ -22,7 +22,7 @@ require "spec_helper" describe Ohai::System, "plugin perl" do let(:plugin) { get_plugin("perl") } - before(:each) do + before do plugin[:languages] = Mash.new @stdout = "version='5.8.8';#{$/}archname='darwin-thread-multi-2level';" allow(plugin).to receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) diff --git a/spec/unit/plugins/php_spec.rb b/spec/unit/plugins/php_spec.rb index 647b608f..7ec373da 100644 --- a/spec/unit/plugins/php_spec.rb +++ b/spec/unit/plugins/php_spec.rb @@ -23,7 +23,7 @@ require "spec_helper" describe Ohai::System, "plugin php" do let(:plugin) { get_plugin("php") } - before(:each) do + before do plugin[:languages] = Mash.new @stdout = <<~OUT PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52) diff --git a/spec/unit/plugins/platform_spec.rb b/spec/unit/plugins/platform_spec.rb index 6245bd88..6c30a1bf 100644 --- a/spec/unit/plugins/platform_spec.rb +++ b/spec/unit/plugins/platform_spec.rb @@ -19,45 +19,45 @@ require "spec_helper" describe Ohai::System, "plugin platform" do - before(:each) do + before do @plugin = get_plugin("platform") allow(@plugin).to receive(:collect_os).and_return(:default) @plugin[:os] = "monkey" @plugin[:os_version] = "poop" end - it "should set the platform and platform family to the os if it was not set earlier" do + it "sets the platform and platform family to the os if it was not set earlier" do @plugin.run expect(@plugin[:platform]).to eql("monkey") expect(@plugin[:platform_family]).to eql("monkey") end - it "should not set the platform to the os if it was set earlier" do + it "does not set the platform to the os if it was set earlier" do @plugin[:platform] = "lars" @plugin.run expect(@plugin[:platform]).to eql("lars") end - it "should set the platform_family to the platform if platform was set earlier but not platform_family" do + it "sets the platform_family to the platform if platform was set earlier but not platform_family" do @plugin[:platform] = "lars" @plugin[:platform_family] = "jack" @plugin.run expect(@plugin[:platform_family]).to eql("jack") end - it "should not set the platform_family if the platform_family was set earlier." do + it "does not set the platform_family if the platform_family was set earlier." do @plugin[:platform] = "lars" @plugin.run expect(@plugin[:platform]).to eql("lars") expect(@plugin[:platform_family]).to eql("lars") end - it "should set the platform_version to the os_version if it was not set earlier" do + it "sets the platform_version to the os_version if it was not set earlier" do @plugin.run expect(@plugin[:os_version]).to eql("poop") end - it "should not set the platform to the os if it was set earlier" do + it "does not set the platform to the os if it was set earlier" do @plugin[:platform_version] = "ulrich" @plugin.run expect(@plugin[:platform_version]).to eql("ulrich") diff --git a/spec/unit/plugins/powershell_spec.rb b/spec/unit/plugins/powershell_spec.rb index 754c2745..e391efba 100644 --- a/spec/unit/plugins/powershell_spec.rb +++ b/spec/unit/plugins/powershell_spec.rb @@ -24,7 +24,7 @@ describe Ohai::System, "plugin powershell" do stub_const("::RbConfig::CONFIG", { "host_os" => "windows" }) end - before(:each) do + before do plugin[:languages] = Mash.new end diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb index 7343dc54..939ee269 100644 --- a/spec/unit/plugins/rackspace_spec.rb +++ b/spec/unit/plugins/rackspace_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "plugin rackspace" do let(:plugin) { get_plugin("rackspace") } - before(:each) do + before do allow(Resolv).to receive(:getname).and_return("1.2.3.4") plugin[:hostname] = "katie" @@ -184,15 +184,15 @@ describe Ohai::System, "plugin rackspace" do end describe "with rackspace hint file" do - it_behaves_like "rackspace" - - before(:each) do + before do allow(Resolv).to receive(:getname).and_raise(Resolv::ResolvError) allow(File).to receive(:exist?).with("/etc/resolv.conf").and_return(true) allow(File).to receive(:read).with("/etc/resolv.conf").and_return("") allow(plugin).to receive(:hint?).with("rackspace").and_return(true) end + it_behaves_like "rackspace" + describe "with no public interfaces (empty eth0)" do before do # unset public (eth0) addresses @@ -216,55 +216,60 @@ describe Ohai::System, "plugin rackspace" do end describe "without hint file" do - it_behaves_like "!rackspace" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("rackspace").and_return(false) end + + it_behaves_like "!rackspace" + end describe "with Rackspace windows manufacturer data" do + before do + allow(plugin).to receive(:hint?).with("rackspace").and_return(false) + allow(plugin).to receive(:has_rackspace_manufacturer?).and_return(true) + end + it "has rackspace attribute" do plugin.run expect(plugin[:rackspace]).not_to be_nil end - before(:each) do - allow(plugin).to receive(:hint?).with("rackspace").and_return(false) - allow(plugin).to receive(:has_rackspace_manufacturer?).and_return(true) - end end describe "xenstore provider returns rackspace" do - it_behaves_like "rackspace" - - before(:each) do + before do stdout = "Rackspace\n" allow(plugin).to receive(:hint?).with("rackspace").and_return(false) allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" )) end + + it_behaves_like "rackspace" + end describe "xenstore provider does not return rackspace" do - it_behaves_like "!rackspace" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("rackspace").and_return(false) stdout = "cumulonimbus\n" allow(plugin).to receive(:shell_out).with("xenstore-read vm-data/provider_data/provider").and_return(mock_shell_out(0, stdout, "" )) end - end - describe "xenstore provider does not exist" do it_behaves_like "!rackspace" - before(:each) do + end + + describe "xenstore provider does not exist" do + before do allow(plugin).to receive(:hint?).with("rackspace").and_return(false) allow(plugin) .to receive(:shell_out) .with("xenstore-read vm-data/provider_data/provider") .and_raise(Ohai::Exceptions::Exec) end + + it_behaves_like "!rackspace" + end describe "when private networks shell out fails" do diff --git a/spec/unit/plugins/root_group_spec.rb b/spec/unit/plugins/root_group_spec.rb index 77eff706..910c6ca2 100644 --- a/spec/unit/plugins/root_group_spec.rb +++ b/spec/unit/plugins/root_group_spec.rb @@ -19,12 +19,12 @@ require "spec_helper" describe Ohai::System, "root_group" do - before(:each) do + before do @plugin = get_plugin("root_group") end describe "unix platform", :unix_only do - before(:each) do + before do # this is deeply intertwingled. unfortunately, the law of demeter # apparently didn't apply to this api. we're just trying to fake # Etc.getgrgid(Etc.getpwnam('root').gid).name @@ -36,30 +36,33 @@ describe Ohai::System, "root_group" do end describe "with wheel group" do - before(:each) do + before do allow(@grgid).to receive(:name).and_return("wheel") end - it "should have a root_group of wheel" do + + it "has a root_group of wheel" do @plugin.run expect(@plugin[:root_group]).to eq("wheel") end end describe "with root group" do - before(:each) do + before do allow(@grgid).to receive(:name).and_return("root") end - it "should have a root_group of root" do + + it "has a root_group of root" do @plugin.run expect(@plugin[:root_group]).to eq("root") end end describe "platform aix with system group" do - before(:each) do + before do allow(@grgid).to receive(:name).and_return("system") end - it "should have a root_group of system" do + + it "has a root_group of system" do @plugin.run expect(@plugin[:root_group]).to eq("system") end @@ -70,11 +73,12 @@ describe Ohai::System, "root_group" do let(:wmi) { double("wmi", { query: "" }) } - before(:each) do + before do allow(WmiLite::Wmi).to receive(:new).and_return(wmi) allow(@plugin).to receive(:collect_os).and_return(:windows) end - it "should return the group Administrators" do + + it "returns the group Administrators" do expect(wmi) .to receive(:query) .with("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True") diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb index e402c5dd..b634f124 100644 --- a/spec/unit/plugins/ruby_spec.rb +++ b/spec/unit/plugins/ruby_spec.rb @@ -30,7 +30,7 @@ describe Ohai::System, "plugin ruby" do @ruby_ohai_data_pristine = @plugin[:languages][:ruby] end - before(:each) do + before do @ruby_ohai_data = @ruby_ohai_data_pristine.dup end @@ -52,7 +52,7 @@ describe Ohai::System, "plugin ruby" do end.find { |bin| ::File.exist? bin }, ruby_bin: ruby_bin, }.each do |attribute, value| - it "should have #{attribute} set to #{value.inspect}" do + it "has #{attribute} set to #{value.inspect}" do expect(@ruby_ohai_data[attribute]).to eql(value) end end diff --git a/spec/unit/plugins/rust_spec.rb b/spec/unit/plugins/rust_spec.rb index 4a642732..542423b9 100644 --- a/spec/unit/plugins/rust_spec.rb +++ b/spec/unit/plugins/rust_spec.rb @@ -25,17 +25,17 @@ describe Ohai::System, "plugin rust" do plugin end - it "should get the rust version" do + it "gets the rust version" do expect(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(0, stdout, "")) plugin.run end - it "should set languages[:rust][:version]" do + it "sets languages[:rust][:version]" do plugin.run expect(plugin.languages[:rust][:version]).to eql("1.0.0-nightly") end - it "should not set the languages[:rust] if rust command fails" do + it "does not set the languages[:rust] if rust command fails" do allow(plugin).to receive(:shell_out).with("rustc --version").and_return(mock_shell_out(1, stdout, "")) plugin.run expect(plugin.languages).not_to have_key(:rust) diff --git a/spec/unit/plugins/scala_spec.rb b/spec/unit/plugins/scala_spec.rb index 9c7170bb..66b51ee2 100644 --- a/spec/unit/plugins/scala_spec.rb +++ b/spec/unit/plugins/scala_spec.rb @@ -34,7 +34,7 @@ describe Ohai::System, "plugin scala" do end context "if scala is installed" do - before(:each) do + before do setup_plugin plugin.run end @@ -45,7 +45,7 @@ describe Ohai::System, "plugin scala" do end context "if scala is not installed" do - before(:each) do + before do allow(plugin).to receive(:shell_out) .and_raise( Ohai::Exceptions::Exec ) plugin.run diff --git a/spec/unit/plugins/scaleway_spec.rb b/spec/unit/plugins/scaleway_spec.rb index 3cd6f3b1..713a8312 100644 --- a/spec/unit/plugins/scaleway_spec.rb +++ b/spec/unit/plugins/scaleway_spec.rb @@ -20,13 +20,13 @@ require "spec_helper" describe Ohai::System, "plugin scaleway" do let(:plugin) { get_plugin("scaleway") } - before(:each) do + before do allow(plugin).to receive(:hint?).with("scaleway").and_return(false) allow(File).to receive(:read).with("/proc/cmdline").and_return(false) end shared_examples_for "!scaleway" do - it "should NOT attempt to fetch the scaleway metadata" do + it "does not attempt to fetch the scaleway metadata" do expect(plugin).not_to receive(:http_client) expect(plugin[:scaleway]).to be_nil plugin.run @@ -34,7 +34,7 @@ describe Ohai::System, "plugin scaleway" do end shared_examples_for "scaleway" do - before(:each) do + before do @http_client = double("Net::HTTP client") allow(plugin).to receive(:http_client).and_return(@http_client) allow(IO).to receive(:select).and_return([[], [1], []]) @@ -48,7 +48,7 @@ describe Ohai::System, "plugin scaleway" do '{"tags": [], "state_detail": "booted", "public_ip": {"dynamic": false, "id": "7564c721-a128-444e-9c95-0754a7616482", "address": "5.1.9.3"}, "ssh_public_keys": [{"key": "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEA5qK2s41yyrNpaXXiQtb/1ADaVHVZZp9rYEtG6Dz7trOPtxkxNsaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/j2C+NAzo6TZCLTbJjBf89ieazqVqhY/dMNLDJINY2Ss2ytgyiJm9bp5bYcZz441czijBlmY/qmI0cFCVOJoDq6X9Lmn/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee+hmLFaTE3FeMr1hmeZT2ChH6ruHi8m6m18SfW0fl2fS8zG4yB+WE2IawdsoZmtgtY/Re3CpvhYP9S/JxpUedl+zzzzzzzzzzzzzzzzz5+YONBAt/PWMelXThfMukbwykto6IXmsX2qflBPsRVrWe0D7vt48loVScHDv5D05ZwqWY9rizFqCx3Y8xCLr6649ieonnnjHEsSOBREU507eXVJL6njHard+s+vuTC4bNH5LiP2INQS+9MaT37/l8WzIAL3U+hvcj95HS8KfATX+7XWa54bGJgeOnPle8ojwp1ssl7ddh2yFJozgk2CkUEyE4f1lmEX2YFJGoEoaW0QC2j0nNYiLs37yHG0h84AOgjoIAJo1rxpBAGGJOgFTkgnSdHjtDZsC9WjJYeu/QpxQ7Lf2Z+FCKoypfnZz/F10/z6nxnkZ3IKKM=", "fingerprint": "4096 4c:71:db:64:cd:24:da:4a:fa:5f:9e:70:af:ea:40:6e (no comment) (RSA)"}], "private_ip": "10.8.23.7", "timezone": "UTC", "id": "77fab916-e7ff-44c6-a025-ae08837b4c4f", "extra_networks": [], "name": "sample-hostname", "hostname": "sample-hostname", "bootscript": {"kernel": "http://169.254.42.24/kernel/x86_64-4.9.20-std-1/vmlinuz-4.9.20-std-1", "title": "x86_64 4.9.20 std #1 (longterm/latest)", "default": false, "dtb": "", "public": false, "initrd": "http://169.254.42.24/initrd/initrd-Linux-x86_64-v3.12.7.gz", "bootcmdargs": "LINUX_COMMON scaleway boot=local", "architecture": "x86_64", "organization": "11111110-1112-4112-8112-111111111116", "id": "855f21ba-e7f9-421d-91b0-976a6ad59910"}, "location": {"platform_id": "21", "hypervisor_id": "518", "node_id": "4", "cluster_id": "82", "zone_id": "par1"}, "volumes": {"0": {"name": "x86_64-debian-stretch-2017-06-29_10:17", "modification_date": "2018-01-26T10:22:28.268074+00:00", "export_uri": "device://dev/vda", "volume_type": "l_ssd", "creation_date": "2018-01-26T10:22:28.268074+00:00", "organization": "90f39224-d0a2-4771-a2f0-1036a9402b97", "server": {"id": "77fab916-e7ff-44c6-a024-ae08837b4c4f", "name": "sample-hostname"}, "id": "3be53d4d-93d7-4430-a513-61cb4410624b", "size": 50000000000}}, "ipv6": null, "organization": "89f39224-d0a2-4771-a2f0-1036a9402b97", "commercial_type": "VC1S"}' end - it "should fetch and properly parse json metadata" do + it "fetches and properly parse json metadata" do expect(@http_client).to receive(:get) .with("/conf?format=json") .and_return(double("Net::HTTP Response", body: body, code: "200")) @@ -59,7 +59,7 @@ describe Ohai::System, "plugin scaleway" do expect(plugin[:scaleway]["hostname"]).to eq("sample-hostname") end - it "should complete the run despite unavailable metadata" do + it "completes the run despite unavailable metadata" do expect(@http_client).to receive(:get) .with("/conf?format=json") .and_return(double("Net::HTTP Response", body: "", code: "404")) @@ -70,22 +70,24 @@ describe Ohai::System, "plugin scaleway" do end describe "without hint or cmdline" do - it_should_behave_like "!scaleway" + it_behaves_like "!scaleway" end describe "with scaleway hint file" do - it_should_behave_like "scaleway" - - before(:each) do + before do allow(plugin).to receive(:hint?).with("scaleway").and_return(true) end + + it_behaves_like "scaleway" + end describe "with scaleway cmdline" do - it_should_behave_like "scaleway" - - before(:each) do + before do allow(File).to receive(:read).with("/proc/cmdline").and_return("initrd=initrd showopts console=ttyS0,115200 nousb vga=0 root=/dev/vda scaleway boot=local") end + + it_behaves_like "scaleway" + end end diff --git a/spec/unit/plugins/scsi_spec.rb b/spec/unit/plugins/scsi_spec.rb index a746fd74..ba258ec1 100644 --- a/spec/unit/plugins/scsi_spec.rb +++ b/spec/unit/plugins/scsi_spec.rb @@ -20,7 +20,8 @@ require "spec_helper" describe Ohai::System, "lsscsi plugin" do let(:plugin) { get_plugin("scsi") } - before(:each) do + + before do allow(plugin).to receive(:collect_os).and_return(:linux) @stdout = <<~LSSCSI [5:0:0:0] disk ATA Hitachi HUA72205 A3EA /dev/sda diff --git a/spec/unit/plugins/shard_spec.rb b/spec/unit/plugins/shard_spec.rb index 8e1657f3..c2352ff5 100644 --- a/spec/unit/plugins/shard_spec.rb +++ b/spec/unit/plugins/shard_spec.rb @@ -20,6 +20,11 @@ require "digest/md5" require "spec_helper" describe Ohai::System, "shard plugin" do + subject do + plugin.run + plugin[:shard_seed] + end + let(:plugin) { get_plugin("shard") } let(:fqdn) { "somehost004.someregion.somecompany.com" } let(:uuid) { "48555CF4-5BB1-21D9-BC4C-E8B73DDE5801" } @@ -29,12 +34,7 @@ describe Ohai::System, "shard plugin" do let(:fips) { false } let(:os) { "linux" } - subject do - plugin.run - plugin[:shard_seed] - end - - before(:each) do + before do plugin["machinename"] = machinename plugin["machine_id"] = machine_id plugin["fqdn"] = fqdn @@ -45,11 +45,11 @@ describe Ohai::System, "shard plugin" do allow(plugin).to receive(:collect_os).and_return(os) end - it "should provide a shard with a default-safe set of sources" do + it "provides a shard with a default-safe set of sources" do expect(subject).to eq(27767217) end - it "should provide a shard with a configured source" do + it "provides a shard with a configured source" do Ohai.config[:plugin][:shard_seed][:sources] = [:fqdn] expect(subject).to eq(203669792) end @@ -59,26 +59,28 @@ describe Ohai::System, "shard plugin" do expect { subject }.to raise_error(RuntimeError) end - it "should provide a shard with a configured algorithm" do + it "provides a shard with a configured algorithm" do Ohai.config[:plugin][:shard_seed][:digest_algorithm] = "sha256" - expect(Digest::MD5).to_not receive(:new) + expect(Digest::MD5).not_to receive(:new) expect(subject).to eq(117055036) end context "with Darwin OS" do let(:os) { "darwin" } + before do plugin.data.delete("fips") # FIPS is undefined on Macs, make sure this still work plugin["hardware"] = { "serial_number" => serial, "platform_UUID" => uuid } end - it "should provide a shard with a default-safe set of sources" do + it "provides a shard with a default-safe set of sources" do expect(subject).to eq(27767217) end end context "with Windows OS" do let(:os) { "windows" } + before do wmi = double("WmiLite::Wmi") allow(WmiLite::Wmi).to receive(:new).and_return(wmi) @@ -88,11 +90,11 @@ describe Ohai::System, "shard plugin" do plugin.data.delete("dmi") # To make sure we aren't using the wrong data. end - it "should provide a shard with a default-safe set of sources" do + it "provides a shard with a default-safe set of sources" do expect(subject).to eq(27767217) end - it "should allow os_serial source" do + it "allows os_serial source" do Ohai.config[:plugin][:shard_seed][:sources] = %i{machinename os_serial uuid} # Different from above. expect(subject).to eq(178738102) @@ -102,7 +104,7 @@ describe Ohai::System, "shard plugin" do context "with a weird OS" do let(:os) { "aix" } - it "should provide a shard with a default-safe set of sources" do + it "provides a shard with a default-safe set of sources" do # Note: this is different than the other defaults. expect(subject).to eq(253499154) end @@ -111,8 +113,8 @@ describe Ohai::System, "shard plugin" do context "with FIPS mode enabled" do let(:fips) { true } - it "should use SHA2" do - expect(Digest::MD5).to_not receive(:hexdigest) + it "uses SHA2" do + expect(Digest::MD5).not_to receive(:hexdigest) expect(subject).to eq(117055036) end end diff --git a/spec/unit/plugins/solaris2/cpu_spec.rb b/spec/unit/plugins/solaris2/cpu_spec.rb index 604cbee5..92f1acda 100644 --- a/spec/unit/plugins/solaris2/cpu_spec.rb +++ b/spec/unit/plugins/solaris2/cpu_spec.rb @@ -17,13 +17,13 @@ require "spec_helper" describe Ohai::System, "Solaris2.X cpu plugin" do - before(:each) do + before do @plugin = get_plugin("cpu") allow(@plugin).to receive(:collect_os).and_return("solaris2") end describe "on x86 processors" do - before(:each) do + before do kstatinfo_output = <<~END cpu_info:0:cpu_info0:brand Crazy(r) Argon(r) CPU Y5570 @ 1.93GHz cpu_info:0:cpu_info0:cache_id 1 @@ -446,28 +446,28 @@ describe Ohai::System, "Solaris2.X cpu plugin" do @plugin.run end - it "should get the total virtual processor count" do + it "gets the total virtual processor count" do expect(@plugin["cpu"]["total"]).to eql(16) end - it "should get the total processor count" do + it "gets the total processor count" do expect(@plugin["cpu"]["real"]).to eql(2) end - it "should get the number of threads per core" do + it "gets the number of threads per core" do expect(@plugin["cpu"]["corethreads"]).to eql(2) end - it "should get the total number of online cores" do + it "gets the total number of online cores" do expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(8) end - it "should get the total number of offline cores" do + it "gets the total number of offline cores" do expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(8) end describe "per-cpu information" do - it "should include processor vendor_ids" do + it "includes processor vendor_ids" do # CPU Socket 0 expect(@plugin["cpu"]["15"]["vendor_id"]).to eql("GenuineIntel") expect(@plugin["cpu"]["13"]["vendor_id"]).to eql("GenuineIntel") @@ -488,7 +488,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["vendor_id"]).to eql("CrazyTown") end - it "should include processor families" do + it "includes processor families" do expect(@plugin["cpu"]["15"]["family"]).to eql("6") expect(@plugin["cpu"]["13"]["family"]).to eql("6") expect(@plugin["cpu"]["11"]["family"]).to eql("6") @@ -508,7 +508,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["family"]).to eql("12") end - it "should include processor models" do + it "includes processor models" do expect(@plugin["cpu"]["15"]["model"]).to eql("26") expect(@plugin["cpu"]["13"]["model"]).to eql("26") expect(@plugin["cpu"]["11"]["model"]).to eql("26") @@ -528,7 +528,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["model"]).to eql("93") end - it "should includ processor architecture" do + it "includs processor architecture" do expect(@plugin["cpu"]["15"]["arch"]).to eql("i386") expect(@plugin["cpu"]["13"]["arch"]).to eql("i386") expect(@plugin["cpu"]["11"]["arch"]).to eql("i386") @@ -548,7 +548,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["arch"]).to eql("i386") end - it "should include processor stepping" do + it "includes processor stepping" do expect(@plugin["cpu"]["15"]["stepping"]).to eql("5") expect(@plugin["cpu"]["13"]["stepping"]).to eql("5") expect(@plugin["cpu"]["11"]["stepping"]).to eql("5") @@ -569,7 +569,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do end - it "should include processor model names" do + it "includes processor model names" do expect(@plugin["cpu"]["15"]["model_name"]).to eql("Intel(r) Xeon(r) CPU X5570 @ 2.93GHz") expect(@plugin["cpu"]["13"]["model_name"]).to eql("Intel(r) Xeon(r) CPU X5570 @ 2.93GHz") expect(@plugin["cpu"]["11"]["model_name"]).to eql("Intel(r) Xeon(r) CPU X5570 @ 2.93GHz") @@ -588,7 +588,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["model_name"]).to eql("Crazy(r) Argon(r) CPU Y5570 @ 1.93GHz") end - it "should include processor speed in MHz" do + it "includes processor speed in MHz" do expect(@plugin["cpu"]["15"]["mhz"]).to eql("2926") expect(@plugin["cpu"]["13"]["mhz"]).to eql("2926") expect(@plugin["cpu"]["11"]["mhz"]).to eql("2926") @@ -607,7 +607,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["0"]["mhz"]).to eql("1933") end - it "should include processor state" do + it "includes processor state" do expect(@plugin["cpu"]["15"]["state"]).to eql("on-line") expect(@plugin["cpu"]["13"]["state"]).to eql("on-line") expect(@plugin["cpu"]["11"]["state"]).to eql("on-line") @@ -629,7 +629,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do end describe "on sparc processors" do - before(:each) do + before do kstatinfo_output = <<~END cpu_info:0:cpu_info0:brand SPARC-T3 cpu_info:0:cpu_info0:chip_id 0 @@ -2812,32 +2812,32 @@ describe Ohai::System, "Solaris2.X cpu plugin" do @plugin.run end - it "should get the total virtual processor count" do + it "gets the total virtual processor count" do expect(@plugin["cpu"]["total"]).to eql(128) end - it "should get the total processor count" do + it "gets the total processor count" do expect(@plugin["cpu"]["real"]).to eql(1) end - it "should get the total core count" do + it "gets the total core count" do expect(@plugin["cpu"]["cores"]).to eql(16) end - it "should get the number of threads per core" do + it "gets the number of threads per core" do expect(@plugin["cpu"]["corethreads"]).to eql(8) end - it "should get the total number of online cores" do + it "gets the total number of online cores" do expect(@plugin["cpu"]["cpustates"]["on-line"]).to eql(124) end - it "should get the total number of offline cores" do + it "gets the total number of offline cores" do expect(@plugin["cpu"]["cpustates"]["off-line"]).to eql(4) end describe "per-cpu information" do - it "should include processor model names" do + it "includes processor model names" do expect(@plugin["cpu"]["0"]["model_name"]).to eql("SPARC-T3") expect(@plugin["cpu"]["1"]["model_name"]).to eql("SPARC-T3") expect(@plugin["cpu"]["2"]["model_name"]).to eql("SPARC-T3") @@ -2848,7 +2848,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["127"]["model_name"]).to eql("SPARC-T4") end - it "should include processor sockets" do + it "includes processor sockets" do expect(@plugin["cpu"]["0"]["socket"]).to eql("0") expect(@plugin["cpu"]["1"]["socket"]).to eql("0") expect(@plugin["cpu"]["2"]["socket"]).to eql("0") @@ -2859,7 +2859,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["127"]["socket"]).to eql("0") end - it "should include processor MHz" do + it "includes processor MHz" do expect(@plugin["cpu"]["0"]["mhz"]).to eql("1649") expect(@plugin["cpu"]["1"]["mhz"]).to eql("1649") expect(@plugin["cpu"]["2"]["mhz"]).to eql("1649") @@ -2870,7 +2870,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["127"]["mhz"]).to eql("1649") end - it "should include processor core IDs" do + it "includes processor core IDs" do expect(@plugin["cpu"]["0"]["core_id"]).to eql("1026") expect(@plugin["cpu"]["8"]["core_id"]).to eql("1033") expect(@plugin["cpu"]["16"]["core_id"]).to eql("1040") @@ -2889,7 +2889,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["120"]["core_id"]).to eql("1131") end - it "should include processor architecture" do + it "includes processor architecture" do expect(@plugin["cpu"]["0"]["arch"]).to eql("sparcv9") expect(@plugin["cpu"]["1"]["arch"]).to eql("sparcv9") expect(@plugin["cpu"]["2"]["arch"]).to eql("sparcv9") @@ -2900,7 +2900,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["127"]["arch"]).to eql("sparcv9") end - it "should include processor FPU type" do + it "includes processor FPU type" do expect(@plugin["cpu"]["0"]["fpu_type"]).to eql("sparcv9") expect(@plugin["cpu"]["1"]["fpu_type"]).to eql("sparcv9") expect(@plugin["cpu"]["2"]["fpu_type"]).to eql("sparcv9") @@ -2911,7 +2911,7 @@ describe Ohai::System, "Solaris2.X cpu plugin" do expect(@plugin["cpu"]["127"]["fpu_type"]).to eql("sparcv9") end - it "should include processor state" do + it "includes processor state" do expect(@plugin["cpu"]["0"]["state"]).to eql("on-line") expect(@plugin["cpu"]["1"]["state"]).to eql("on-line") expect(@plugin["cpu"]["2"]["state"]).to eql("on-line") diff --git a/spec/unit/plugins/solaris2/dmi_spec.rb b/spec/unit/plugins/solaris2/dmi_spec.rb index 50b45cd8..fcc2225e 100644 --- a/spec/unit/plugins/solaris2/dmi_spec.rb +++ b/spec/unit/plugins/solaris2/dmi_spec.rb @@ -112,14 +112,14 @@ SOLARIS_DMI_OUT = <<~EOS.freeze EOS describe Ohai::System, "Solaris2.X DMI plugin" do - before(:each) do + before do @plugin = get_plugin("solaris2/dmi") allow(@plugin).to receive(:collect_os).and_return("solaris2") @stdout = SOLARIS_DMI_OUT allow(@plugin).to receive(:shell_out).with("smbios").and_return(mock_shell_out(0, @stdout, "")) end - it "should run smbios" do + it "runs smbios" do expect(@plugin).to receive(:shell_out).with("smbios").and_return(mock_shell_out(0, @stdout, "")) @plugin.run end @@ -139,14 +139,14 @@ describe Ohai::System, "Solaris2.X DMI plugin" do }, }.each do |id, data| data.each do |attribute, value| - it "should have [:dmi][:#{id}][:#{attribute}] set" do + it "has [:dmi][:#{id}][:#{attribute}] set" do @plugin.run expect(@plugin[:dmi][id][attribute]).to eql(value) end end end - it "should ignore unwanted types" do + it "ignores unwanted types" do @plugin.run expect(@plugin[:dmi]).not_to have_key(:on_board_devices) end diff --git a/spec/unit/plugins/solaris2/filesystem.rb b/spec/unit/plugins/solaris2/filesystem.rb index d60432eb..b1cce7fa 100644 --- a/spec/unit/plugins/solaris2/filesystem.rb +++ b/spec/unit/plugins/solaris2/filesystem.rb @@ -20,14 +20,14 @@ require_relative "spec_helper" describe Ohai::System, "Solaris2.X filesystem plugin" do let(:plugin) { get_plugin("filesystem") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return("solaris2") end describe "filesystem properties" do let(:plugin_config) { {} } - before(:each) do + before do @original_plugin_config = Ohai.config[:plugin] Ohai.config[:plugin] = plugin_config allow(plugin).to receive(:shell_out).with("df -Pka").and_return(mock_shell_out(0, "", "")) @@ -326,7 +326,7 @@ describe Ohai::System, "Solaris2.X filesystem plugin" do ZFS_GET end - after(:each) do + after do Ohai.config[:plugin] = @original_plugin_config end diff --git a/spec/unit/plugins/solaris2/hostname_spec.rb b/spec/unit/plugins/solaris2/hostname_spec.rb index 3b3502cd..a8db9478 100644 --- a/spec/unit/plugins/solaris2/hostname_spec.rb +++ b/spec/unit/plugins/solaris2/hostname_spec.rb @@ -19,7 +19,7 @@ require "spec_helper" describe Ohai::System, "Solaris2.X hostname plugin" do - before(:each) do + before do @plugin = get_plugin("hostname") allow(@plugin).to receive(:collect_os).and_return(:solaris2) allow(@plugin).to receive(:resolve_fqdn).and_return("kitteh.inurfridge.eatinurfoodz") @@ -29,7 +29,7 @@ describe Ohai::System, "Solaris2.X hostname plugin" do it_should_check_from("solaris2::hostname", "hostname", "hostname", "kitteh") - it "should get the fqdn value from #resolve_fqdn" do + it "gets the fqdn value from #resolve_fqdn" do @plugin.run expect(@plugin["fqdn"]).to eq("kitteh.inurfridge.eatinurfoodz") end diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb index 633742f6..e2f7971d 100644 --- a/spec/unit/plugins/solaris2/kernel_spec.rb +++ b/spec/unit/plugins/solaris2/kernel_spec.rb @@ -133,7 +133,7 @@ describe Ohai::System, "Solaris2.X kernel plugin" do 146 121719e 28c - 1 RT_DPTBL (realtime dispatch table) TOOMUCH - before(:each) do + before do @plugin = get_plugin("kernel") allow(@plugin).to receive(:collect_os).and_return(:solaris2) allow(@plugin).to receive(:init_kernel).and_return({}) @@ -143,21 +143,21 @@ describe Ohai::System, "Solaris2.X kernel plugin" do allow(File).to receive(:open).with("/etc/release").and_yield(@release) end - it "should give the Solaris update version information" do + it "gives the Solaris update version information" do @release = StringIO.new(" Solaris 10 10/08 s10s_u6wos_07b SPARC\n Use is subject to license terms.\n Assembled 27 October 2008") allow(File).to receive(:open).with("/etc/release").and_yield(@release) @plugin.run expect(@plugin[:kernel][:update]).to eq("10 10/08 s10s_u6wos_07") end - it "should give the Oracle Solaris update version information" do + it "gives the Oracle Solaris update version information" do @release = StringIO.new(" Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC\n Assembled 17 January 2013") allow(File).to receive(:open).with("/etc/release").and_yield(@release) @plugin.run expect(@plugin[:kernel][:update]).to eq("10 1/13 s10s_u11wos_24") end - it "should give the Solaris 11 update version information" do + it "gives the Solaris 11 update version information" do @release = StringIO.new(" Oracle Solaris 11.3 SPARC\n Assembled 25 July 2016") allow(File).to receive(:open).with("/etc/release").and_yield(@release) @plugin.run diff --git a/spec/unit/plugins/solaris2/memory_spec.rb b/spec/unit/plugins/solaris2/memory_spec.rb index fe7d2755..11fc88b9 100644 --- a/spec/unit/plugins/solaris2/memory_spec.rb +++ b/spec/unit/plugins/solaris2/memory_spec.rb @@ -17,7 +17,7 @@ require "spec_helper" describe Ohai::System, "Solaris2.X memory plugin" do - before(:each) do + before do @plugin = get_plugin("solaris2/memory") allow(@plugin).to receive(:collect_os).and_return("solaris2") allow(@plugin).to receive(:shell_out).with("prtconf | grep Memory").and_return(mock_shell_out(0, "Memory size: 8194 Megabytes\n", "")) @@ -25,17 +25,17 @@ describe Ohai::System, "Solaris2.X memory plugin" do allow(@plugin).to receive(:shell_out).with("swap -s").and_return(mock_shell_out(0, @swap_s, "")) end - it "should get the total memory" do + it "gets the total memory" do @plugin.run expect(@plugin[:memory][:total]).to eql("#{8194 * 1024}kB") end - it "should get total swap" do + it "gets total swap" do @plugin.run expect(@plugin[:memory][:swap][:total]).to eql("#{(470096232 + 47057688)}kB" ) end - it "should get free swap" do + it "gets free swap" do @plugin.run expect(@plugin[:memory][:swap][:free]).to eql("47057688kB") end diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb index 249c27d9..3a1560a3 100644 --- a/spec/unit/plugins/solaris2/platform_spec.rb +++ b/spec/unit/plugins/solaris2/platform_spec.rb @@ -19,14 +19,14 @@ require "spec_helper" describe Ohai::System, "Solaris plugin platform" do - before(:each) do + before do @plugin = get_plugin("solaris2/platform") allow(@plugin).to receive(:collect_os).and_return(:solaris2) allow(@plugin).to receive(:shell_out).with("/sbin/uname -X") end describe "on SmartOS" do - before(:each) do + before do @uname_x = <<~UNAME_X System = SunOS Node = node.example.com @@ -48,17 +48,17 @@ describe Ohai::System, "Solaris plugin platform" do allow(File).to receive(:open).with("/etc/release").and_yield(@release) end - it "should run uname and set platform and build" do + it "runs uname and set platform and build" do @plugin.run expect(@plugin[:platform_build]).to eq("joyent_20120130T201844Z") end - it "should set the platform" do + it "sets the platform" do @plugin.run expect(@plugin[:platform]).to eq("smartos") end - it "should set the platform_version" do + it "sets the platform_version" do @plugin.run expect(@plugin[:platform_version]).to eq("5.11") end @@ -66,7 +66,7 @@ describe Ohai::System, "Solaris plugin platform" do end describe "on Solaris 11" do - before(:each) do + before do @uname_x = <<~UNAME_X System = SunOS Node = node.example.com @@ -88,17 +88,17 @@ describe Ohai::System, "Solaris plugin platform" do allow(File).to receive(:open).with("/etc/release").and_yield(@release) end - it "should run uname and set platform and build" do + it "runs uname and set platform and build" do @plugin.run expect(@plugin[:platform_build]).to eq("11.1") end - it "should set the platform" do + it "sets the platform" do @plugin.run expect(@plugin[:platform]).to eq("solaris2") end - it "should set the platform_version" do + it "sets the platform_version" do @plugin.run expect(@plugin[:platform_version]).to eq("5.11") end diff --git a/spec/unit/plugins/solaris2/virtualization_spec.rb b/spec/unit/plugins/solaris2/virtualization_spec.rb index 205b053c..fb3ce8cb 100644 --- a/spec/unit/plugins/solaris2/virtualization_spec.rb +++ b/spec/unit/plugins/solaris2/virtualization_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "Solaris virtualization platform" do let(:plugin) { get_plugin("solaris2/virtualization") } - before(:each) do + before do @psrinfo_pv = <<~PSRINFO_PV The physical processor has 1 virtual processor (0) x86 (GenuineIntel family 6 model 2 step 3 clock 2667 MHz) @@ -39,16 +39,16 @@ describe Ohai::System, "Solaris virtualization platform" do end describe "when we are checking for kvm" do - before(:each) do + before do expect(File).to receive(:exist?).with("/usr/sbin/psrinfo").and_return(true) end - it "should run psrinfo -pv" do + it "runs psrinfo -pv" do expect(plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv") plugin.run end - it "Should set kvm guest if psrinfo -pv contains QEMU Virtual CPU" do + it "sets kvm guest if psrinfo -pv contains QEMU Virtual CPU" do allow(plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "QEMU Virtual CPU", "")) plugin.run expect(plugin[:virtualization][:system]).to eq("kvm") @@ -56,7 +56,7 @@ describe Ohai::System, "Solaris virtualization platform" do expect(plugin[:virtualization][:systems][:kvm]).to eq("guest") end - it "should not set virtualization if kvm isn't there" do + it "does not set virtualization if kvm isn't there" do expect(plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, @psrinfo_pv, "")) plugin.run expect(plugin[:virtualization][:systems]).to eq({}) @@ -90,7 +90,7 @@ describe Ohai::System, "Solaris virtualization platform" do end end - it "should not set virtualization if no tests match" do + it "does not set virtualization if no tests match" do plugin.run expect(plugin[:virtualization][:systems]).to eq({}) end diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb index b4dfc7e0..8eea800e 100644 --- a/spec/unit/plugins/ssh_host_keys_spec.rb +++ b/spec/unit/plugins/ssh_host_keys_spec.rb @@ -20,7 +20,7 @@ require "spec_helper" describe Ohai::System, "ssh_host_key plugin" do - before(:each) do + before do @plugin = get_plugin("ssh_host_key") @plugin[:keys] = Mash.new @@ -83,6 +83,7 @@ describe Ohai::System, "ssh_host_key plugin" do HostKey /etc/ssh/ssh_host_ed25519_key EOS end + it_behaves_like "loads keys" end @@ -96,6 +97,7 @@ describe Ohai::System, "ssh_host_key plugin" do #HostKey /etc/ssh/ssh_host_ed25519_key EOS end + it_behaves_like "loads keys" end @@ -103,6 +105,7 @@ describe Ohai::System, "ssh_host_key plugin" do let :sshd_config_file do nil end + before do allow(File).to receive(:exist?).with("/etc/ssh/sshd_config").and_return(false) allow(File).to receive(:exist?).with("/etc/sshd_config").and_return(false) diff --git a/spec/unit/plugins/sysconf_spec.rb b/spec/unit/plugins/sysconf_spec.rb index 8e979110..0df9f71c 100644 --- a/spec/unit/plugins/sysconf_spec.rb +++ b/spec/unit/plugins/sysconf_spec.rb @@ -21,7 +21,7 @@ require "spec_helper" describe Ohai::System, "sysconf plugin", :unix_only do let(:plugin) { get_plugin("sysconf") } - it "should populate sysconf if getconf is found" do + it "populates sysconf if getconf is found" do getconf_out = <<~GETCONF_OUT LINK_MAX 65000 _POSIX_LINK_MAX 65000 @@ -672,7 +672,7 @@ describe Ohai::System, "sysconf plugin", :unix_only do }) end - it "should not populate sysconf if getconf is not found" do + it "does not populate sysconf if getconf is not found" do allow(plugin).to receive(:which).with("getconf").and_return(false) plugin.run expect(plugin[:sysconf]).to be(nil) diff --git a/spec/unit/plugins/timezone_spec.rb b/spec/unit/plugins/timezone_spec.rb index 6ced5a25..154ccfd3 100644 --- a/spec/unit/plugins/timezone_spec.rb +++ b/spec/unit/plugins/timezone_spec.rb @@ -18,12 +18,12 @@ require "spec_helper" describe Ohai::System, "timezone plugin" do - before(:each) do + before do @plugin = get_plugin("timezone") allow(Time).to receive_message_chain(:now, :getlocal, :zone) { "ZZZ" } end - it "should get the local timezone" do + it "gets the local timezone" do @plugin.run expect(@plugin["time"]["timezone"]).to eq("ZZZ") end diff --git a/spec/unit/plugins/virtualbox_spec.rb b/spec/unit/plugins/virtualbox_spec.rb index 27ad6fd5..a884e3fa 100644 --- a/spec/unit/plugins/virtualbox_spec.rb +++ b/spec/unit/plugins/virtualbox_spec.rb @@ -299,13 +299,13 @@ EOF describe Ohai::System, "plugin virtualbox" do let(:plugin) { get_plugin("virtualbox") } - before(:each) do + before do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new end context "when not on a virtualbox guest" do - it "should not set the virtualbox attribute" do + it "does not set the virtualbox attribute" do plugin[:virtualization][:systems][:vmware] = "host" plugin.run expect(plugin).not_to have_key(:virtualbox) @@ -314,7 +314,7 @@ describe Ohai::System, "plugin virtualbox" do context "when on a vbox guest" do context "when VBoxControl shellout fails" do - it "should not set the virtualbox attribute" do + it "does not set the virtualbox attribute" do plugin[:virtualization][:systems][:vbox] = "guest" allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(1, "", "")) plugin.run @@ -323,29 +323,29 @@ describe Ohai::System, "plugin virtualbox" do end context "when VBoxControl shellout succeeds" do - before(:each) do + before do plugin[:virtualization][:systems][:vbox] = "guest" allow(plugin).to receive(:shell_out).with("VBoxControl guestproperty enumerate").and_return(mock_shell_out(0, vbox_output, "")) plugin.run end - it "should set the host version" do + it "sets the host version" do expect(plugin[:virtualbox][:host][:version]).to eql("5.0.10") end - it "should set the host revision" do + it "sets the host revision" do expect(plugin[:virtualbox][:host][:revision]).to eql("104061") end - it "should set the host language" do + it "sets the host language" do expect(plugin[:virtualbox][:host][:language]).to eql("en_US") end - it "should set the guest additions version" do + it "sets the guest additions version" do expect(plugin[:virtualbox][:guest][:guest_additions_version]).to eql("5.0.2") end - it "should set the guest additions revision" do + it "sets the guest additions revision" do expect(plugin[:virtualbox][:guest][:guest_additions_revision]).to eql("102096") end end @@ -353,7 +353,7 @@ describe Ohai::System, "plugin virtualbox" do context "when on a vbox host" do context "if the host has virtualbox installed" do - it "should create a vbox attribute with accurate data" 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") allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted vms").and_return(mock_shell_out(0, vbox_list_vms_stdout, "")) diff --git a/spec/unit/plugins/vmware_spec.rb b/spec/unit/plugins/vmware_spec.rb index 74443312..8e746940 100644 --- a/spec/unit/plugins/vmware_spec.rb +++ b/spec/unit/plugins/vmware_spec.rb @@ -21,12 +21,12 @@ describe Ohai::System, "plugin vmware" do let(:plugin) { get_plugin("vmware") } let(:path) { "/usr/bin/vmware-toolbox-cmd" } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:linux) end context "on vmware guest with toolbox installed" do - before(:each) 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)) allow(plugin).to receive(:shell_out).with("#{path} stat hosttime").and_return(mock_shell_out(0, "04 Jun 2015 19:21:16", nil)) @@ -59,7 +59,7 @@ describe Ohai::System, "plugin vmware" do end context "on vmware guest without toolbox" do - it "should not create a vmware attribute" do + it "does not create a vmware attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new plugin[:virtualization][:systems][:vmware] = Mash.new @@ -70,7 +70,7 @@ describe Ohai::System, "plugin vmware" do end context "on vbox guest" do - it "should not create a vmware attribute" do + it "does not create a vmware attribute" do plugin[:virtualization] = Mash.new plugin[:virtualization][:systems] = Mash.new plugin[:virtualization][:systems][:vbox] = Mash.new diff --git a/spec/unit/plugins/windows/cpu_spec.rb b/spec/unit/plugins/windows/cpu_spec.rb index 06665c06..551f030d 100644 --- a/spec/unit/plugins/windows/cpu_spec.rb +++ b/spec/unit/plugins/windows/cpu_spec.rb @@ -20,48 +20,48 @@ require "spec_helper" shared_examples "a cpu" do |cpu_no| describe "cpu #{cpu_no}" do - it "should set physical_id to CPU#{cpu_no}" do + it "sets physical_id to CPU#{cpu_no}" do expect(@plugin[:cpu][cpu_no.to_s][:physical_id]).to eq("CPU#{cpu_no}") end - it "should set mhz to 2793" do + it "sets mhz to 2793" do expect(@plugin[:cpu][cpu_no.to_s][:mhz]).to eq("2793") end - it "should set vendor_id to GenuineIntel" do + it "sets vendor_id to GenuineIntel" do expect(@plugin[:cpu][cpu_no.to_s][:vendor_id]).to eq("GenuineIntel") end - it "should set model_name to Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz" do + it "sets model_name to Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz" do expect(@plugin[:cpu][cpu_no.to_s][:model_name]) .to eq("Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz") end - it "should set description to Intel64 Family 6 Model 70 Stepping 1" do + it "sets description to Intel64 Family 6 Model 70 Stepping 1" do expect(@plugin[:cpu][cpu_no.to_s][:description]) .to eq("Intel64 Family 6 Model 70 Stepping 1") end - it "should set model to 17921" do + it "sets model to 17921" do expect(@plugin[:cpu][cpu_no.to_s][:model]).to eq("17921") end - it "should set family to 2" do + it "sets family to 2" do expect(@plugin[:cpu][cpu_no.to_s][:family]).to eq("2") end - it "should set stepping to 9" do + it "sets stepping to 9" do expect(@plugin[:cpu][cpu_no.to_s][:stepping]).to eq(9) end - it "should set cache_size to 64 KB" do + it "sets cache_size to 64 KB" do expect(@plugin[:cpu][cpu_no.to_s][:cache_size]).to eq("64 KB") end end end describe Ohai::System, "Windows cpu plugin" do - before(:each) do + before do @plugin = get_plugin("cpu") allow(@plugin).to receive(:collect_os).and_return(:windows) @@ -100,15 +100,15 @@ describe Ohai::System, "Windows cpu plugin" do @plugin.run end - it "should set total cpu to 2" do + it "sets total cpu to 2" do expect(@plugin[:cpu][:total]).to eq(4) end - it "should set real cpu to 2" do + it "sets real cpu to 2" do expect(@plugin[:cpu][:real]).to eq(2) end - it "should set 2 distinct cpus numbered 0 and 1" do + it "sets 2 distinct cpus numbered 0 and 1" do expect(@plugin[:cpu]).to have_key("0") expect(@plugin[:cpu]).to have_key("1") end diff --git a/spec/unit/plugins/windows/filesystem_spec.rb b/spec/unit/plugins/windows/filesystem_spec.rb index e1f33b70..0d6c0632 100644 --- a/spec/unit/plugins/windows/filesystem_spec.rb +++ b/spec/unit/plugins/windows/filesystem_spec.rb @@ -66,7 +66,7 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do WmiLite::WmiException.new(exception, :ConnectServer, @namespace) end - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:windows) end diff --git a/spec/unit/plugins/windows/fips_spec.rb b/spec/unit/plugins/windows/fips_spec.rb index 83876c82..b0b36f54 100644 --- a/spec/unit/plugins/windows/fips_spec.rb +++ b/spec/unit/plugins/windows/fips_spec.rb @@ -20,16 +20,16 @@ require "spec_helper" require "openssl" describe Ohai::System, "plugin fips" do - let(:enabled) { 0 } - let(:plugin) { get_plugin("windows/fips") } - let(:openssl_test_mode) { false } - subject do plugin.run plugin["fips"]["kernel"]["enabled"] end - before(:each) do + let(:enabled) { 0 } + let(:plugin) { get_plugin("windows/fips") } + let(:openssl_test_mode) { false } + + before do allow(plugin).to receive(:collect_os).and_return(:windows) end @@ -44,6 +44,7 @@ describe Ohai::System, "plugin fips" do context "with OpenSSL.fips_mode == false" do before { allow(OpenSSL).to receive(:fips_mode).and_return(false) } + it "does not set fips plugin" do expect(subject).to be(false) end @@ -51,6 +52,7 @@ describe Ohai::System, "plugin fips" do context "with OpenSSL.fips_mode == true" do before { allow(OpenSSL).to receive(:fips_mode).and_return(true) } + it "sets fips plugin" do expect(subject).to be(true) end diff --git a/spec/unit/plugins/windows/kernel_spec.rb b/spec/unit/plugins/windows/kernel_spec.rb index d72c2eaa..6127848c 100644 --- a/spec/unit/plugins/windows/kernel_spec.rb +++ b/spec/unit/plugins/windows/kernel_spec.rb @@ -65,7 +65,7 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do plugin.run end - it "should set the correct system information" do + it "sets the correct system information" do expect(plugin[:kernel][:name]).to eq("Microsoft Windows 7 Ultimate") expect(plugin[:kernel][:release]).to eq("6.1.7601") expect(plugin[:kernel][:version]).to eq("6.1.7601 Service Pack 1 Build 7601") diff --git a/spec/unit/plugins/windows/memory_spec.rb b/spec/unit/plugins/windows/memory_spec.rb index 0fad7744..38e88eda 100644 --- a/spec/unit/plugins/windows/memory_spec.rb +++ b/spec/unit/plugins/windows/memory_spec.rb @@ -29,22 +29,22 @@ describe Ohai::System, "Windows memory plugin", :windows_only do expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with("Win32_OperatingSystem").and_return(mock_os) end - it "should get total memory" do + it "gets total memory" do @plugin.run expect(@plugin["memory"]["total"]).to eql("10485760kB") end - it "should get free memory" do + it "gets free memory" do @plugin.run expect(@plugin["memory"]["free"]).to eql("5242880kB") end - it "should get total swap" do + it "gets total swap" do @plugin.run expect(@plugin["memory"]["swap"]["total"]).to eql("20971520kB") end - it "should get free memory" do + it "gets free memory" do @plugin.run expect(@plugin["memory"]["swap"]["free"]).to eql("15728640kB") end diff --git a/spec/unit/plugins/windows/network_spec.rb b/spec/unit/plugins/windows/network_spec.rb index 84efa447..2a7479ca 100644 --- a/spec/unit/plugins/windows/network_spec.rb +++ b/spec/unit/plugins/windows/network_spec.rb @@ -22,7 +22,7 @@ require "ipaddress" describe Ohai::System, "Windows Network Plugin" do let(:plugin) { get_plugin("windows/network") } - before(:each) do + before do allow(plugin).to receive(:collect_os).and_return(:windows) end diff --git a/spec/unit/plugins/windows/system_enclosure_spec.rb b/spec/unit/plugins/windows/system_enclosure_spec.rb index 5051c8c0..0e1bbc93 100644 --- a/spec/unit/plugins/windows/system_enclosure_spec.rb +++ b/spec/unit/plugins/windows/system_enclosure_spec.rb @@ -33,12 +33,12 @@ describe Ohai::System, "System Enclosure", :windows_only do expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with(("Win32_SystemEnclosure")).and_return(wmi_object) end - it "should return the manufacturer" do + it "returns the manufacturer" do @plugin.run expect(@plugin["system_enclosure"]["manufacturer"]).to eql("My Fake Manufacturer") end - it "should return a serial number" do + it "returns a serial number" do @plugin.run expect(@plugin["system_enclosure"]["serialnumber"]).to eql("1234123412341234") end diff --git a/spec/unit/plugins/windows/uptime_spec.rb b/spec/unit/plugins/windows/uptime_spec.rb index a3fe0138..6486ded7 100644 --- a/spec/unit/plugins/windows/uptime_spec.rb +++ b/spec/unit/plugins/windows/uptime_spec.rb @@ -23,7 +23,7 @@ describe Ohai::System, "Windows plugin uptime" do let(:plugin) { get_plugin("uptime") } let(:wmi) { double("wmi", { first_of: "" }) } - before(:each) do + before do allow(WmiLite::Wmi).to receive(:new).and_return(wmi) allow(plugin).to receive(:collect_os).and_return(:windows) end diff --git a/spec/unit/plugins/windows/virtualization_spec.rb b/spec/unit/plugins/windows/virtualization_spec.rb index 564ff14c..07badbda 100644 --- a/spec/unit/plugins/windows/virtualization_spec.rb +++ b/spec/unit/plugins/windows/virtualization_spec.rb @@ -24,7 +24,7 @@ describe Ohai::System, "Windows virtualization platform" do let(:plugin) { get_plugin("windows/virtualization") } let(:wmi) { double("WmiLite::Wmi") } - before(:each) do + before do allow(WmiLite::Wmi).to receive(:new).and_return(wmi) allow(plugin).to receive(:collect_os).and_return(:windows) end diff --git a/spec/unit/plugins/zpools_spec.rb b/spec/unit/plugins/zpools_spec.rb index 1868da48..fc16bc2e 100644 --- a/spec/unit/plugins/zpools_spec.rb +++ b/spec/unit/plugins/zpools_spec.rb @@ -66,6 +66,7 @@ describe Ohai::System, "zpools plugin" do errors: No known data errors EOSR end + before do allow(plugin).to receive(:platform_family).and_return("rhel") allow(plugin).to receive(:collect_os).and_return(:linux) @@ -177,6 +178,7 @@ describe Ohai::System, "zpools plugin" do errors: No known data errors EOSR end + before do allow(plugin).to receive(:platform_family).and_return("solaris2") allow(plugin).to receive(:collect_os).and_return(:solaris2) diff --git a/spec/unit/provides_map_spec.rb b/spec/unit/provides_map_spec.rb index 47b1d753..6e689057 100644 --- a/spec/unit/provides_map_spec.rb +++ b/spec/unit/provides_map_spec.rb @@ -30,13 +30,13 @@ describe Ohai::ProvidesMap do describe "when looking up providing plugins for a single attribute" do describe "when the attribute does not exist" do - it "should raise Ohai::Exceptions::AttributeNotFound error" do + it "raises Ohai::Exceptions::AttributeNotFound error" do expect { provides_map.find_providers_for(["single"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'single'") end end describe "when the attribute does not have a provider" do - it "should raise Ohai::Exceptions::ProviderNotFound error" do + it "raises Ohai::Exceptions::ProviderNotFound error" do provides_map.set_providers_for(plugin_1, ["first/second"]) expect { provides_map.find_providers_for(["first"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'first'") end @@ -47,7 +47,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_1, ["single"]) end - it "should return the provider" do + it "returns the provider" do expect(provides_map.find_providers_for(["single"])).to eq([plugin_1]) end end @@ -58,7 +58,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_2, ["single"]) end - it "should return all providers" do + it "returns all providers" do expect(provides_map.find_providers_for(["single"])).to eq([plugin_1, plugin_2]) end end @@ -72,7 +72,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_2, ["two"]) end - it "should return each provider" do + it "returns each provider" do expect(provides_map.find_providers_for(%w{one two})).to eq([plugin_1, plugin_2]) end end @@ -84,7 +84,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_1, ["one_again"]) end - it "should return unique providers" do + it "returns unique providers" do expect(provides_map.find_providers_for(%w{one one_again})).to eq([plugin_1]) end end @@ -96,7 +96,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_1, ["top/middle/bottom"]) end - it "should collect the provider" do + it "collects the provider" do expect(provides_map.find_providers_for(["top/middle/bottom"])).to eq([plugin_1]) end end @@ -104,13 +104,13 @@ describe Ohai::ProvidesMap do describe "when setting multi-level attributes" do describe "when the attribute contains //" do - it "should raise an Ohai::Exceptions::AttributeSyntaxError" do + it "raises an Ohai::Exceptions::AttributeSyntaxError" do expect { provides_map.set_providers_for(plugin_1, ["this/plugin//is/bad"]) }.to raise_error(Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: this/plugin//is/bad") end end describe "when the attribute has a trailing slash" do - it "should raise an Ohai::Exceptions::AttributeSyntaxError" do + it "raises an Ohai::Exceptions::AttributeSyntaxError" do expect { provides_map.set_providers_for(plugin_1, ["this/plugin/is/bad/"]) }.to raise_error(Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': this/plugin/is/bad/") end end @@ -123,7 +123,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_3, ["cat/mouth/teeth"]) end - it "should find providers for subattributes if any exists when the attribute doesn't have a provider" do + it "finds providers for subattributes if any exists when the attribute doesn't have a provider" do providers = provides_map.deep_find_providers_for(["cat"]) expect(providers).to have(3).plugins expect(providers).to include(plugin_1) @@ -131,7 +131,7 @@ describe Ohai::ProvidesMap do expect(providers).to include(plugin_3) end - it "should find providers for the first parent attribute when the attribute or any subattributes doesn't have a provider" do + it "finds providers for the first parent attribute when the attribute or any subattributes doesn't have a provider" do providers = provides_map.deep_find_providers_for(["cat/paws/front"]) expect(providers).to eq([plugin_2]) end @@ -143,7 +143,7 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_1, ["do/not/eat/metal"]) end - it "should return the provider of the full attribute" do + it "returns the provider of the full attribute" do expect(provides_map.find_closest_providers_for(["do/not/eat/metal"])).to eql([plugin_1]) end end @@ -153,34 +153,34 @@ describe Ohai::ProvidesMap do provides_map.set_providers_for(plugin_1, ["do/not/eat"]) end - it "should not raise error if a parent attribute is provided" do + it "does not raise error if a parent attribute is provided" do expect { provides_map.find_closest_providers_for(["do/not/eat/plastic"]) }.not_to raise_error end - it "should return the providers of the closest parent attribute" do + it "returns the providers of the closest parent attribute" do provides_map.set_providers_for(plugin_2, ["do/not"]) # set a less-specific parent expect(provides_map.find_closest_providers_for(["do/not/eat/glass"])).to eql([plugin_1]) end - it "should raise error if the least-specific parent is not an attribute" do + it "raises error if the least-specific parent is not an attribute" do expect { provides_map.find_closest_providers_for(["please/eat/your/vegetables"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'please/eat/your/vegetables'") end - it "should raise error if no parent attribute has a provider" do + it "raises error if no parent attribute has a provider" do expect { provides_map.find_closest_providers_for(["do/not"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'do/not'") end end end describe "when listing all plugins" do - before(:each) do + before do provides_map.set_providers_for(plugin_1, ["one"]) provides_map.set_providers_for(plugin_2, ["two"]) provides_map.set_providers_for(plugin_3, ["stub/three"]) provides_map.set_providers_for(plugin_4, ["foo/bar/four", "also/this/four"]) end - it "should find all the plugins providing attributes" do + it "finds all the plugins providing attributes" do all_plugins = provides_map.all_plugins expect(all_plugins).to have(4).plugins expect(all_plugins).to include(plugin_1) diff --git a/spec/unit/runner_spec.rb b/spec/unit/runner_spec.rb index 9c37dfd2..ce111f4e 100644 --- a/spec/unit/runner_spec.rb +++ b/spec/unit/runner_spec.rb @@ -22,13 +22,13 @@ require "spec_helper" describe Ohai::Runner, "run_plugin" do let(:safe_run) { true } - before(:each) do + before do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, safe_run) end describe "when running an invalid plugin" do - it "should raise error" do + it "raises error" do expect { @runner.run_plugin(double("Ohai::NotPlugin")) }.to raise_error(Ohai::Exceptions::InvalidPlugin) end end @@ -39,7 +39,7 @@ describe Ohai::Runner, "run_plugin" do let(:has_run) { false } describe "version 7" do - it "should call run_v7_plugin" do + it "calls run_v7_plugin" do expect(@runner).to receive(:run_v7_plugin) @runner.run_plugin(plugin) end @@ -47,7 +47,7 @@ describe Ohai::Runner, "run_plugin" do describe "if the plugin has run before" do let(:has_run) { true } - it "should not run the plugin" do + it "does not run the plugin" do expect(plugin).not_to receive(:safe_run) @runner.run_plugin(plugin) end @@ -57,7 +57,7 @@ describe Ohai::Runner, "run_plugin" do describe "invalid version" do let(:version) { :versionBla } - it "should raise error" do + it "raises error" do expect { @runner.run_plugin(plugin) }.to raise_error(Ohai::Exceptions::InvalidPlugin) end end @@ -74,12 +74,12 @@ describe Ohai::Runner, "run_plugin" do klass.new(@ohai.data, @ohai.logger) end - it "should run the plugin" do + it "runs the plugin" do @runner.run_plugin(plugin) expect(plugin.has_run?).to be true end - it "should add plugin data to Ohai::System.data" do + it "adds plugin data to Ohai::System.data" do @runner.run_plugin(plugin) expect(@ohai.data).to have_key(:thing) expect(@ohai.data[:thing]).to eql({}) @@ -88,7 +88,7 @@ describe Ohai::Runner, "run_plugin" do describe "when running a plugin with one dependency" do describe "when the dependency does not exist" do - before(:each) do + before do klass = Ohai.plugin(:Test) do provides("thing") depends("other_thing") @@ -99,18 +99,18 @@ describe Ohai::Runner, "run_plugin" do @plugin = klass.new(@ohai.data, @ohai.logger) end - it "should raise Ohai::Excpetions::AttributeNotFound" do + it "raises Ohai::Excpetions::AttributeNotFound" do expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound) end - it "should not run the plugin" do + it "does not run the plugin" do expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound) expect(@plugin.has_run?).to be false end end describe "when the dependency has a single provider" do - before(:each) do + before do klass1 = Ohai.plugin(:Thing) do provides("thing") collect_data do @@ -134,7 +134,7 @@ describe Ohai::Runner, "run_plugin" do @ohai.provides_map.set_providers_for(@plugin1, ["thing"]) end - it "should run the plugins" do + it "runs the plugins" do @runner.run_plugin(@plugin2) @plugins.each do |plugin| expect(plugin.has_run?).to be true @@ -143,7 +143,7 @@ describe Ohai::Runner, "run_plugin" do end describe "when the dependency has multiple providers" do - before(:each) do + before do klass1 = Ohai.plugin(:Thing) do provides("thing") collect_data do @@ -168,7 +168,7 @@ describe Ohai::Runner, "run_plugin" do @ohai.provides_map.set_providers_for(@plugin2, ["thing"]) end - it "should run the plugins" do + it "runs the plugins" do @runner.run_plugin(@plugin3) @plugins.each do |plugin| expect(plugin.has_run?).to be true @@ -178,7 +178,7 @@ describe Ohai::Runner, "run_plugin" do end describe "when running a plugin with many dependencies" do - before(:each) do + before do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) @@ -211,7 +211,7 @@ describe Ohai::Runner, "run_plugin" do @ohai.provides_map.set_providers_for(@plugin2, %w{one two}) end - it "should run the plugins" do + it "runs the plugins" do @runner.run_plugin(@plugin3) @plugins.each do |plugin| expect(plugin.has_run?).to be true @@ -242,7 +242,7 @@ describe Ohai::Runner, "run_plugin" do end context "when there is one edge in the cycle (A->B and B->A)" do - before(:each) do + before do klass1 = Ohai.plugin(:Thing) do # rubocop disable Lint/UselessAssignment provides("thing") depends("other") @@ -266,7 +266,7 @@ describe Ohai::Runner, "run_plugin" do @plugin1, @plugin2 = @plugins end - it "should raise Ohai::Exceptions::DependencyCycle" do + it "raises Ohai::Exceptions::DependencyCycle" do allow(runner).to receive(:fetch_plugins).with(["thing"]).and_return([@plugin1]) allow(runner).to receive(:fetch_plugins).with(["other"]).and_return([@plugin2]) expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other" @@ -276,7 +276,7 @@ describe Ohai::Runner, "run_plugin" do end describe "when A depends on B and C, and B depends on C" do - before(:each) do + before do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) @@ -302,7 +302,7 @@ describe Ohai::Runner, "run_plugin" do @plugin_a, @plugin_b, @plugin_c = @plugins end - it "should not detect a cycle when B is the first provider returned" do + it "does not detect a cycle when B is the first provider returned" do @ohai.provides_map.set_providers_for(@plugin_a, ["A"]) @ohai.provides_map.set_providers_for(@plugin_b, ["B"]) @ohai.provides_map.set_providers_for(@plugin_c, ["C"]) @@ -315,7 +315,7 @@ describe Ohai::Runner, "run_plugin" do end end - it "should not detect a cycle when C is the first provider returned" do + it "does not detect a cycle when C is the first provider returned" do @ohai.provides_map.set_providers_for(@plugin_a, ["A"]) @ohai.provides_map.set_providers_for(@plugin_c, ["C"]) @ohai.provides_map.set_providers_for(@plugin_b, ["B"]) @@ -331,14 +331,14 @@ describe Ohai::Runner, "run_plugin" do end describe Ohai::Runner, "fetch_plugins" do - before(:each) do + before 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) end - it "should collect the provider" do + it "collects the provider" do plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger) @ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"]) @@ -348,7 +348,7 @@ describe Ohai::Runner, "fetch_plugins" do describe "when the attribute is not provided by any plugin" do describe "and some parent attribute has providers" do - it "should return the providers for the parent" do + it "returns the providers for the parent" do plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger) @provides_map.set_providers_for(plugin, ["test/attribute"]) expect(@runner.fetch_plugins(["test/attribute/too_far"])).to eql([plugin]) @@ -356,14 +356,14 @@ describe Ohai::Runner, "fetch_plugins" do end describe "and no parent attribute has providers" do - it "should raise Ohai::Exceptions::AttributeNotFound exception" do + it "raises Ohai::Exceptions::AttributeNotFound exception" do # provides map is empty expect { @runner.fetch_plugins(["false/attribute"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'false/attribute'") end end end - it "should return unique providers" do + it "returns unique providers" do plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger) @provides_map.set_providers_for(plugin, ["test", "test/too_far/way_too_far"]) expect(@runner.fetch_plugins(["test", "test/too_far/way_too_far"])).to eql([plugin]) @@ -371,7 +371,7 @@ describe Ohai::Runner, "fetch_plugins" do end describe Ohai::Runner, "#get_cycle" do - before(:each) do + before do @ohai = Ohai::System.new @runner = Ohai::Runner.new(@ohai, true) @@ -404,7 +404,7 @@ describe Ohai::Runner, "#get_cycle" do @plugin1, @plugin2, @plugin3 = plugins end - it "should return the sources for the plugins in the cycle, when given an exact cycle" do + it "returns the sources for the plugins in the cycle, when given an exact cycle" do cycle = [@plugin1, @plugin2] cycle_start = @plugin1 @@ -412,7 +412,7 @@ describe Ohai::Runner, "#get_cycle" do expect(cycle_names).to eql([@plugin1.name, @plugin2.name]) end - it "should return the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do + it "returns the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do cycle = [@plugin3, @plugin1, @plugin2] cycle_start = @plugin1 diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index fc1508e7..6d51c0ed 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -152,7 +152,7 @@ describe "Ohai::System" do end EOF - it "should collect platform specific" do + it "collects platform specific" do Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins expect(ohai.data[:message]).to eq("platform_specific_message") @@ -199,7 +199,7 @@ describe "Ohai::System" do end EOF - it "should collect data from all the plugins" do + it "collects data from all the plugins" do Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins expect(ohai.data[:zoo]).to eq("animals") @@ -208,7 +208,7 @@ describe "Ohai::System" do expect(ohai.data[:park]).to be_frozen end - it "should write an error to Ohai::Log" do + it "writes an error to Ohai::Log" do Ohai.config[:plugin_path] = [ path_to(".") ] # Make sure the stubbing of runner is not overriden with reset_system during test allow(ohai).to receive(:reset_system) @@ -226,7 +226,7 @@ describe "Ohai::System" do Ohai.config[:disabled_plugins] = [ ] end - it "shouldn't run disabled plugins" do + it "does not run disabled plugins" do Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins expect(ohai.data[:zoo]).to be_nil @@ -246,7 +246,7 @@ describe "Ohai::System" do Ohai.config[:critical_plugins] = [] end - it "should fail when critical plugins fail" do + it "fails when critical plugins fail" do Ohai.config[:plugin_path] = [ path_to(".") ] expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::CriticalPluginFailure, "The following Ohai plugins marked as critical failed: [:Fails]. Failing Chef run.") @@ -254,20 +254,20 @@ describe "Ohai::System" do end describe "when using :optional_plugins" do - it "should not run optional plugins by default" do + it "does not run optional plugins by default" do Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins expect(ohai.data[:optional]).to be_nil end - it "should run optional plugins when specifically enabled" do + it "runs optional plugins when specifically enabled" do Ohai.config[:optional_plugins] = [ :Optional ] Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins expect(ohai.data[:optional]).to eq("canteloupe") end - it "should run optional plugins when all plugins are enabled" do + it "runs optional plugins when all plugins are enabled" do Ohai.config[:run_all_plugins] = true Ohai.config[:plugin_path] = [ path_to(".") ] ohai.all_plugins @@ -294,7 +294,7 @@ describe "Ohai::System" do Ohai.config[:plugin_path] = [ path_to(".") ] end - it "should rerun the plugin providing the desired attributes" do + it "reruns the plugin providing the desired attributes" do ohai.all_plugins initial_value = ohai.data["random"] ohai.all_plugins @@ -347,19 +347,19 @@ describe "Ohai::System" do Ohai.config[:plugin_path] = [ path_to(".") ] end - it "should run all the plugins when a top level attribute is specified" do + it "runs all the plugins when a top level attribute is specified" do ohai.all_plugins("languages") expect(ohai.data[:languages][:english][:version]).to eq(2014) expect(ohai.data[:languages][:french][:version]).to eq(2012) end - it "should run the first parent when a non-existent child is specified" do + it "runs the first parent when a non-existent child is specified" do ohai.all_plugins("languages/english/version") expect(ohai.data[:languages][:english][:version]).to eq(2014) expect(ohai.data[:languages][:french]).to be_nil end - it "should be able to run multiple plugins" do + it "is able to run multiple plugins" do ohai.all_plugins(["languages/english", "languages/french"]) expect(ohai.data[:languages][:english][:version]).to eq(2014) expect(ohai.data[:languages][:french][:version]).to eq(2012) @@ -406,7 +406,7 @@ describe "Ohai::System" do end E - it "should run all the plugins" do + it "runs all the plugins" do ohai.run_additional_plugins(@plugins_directory) expect(ohai.data[:canteloupe][:english][:version]).to eq(2014) expect(ohai.data[:canteloupe][:french][:version]).to eq(2012) diff --git a/spec/unit/util/file_helper_spec.rb b/spec/unit/util/file_helper_spec.rb index 88caeb5f..8fc542f0 100644 --- a/spec/unit/util/file_helper_spec.rb +++ b/spec/unit/util/file_helper_spec.rb @@ -26,7 +26,7 @@ end describe "Ohai::Util::FileHelper" do let(:file_helper) { FileHelperMock.new } - before(:each) do + before do allow(file_helper).to receive(:name).and_return("Fakeclass") logger = instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil) allow(file_helper).to receive(:logger).and_return(logger) diff --git a/spec/unit/util/ip_helper_spec.rb b/spec/unit/util/ip_helper_spec.rb index 0532cbc9..ec9b37ba 100644 --- a/spec/unit/util/ip_helper_spec.rb +++ b/spec/unit/util/ip_helper_spec.rb @@ -78,12 +78,12 @@ describe "Ohai::Util::IpHelper" do allow(ip_helper).to receive(:private_address?) end - it "should call #private_address?" do + it "calls #private_address?" do expect(ip_helper).to receive(:private_address?) ip_helper.public_address?(address) end - it "should return the inverse of #private_address?" do + it "returns the inverse of #private_address?" do expect(ip_helper.public_address?(address)).to equal !ip_helper.private_address?(address) end end @@ -93,7 +93,7 @@ describe "Ohai::Util::IpHelper" do context "that is a loopback address" do let(:address) { "127.0.0.1" } - it "should identify the address as a loopback address" do + it "identifies the address as a loopback address" do expect(ip_helper.loopback?(address)).to be_truthy end end @@ -101,7 +101,7 @@ describe "Ohai::Util::IpHelper" do context "that is not a loopback address" do let(:address) { "1.2.3.4" } - it "should not identify the address as a loopback address" do + it "does not identify the address as a loopback address" do expect(ip_helper.loopback?(address)).to be_falsey end end @@ -111,7 +111,7 @@ describe "Ohai::Util::IpHelper" do context "that is a loopback address" do let(:address) { "0:0:0:0:0:0:0:1" } - it "should identify the address as a loopback address" do + it "identifies the address as a loopback address" do expect(ip_helper.loopback?(address)).to be_truthy end end @@ -119,7 +119,7 @@ describe "Ohai::Util::IpHelper" do context "that is not a loopback address" do let(:address) { "2400:6180:0000:00D0:0000:0000:0009:7001" } - it "should not identify the address as a loopback address" do + it "does not identify the address as a loopback address" do expect(ip_helper.loopback?(address)).to be_falsey end end |