spec/unit/plugins/hostname_spec.rb in ohai-15.2.5 vs spec/unit/plugins/hostname_spec.rb in ohai-15.3.1

- old
+ new

@@ -19,78 +19,79 @@ require "spec_helper" 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", "") ) allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return( mock_shell_out(0, "", ""), mock_shell_out(0, "katie.local", "") ) 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", "") ) allow(@plugin).to receive(:shell_out).with("hostname --fqdn").and_return( mock_shell_out(0, "katie.local", "") ) 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 end end @@ -133,27 +134,27 @@ 23, "address", ] 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) allow(Socket).to receive(:gethostname).and_return("local") allow(Socket).to receive(:gethostbyname).with(anything).and_return(info) 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") end 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") end end