spec/unit/plugins/linux/lsb_spec.rb in ohai-6.24.2 vs spec/unit/plugins/linux/lsb_spec.rb in ohai-7.0.0.rc.0

- old
+ new

@@ -21,130 +21,128 @@ # We do not alter case for lsb attributes and consume them as provided describe Ohai::System, "Linux lsb plugin" do before(:each) do - @ohai = Ohai::System.new - @ohai[:os] = "linux" - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) + @plugin = get_plugin("linux/lsb") + @plugin.stub(:collect_os).and_return(:linux) end describe "on systems with /etc/lsb-release" do before(:each) do - @mock_file = mock("/etc/lsb-release") - @mock_file.stub!(:each). + @double_file = double("/etc/lsb-release") + @double_file.stub(:each). and_yield("DISTRIB_ID=Ubuntu"). and_yield("DISTRIB_RELEASE=8.04"). and_yield("DISTRIB_CODENAME=hardy"). and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"') - File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file) - File.stub!(:exists?).with("/etc/lsb-release").and_return(true) + File.stub(:open).with("/etc/lsb-release").and_return(@double_file) + File.stub(:exists?).with("/etc/lsb-release").and_return(true) end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "Ubuntu" + @plugin.run + @plugin[:lsb][:id].should == "Ubuntu" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "8.04" + @plugin.run + @plugin[:lsb][:release].should == "8.04" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "hardy" + @plugin.run + @plugin[:lsb][:codename].should == "hardy" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "Ubuntu 8.04" + @plugin.run + @plugin[:lsb][:description].should == "Ubuntu 8.04" end end describe "on systems with /usr/bin/lsb_release" do before(:each) do - File.stub!(:exists?).with("/etc/lsb-release").and_return(false) - File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(true) + File.stub(:exists?).with("/etc/lsb-release").and_return(false) + File.stub(:exists?).with("/usr/bin/lsb_release").and_return(true) - @stdin = mock("STDIN", { :close => true }) + @stdin = double("STDIN", { :close => true }) @pid = 10 - @stderr = mock("STDERR") - @stdout = mock("STDOUT") + @stderr = double("STDERR") + @stdout = double("STDOUT") @status = 0 end describe "on Centos 5.4 correctly" do before(:each) do - @stdout.stub!(:each). - and_yield("LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch"). - and_yield("Distributor ID: CentOS"). - and_yield("Description: CentOS release 5.4 (Final)"). - and_yield("Release: 5.4"). - and_yield("Codename: Final") - - @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout = <<-LSB_RELEASE +LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch +Distributor ID: CentOS +Description: CentOS release 5.4 (Final) +Release: 5.4 +Codename: Final +LSB_RELEASE + @plugin.stub(:shell_out).with("lsb_release -a").and_return(mock_shell_out(0, @stdout, "")) end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "CentOS" + @plugin.run + @plugin[:lsb][:id].should == "CentOS" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "5.4" + @plugin.run + @plugin[:lsb][:release].should == "5.4" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "Final" + @plugin.run + @plugin[:lsb][:codename].should == "Final" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "CentOS release 5.4 (Final)" + @plugin.run + @plugin[:lsb][:description].should == "CentOS release 5.4 (Final)" end end describe "on Fedora 14 correctly" do before(:each) do - @stdout.stub!(:each). - and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch"). - and_yield("Distributor ID: Fedora"). - and_yield("Description: Fedora release 14 (Laughlin)"). - and_yield("Release: 14"). - and_yield("Codename: Laughlin") - - @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @stdout = <<-LSB_RELEASE +LSB Version: :core-4.0-ia32:core-4.0-noarch +Distributor ID: Fedora +Description: Fedora release 14 (Laughlin) +Release: 14 +Codename: Laughlin +LSB_RELEASE + @plugin.stub(:shell_out).with("lsb_release -a").and_return(mock_shell_out(0, @stdout, "")) end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "Fedora" + @plugin.run + @plugin[:lsb][:id].should == "Fedora" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "14" + @plugin.run + @plugin[:lsb][:release].should == "14" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "Laughlin" + @plugin.run + @plugin[:lsb][:codename].should == "Laughlin" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)" + @plugin.run + @plugin[:lsb][:description].should == "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 - File.stub!(:exists?).with("/etc/lsb-release").and_return(false) - File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(false) - @ohai.attribute?(:lsb).should be(false) + File.stub(:exists?).with("/etc/lsb-release").and_return(false) + File.stub(:exists?).with("/usr/bin/lsb_release").and_return(false) + @plugin.attribute?(:lsb).should be(false) end end