diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-21 18:55:32 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-22 09:44:04 -0800 |
commit | d1d43a53bfec01746208296f16a9c35056e522a1 (patch) | |
tree | 8a124bc72cd7142b3ebe0162f21fdeb6d1a6f1b7 /spec/unit/provider | |
parent | 857ce79d05fe5c35bb85ad4ca583c023a523a71a (diff) | |
download | chef-d1d43a53bfec01746208296f16a9c35056e522a1.tar.gz |
cleanup of ifconfig and route providerslcg/route-ifconfig
* run_command elimination
* shell_out array usage
* other misc cleanup
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit/provider')
-rw-r--r-- | spec/unit/provider/ifconfig/aix_spec.rb | 28 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig/debian_spec.rb | 32 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig/redhat_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/provider/ifconfig_spec.rb | 37 | ||||
-rw-r--r-- | spec/unit/provider/route_spec.rb | 42 |
5 files changed, 67 insertions, 80 deletions
diff --git a/spec/unit/provider/ifconfig/aix_spec.rb b/spec/unit/provider/ifconfig/aix_spec.rb index 7847fc9a5f..7f316c952b 100644 --- a/spec/unit/provider/ifconfig/aix_spec.rb +++ b/spec/unit/provider/ifconfig/aix_spec.rb @@ -48,7 +48,7 @@ IFCONFIG describe "#load_current_resource" do before do - @status = double(:stdout => @ifconfig_output, :exitstatus => 0) + @status = double(stdout: @ifconfig_output, exitstatus: 0) allow(@provider).to receive(:shell_out).and_return(@status) @new_resource.device "en0" end @@ -68,11 +68,11 @@ IFCONFIG it "should add an interface if it does not exist" do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end command = "chdev -l #{@new_resource.device} -a netaddr=#{@new_resource.name}" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:add) expect(@new_resource).to be_updated @@ -82,7 +82,7 @@ IFCONFIG @new_resource.device "en0" @new_resource.metric "1" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end @@ -94,11 +94,11 @@ IFCONFIG it "should enable an interface if it does not exist" do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end command = "ifconfig #{@new_resource.device} #{@new_resource.name}" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:enable) expect(@new_resource).to be_updated @@ -110,11 +110,11 @@ IFCONFIG it "should not disable an interface if it does not exist" do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:disable) expect(@new_resource).not_to be_updated @@ -124,7 +124,7 @@ IFCONFIG before do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) current_resource.device @new_resource.device @provider.instance_variable_set("@current_resource", current_resource) @@ -133,7 +133,7 @@ IFCONFIG it "should disable an interface if it exists" do command = "ifconfig #{@new_resource.device} down" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:disable) expect(@new_resource).to be_updated @@ -147,11 +147,11 @@ IFCONFIG it "should not delete an interface if it does not exist" do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) @provider.instance_variable_set("@current_resource", Chef::Resource::Ifconfig.new("10.0.0.1", @run_context)) end - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) @provider.run_action(:delete) expect(@new_resource).not_to be_updated @@ -161,7 +161,7 @@ IFCONFIG before do @new_resource.device "en10" allow(@provider).to receive(:load_current_resource) do - @provider.instance_variable_set("@status", double("Status", :exitstatus => 0)) + @provider.instance_variable_set("@status", double("Status", exitstatus: 0)) current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) current_resource.device @new_resource.device @provider.instance_variable_set("@current_resource", current_resource) @@ -170,7 +170,7 @@ IFCONFIG it "should delete an interface if it exists" do command = "chdev -l #{@new_resource.device} -a state=down" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:delete) expect(@new_resource).to be_updated diff --git a/spec/unit/provider/ifconfig/debian_spec.rb b/spec/unit/provider/ifconfig/debian_spec.rb index 1f61957721..9a90dc1e0a 100644 --- a/spec/unit/provider/ifconfig/debian_spec.rb +++ b/spec/unit/provider/ifconfig/debian_spec.rb @@ -40,12 +40,12 @@ describe Chef::Provider::Ifconfig::Debian do let(:current_resource) { Chef::Resource::Ifconfig.new("10.0.0.1", run_context) } let(:provider) do - status = double("Status", :exitstatus => 0) + status = double("Status", exitstatus: 0) provider = Chef::Provider::Ifconfig::Debian.new(new_resource, run_context) provider.instance_variable_set("@status", status) provider.current_resource = current_resource allow(provider).to receive(:load_current_resource) - allow(provider).to receive(:run_command) + allow(provider).to receive(:shell_out!) provider end @@ -77,12 +77,12 @@ describe Chef::Provider::Ifconfig::Debian do context "when the interface_dot_d directory does not exist" do before do FileUtils.rmdir tempdir_path - expect(File.exists?(tempdir_path)).to be_falsey + expect(File.exist?(tempdir_path)).to be_falsey end it "should create the /etc/network/interfaces.d directory" do provider.run_action(:add) - expect(File.exists?(tempdir_path)).to be_truthy + expect(File.exist?(tempdir_path)).to be_truthy expect(File.directory?(tempdir_path)).to be_truthy end @@ -94,7 +94,7 @@ describe Chef::Provider::Ifconfig::Debian do context "when the interface_dot_d directory exists" do before do - expect(File.exists?(tempdir_path)).to be_truthy + expect(File.exist?(tempdir_path)).to be_truthy end it "should still mark the resource as updated (we still write a file to it)" do @@ -114,13 +114,7 @@ describe Chef::Provider::Ifconfig::Debian do before do stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_FILE", tempfile.path) stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_DOT_D_DIR", tempdir_path) - config_file_ifcfg = StringIO.new(<<-EOF -iface eth0 inet static - address 10.0.0.1 - netmask 255.255.254.0 -EOF - ) - expect(File.exists?(tempdir_path)).to be_truthy # since the file exists, the enclosing dir must also exist + expect(File.exist?(tempdir_path)).to be_truthy # since the file exists, the enclosing dir must also exist end context "when the /etc/network/interfaces file has the source line" do @@ -210,12 +204,12 @@ EOF context "when the interface_dot_d directory does not exist" do before do FileUtils.rmdir tempdir_path - expect(File.exists?(tempdir_path)).to be_falsey + expect(File.exist?(tempdir_path)).to be_falsey end it "should not create the /etc/network/interfaces.d directory" do provider.run_action(:add) - expect(File.exists?(tempdir_path)).not_to be_truthy + expect(File.exist?(tempdir_path)).not_to be_truthy end it "should mark the resource as updated" do @@ -226,7 +220,7 @@ EOF context "when the interface_dot_d directory exists" do before do - expect(File.exists?(tempdir_path)).to be_truthy + expect(File.exist?(tempdir_path)).to be_truthy end it "should still mark the resource as updated (we still write a file to it)" do @@ -246,14 +240,8 @@ EOF before do stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_FILE", tempfile.path) stub_const("Chef::Provider::Ifconfig::Debian::INTERFACES_DOT_D_DIR", tempdir_path) - config_file_ifcfg = StringIO.new(<<-EOF -iface eth0 inet static - address 10.0.0.1 - netmask 255.255.254.0 - EOF - ) expect(File).not_to receive(:new).with(config_filename_ifcfg, "w") - expect(File.exists?(tempdir_path)).to be_truthy # since the file exists, the enclosing dir must also exist + expect(File.exist?(tempdir_path)).to be_truthy # since the file exists, the enclosing dir must also exist end context "when the /etc/network/interfaces file has the source line" do diff --git a/spec/unit/provider/ifconfig/redhat_spec.rb b/spec/unit/provider/ifconfig/redhat_spec.rb index 0088cef9f9..2111de02fb 100644 --- a/spec/unit/provider/ifconfig/redhat_spec.rb +++ b/spec/unit/provider/ifconfig/redhat_spec.rb @@ -25,7 +25,7 @@ describe Chef::Provider::Ifconfig::Redhat do @cookbook_collection = Chef::CookbookCollection.new([]) @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events) - #This new_resource can be called anything --> it is not the same as in ifconfig.rb + # This new_resource can be called anything --> it is not the same as in ifconfig.rb @new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) @new_resource.mask "255.255.254.0" @new_resource.metric "1" @@ -34,7 +34,7 @@ describe Chef::Provider::Ifconfig::Redhat do @provider = Chef::Provider::Ifconfig::Redhat.new(@new_resource, @run_context) @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) - status = double("Status", :exitstatus => 0) + status = double("Status", exitstatus: 0) @provider.instance_variable_set("@status", status) @provider.current_resource = @current_resource @@ -47,7 +47,7 @@ describe Chef::Provider::Ifconfig::Redhat do it "should write network-script for centos" do allow(@provider).to receive(:load_current_resource) - allow(@provider).to receive(:run_command) + allow(@provider).to receive(:shell_out!) expect(@config).to receive(:content) do |arg| expect(arg).to match(/^\s*DEVICE=eth0\s*$/) expect(arg).to match(/^\s*IPADDR=10\.0\.0\.1\s*$/) @@ -64,7 +64,7 @@ describe Chef::Provider::Ifconfig::Redhat do it "should delete network-script if it exists for centos" do @current_resource.device @new_resource.device allow(@provider).to receive(:load_current_resource) - allow(@provider).to receive(:run_command) + allow(@provider).to receive(:shell_out!) expect(@config).to receive(:run_action).with(:delete) expect(@config).to receive(:updated?).and_return(true) @provider.run_action(:delete) diff --git a/spec/unit/provider/ifconfig_spec.rb b/spec/unit/provider/ifconfig_spec.rb index db45640169..da27d647ee 100644 --- a/spec/unit/provider/ifconfig_spec.rb +++ b/spec/unit/provider/ifconfig_spec.rb @@ -16,7 +16,7 @@ # limitations under the License. # -#require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) +# require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper")) require "spec_helper" require "chef/exceptions" @@ -26,7 +26,7 @@ describe Chef::Provider::Ifconfig do @cookbook_collection = Chef::CookbookCollection.new([]) @events = Chef::EventDispatch::Dispatcher.new @run_context = Chef::RunContext.new(@node, @cookbook_collection, @events) - #This new_resource can be called anything --> it is not the same as in ifconfig.rb + # This new_resource can be called anything --> it is not the same as in ifconfig.rb @new_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) @new_resource.mask "255.255.254.0" @new_resource.metric "1" @@ -35,14 +35,14 @@ describe Chef::Provider::Ifconfig do @provider = Chef::Provider::Ifconfig.new(@new_resource, @run_context) @current_resource = Chef::Resource::Ifconfig.new("10.0.0.1", @run_context) - status = double("Status", :exitstatus => 0) + status = double("Status", exitstatus: 0) @provider.instance_variable_set("@status", status) @provider.current_resource = @current_resource end describe Chef::Provider::Ifconfig, "load_current_resource" do before do - @status = double(:stdout => "", :exitstatus => 1) + @status = double(stdout: "", exitstatus: 1) allow(@provider).to receive(:shell_out).and_return(@status) @provider.load_current_resource end @@ -57,11 +57,10 @@ describe Chef::Provider::Ifconfig do describe Chef::Provider::Ifconfig, "action_add" do it "should add an interface if it does not exist" do - #@provider.stub(:run_command).and_return(true) allow(@provider).to receive(:load_current_resource) @current_resource.inet_addr nil command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) expect(@provider).to receive(:generate_config) @provider.run_action(:add) @@ -72,7 +71,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @new_resource.target "172.16.32.2" command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:add) expect(@new_resource).to be_updated @@ -80,7 +79,7 @@ describe Chef::Provider::Ifconfig do it "should not add an interface if it already exists" do allow(@provider).to receive(:load_current_resource) - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) @current_resource.inet_addr "10.0.0.1" expect(@provider).to receive(:generate_config) @@ -88,9 +87,9 @@ describe Chef::Provider::Ifconfig do expect(@new_resource).not_to be_updated end - #We are not testing this case with the assumption that anyone writing the cookbook would not make a typo == lo - #it "should add a blank command if the #{@new_resource.device} == lo" do - #end + # We are not testing this case with the assumption that anyone writing the cookbook would not make a typo == lo + # it "should add a blank command if the #{@new_resource.device} == lo" do + # end end describe Chef::Provider::Ifconfig, "action_enable" do @@ -99,7 +98,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @current_resource.inet_addr nil command = "ifconfig eth0 10.0.0.1 netmask 255.255.254.0 metric 1 mtu 1500" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) expect(@provider).not_to receive(:generate_config) @provider.run_action(:enable) @@ -110,7 +109,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @new_resource.target "172.16.32.2" command = "ifconfig eth0 172.16.32.2 netmask 255.255.254.0 metric 1 mtu 1500" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) @provider.run_action(:enable) expect(@new_resource).to be_updated @@ -133,7 +132,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) expect(@provider).to receive(:delete_config) @provider.run_action(:delete) @@ -142,7 +141,7 @@ describe Chef::Provider::Ifconfig do it "should not delete interface if it does not exist" do allow(@provider).to receive(:load_current_resource) - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) expect(@provider).to receive(:delete_config) @provider.run_action(:delete) @@ -156,7 +155,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) expect(@provider).not_to receive(:delete_config) @provider.run_action(:disable) @@ -165,7 +164,7 @@ describe Chef::Provider::Ifconfig do it "should not delete interface if it does not exist" do allow(@provider).to receive(:load_current_resource) - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) expect(@provider).not_to receive(:delete_config) @provider.run_action(:disable) @@ -179,7 +178,7 @@ describe Chef::Provider::Ifconfig do allow(@provider).to receive(:load_current_resource) @current_resource.device "eth0" command = "ifconfig #{@new_resource.device} down" - expect(@provider).to receive(:run_command).with(:command => command) + expect(@provider).to receive(:shell_out!).with(*command.split(" ")) expect(@provider).to receive(:delete_config) @provider.run_action(:delete) @@ -190,7 +189,7 @@ describe Chef::Provider::Ifconfig do # This is so that our fake values do not get overwritten allow(@provider).to receive(:load_current_resource) # This is so that nothing actually runs - expect(@provider).not_to receive(:run_command) + expect(@provider).not_to receive(:shell_out!) expect(@provider).to receive(:delete_config) @provider.run_action(:delete) diff --git a/spec/unit/provider/route_spec.rb b/spec/unit/provider/route_spec.rb index 2e3f6e4e9e..7058d76590 100644 --- a/spec/unit/provider/route_spec.rb +++ b/spec/unit/provider/route_spec.rb @@ -51,7 +51,7 @@ describe Chef::Provider::Route do context "on linux" do before do @node.automatic_attrs[:os] = "linux" - routing_table = "Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT\n" + + routing_table = "Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT\n" \ "eth0 0064A8C0 0984A8C0 0003 0 0 0 00FFFFFF 0 0 0\n" route_file = StringIO.new(routing_table) allow(File).to receive(:open).with("/proc/net/route", "r").and_return(route_file) @@ -91,16 +91,16 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "action_add" do it "should add the route if it does not exist" do - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!) allow(@current_resource).to receive(:gateway).and_return(nil) - expect(@provider).to receive(:generate_command).once.with(:add) + expect(@provider).to receive(:generate_command).with(:add).and_return(["command"]) expect(@provider).to receive(:generate_config) @provider.run_action(:add) expect(@new_resource).to be_updated end it "should not add the route if it exists" do - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!) allow(@provider).to receive(:is_running).and_return(true) expect(@provider).not_to receive(:generate_command).with(:add) expect(@provider).to receive(:generate_config) @@ -115,7 +115,7 @@ describe Chef::Provider::Route do expect(File).to receive(:new).and_return(route_file) @resource_add = Chef::Resource::Route.new("192.168.1.0/24 via 192.168.0.1") @run_context.resource_collection << @resource_add - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(true) @resource_add.action(:add) @provider.run_action(:add) @@ -126,8 +126,8 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "action_delete" do it "should delete the route if it exists" do - allow(@provider).to receive(:run_command).and_return(true) - expect(@provider).to receive(:generate_command).once.with(:delete) + allow(@provider).to receive(:shell_out!).and_return(true) + expect(@provider).to receive(:generate_command).with(:delete).and_return(["command"]) allow(@provider).to receive(:is_running).and_return(true) @provider.run_action(:delete) expect(@new_resource).to be_updated @@ -135,7 +135,7 @@ describe Chef::Provider::Route do it "should not delete the route if it does not exist" do allow(@current_resource).to receive(:gateway).and_return(nil) - allow(@provider).to receive(:run_command).and_return(true) + allow(@provider).to receive(:shell_out!).and_return(true) expect(@provider).not_to receive(:generate_command).with(:add) @provider.run_action(:delete) expect(@new_resource).not_to be_updated @@ -145,61 +145,61 @@ describe Chef::Provider::Route do describe Chef::Provider::Route, "generate_command for action_add" do it "should include a netmask when a one is specified" do allow(@new_resource).to receive(:netmask).and_return("255.255.0.0") - expect(@provider.generate_command(:add)).to match(/\/\d{1,2}\s/) + expect(@provider.generate_command(:add).join(" ")).to match(/\/\d{1,2}/) end it "should not include a netmask when a one is specified" do allow(@new_resource).to receive(:netmask).and_return(nil) - expect(@provider.generate_command(:add)).not_to match(/\/\d{1,2}\s/) + expect(@provider.generate_command(:add).join(" ")).not_to match(/\/\d{1,2}/) end it "should include ' via $gateway ' when a gateway is specified" do - expect(@provider.generate_command(:add)).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:add).join(" ")).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}/) end it "should not include ' via $gateway ' when a gateway is not specified" do allow(@new_resource).to receive(:gateway).and_return(nil) - expect(@provider.generate_command(:add)).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:add).join(" ")).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}/) end end describe Chef::Provider::Route, "generate_command for action_delete" do it "should include a netmask when a one is specified" do allow(@new_resource).to receive(:netmask).and_return("255.255.0.0") - expect(@provider.generate_command(:delete)).to match(/\/\d{1,2}\s/) + expect(@provider.generate_command(:delete).join(" ")).to match(/\/\d{1,2}/) end it "should not include a netmask when a one is specified" do allow(@new_resource).to receive(:netmask).and_return(nil) - expect(@provider.generate_command(:delete)).not_to match(/\/\d{1,2}\s/) + expect(@provider.generate_command(:delete).join(" ")).not_to match(/\/\d{1,2}/) end it "should include ' via $gateway ' when a gateway is specified" do - expect(@provider.generate_command(:delete)).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:delete).join(" ")).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}/) end it "should not include ' via $gateway ' when a gateway is not specified" do allow(@new_resource).to receive(:gateway).and_return(nil) - expect(@provider.generate_command(:delete)).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\s/) + expect(@provider.generate_command(:delete).join(" ")).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}/) end end describe Chef::Provider::Route, "config_file_contents for action_add" do it "should include a netmask when a one is specified" do allow(@new_resource).to receive(:netmask).and_return("255.255.0.0") - expect(@provider.config_file_contents(:add, { :target => @new_resource.target, :netmask => @new_resource.netmask })).to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target, netmask: @new_resource.netmask)).to match(/\/\d{1,2}.*\n$/) end it "should not include a netmask when a one is specified" do - expect(@provider.config_file_contents(:add, { :target => @new_resource.target })).not_to match(/\/\d{1,2}.*\n$/) + expect(@provider.config_file_contents(:add, target: @new_resource.target)).not_to match(/\/\d{1,2}.*\n$/) end it "should include ' via $gateway ' when a gateway is specified" do - expect(@provider.config_file_contents(:add, { :target => @new_resource.target, :gateway => @new_resource.gateway })).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) + expect(@provider.config_file_contents(:add, target: @new_resource.target, gateway: @new_resource.gateway)).to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end it "should not include ' via $gateway ' when a gateway is not specified" do - expect(@provider.generate_command(:add)).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) + expect(@provider.generate_command(:add).join(" ")).not_to match(/\svia\s#{Regexp.escape(@new_resource.gateway.to_s)}\n/) end end @@ -216,7 +216,7 @@ describe Chef::Provider::Route do route_file = StringIO.new expect(File).to receive(:new).with("/etc/sysconfig/network-scripts/route-eth0", "w").and_return(route_file) - #Chef::Log.should_receive(:debug).with("route[10.0.0.10] writing route.eth0\n10.0.0.10 via 10.0.0.9\n") + # Chef::Log.should_receive(:debug).with("route[10.0.0.10] writing route.eth0\n10.0.0.10 via 10.0.0.9\n") @run_context.resource_collection << @new_resource @provider.generate_config end |