From 8ccfd084d507bd92df4ca486920f938dc1047928 Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Mon, 12 Aug 2013 22:41:35 -0400 Subject: [PATCH] Removed Common.write in favor of File.write --- lib/linux_admin/common.rb | 7 ------- lib/linux_admin/fstab.rb | 2 +- spec/common_spec.rb | 6 ------ spec/fstab_spec.rb | 4 +--- 4 files changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/linux_admin/common.rb b/lib/linux_admin/common.rb index 1d078f2..a1e9f48 100644 --- a/lib/linux_admin/common.rb +++ b/lib/linux_admin/common.rb @@ -4,13 +4,6 @@ class LinuxAdmin class CommandError < RuntimeError; end module Common - def write(file, content) - raise ArgumentError, "file and content can not be empty" if file.blank? || content.blank? - File.open(file, "w") do |f| - f.write(content) - end - end - def cmd(cmd) Distro.local.class::COMMANDS[cmd] end diff --git a/lib/linux_admin/fstab.rb b/lib/linux_admin/fstab.rb index 6f3a1f4..b524ce1 100644 --- a/lib/linux_admin/fstab.rb +++ b/lib/linux_admin/fstab.rb @@ -29,7 +29,7 @@ def write! @entries.each do |entry| content += "#{entry.device} #{entry.mount_point} #{entry.fs_type} #{entry.mount_options} #{entry.dumpable} #{entry.fsck_order}\n" end - write('/etc/fstab', content) + File.write('/etc/fstab', content) self end diff --git a/spec/common_spec.rb b/spec/common_spec.rb index 329e1ef..d24ba33 100644 --- a/spec/common_spec.rb +++ b/spec/common_spec.rb @@ -27,12 +27,6 @@ class TestClass subject { TestClass } - context ".write" do - it "no file no content" do - expect { subject.write("", "") }.to raise_error(ArgumentError) - end - end - context ".cmd" do it "looks up local command from id" do d = double(LinuxAdmin::Distro) diff --git a/spec/fstab_spec.rb b/spec/fstab_spec.rb index 8067ef3..4199b8f 100644 --- a/spec/fstab_spec.rb +++ b/spec/fstab_spec.rb @@ -38,10 +38,8 @@ entry.fsck_order = 1 LinuxAdmin::FSTab.instance.entries = [entry] - f = StringIO.new - File.should_receive(:open).with('/etc/fstab', 'w').and_yield(f) + File.should_receive(:write).with('/etc/fstab', "/dev/sda1 / ext4 defaults 1 1\n") LinuxAdmin::FSTab.instance.write! - f.string.should == "/dev/sda1 / ext4 defaults 1 1\n" end end end