From 4cef28b413256b0b0a6f218efc3bf02aad6e8797 Mon Sep 17 00:00:00 2001 From: Joe Rafaniello Date: Wed, 4 Sep 2013 13:33:51 -0400 Subject: [PATCH] Don't create FSTabEntry objects for lines with only whitespace. --- lib/linux_admin/fstab.rb | 8 +------- spec/fstab_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/linux_admin/fstab.rb b/lib/linux_admin/fstab.rb index 41bb36d..647fe30 100644 --- a/lib/linux_admin/fstab.rb +++ b/lib/linux_admin/fstab.rb @@ -56,13 +56,7 @@ def write! private def read - contents = File.read('/etc/fstab') - contents = contents.lines.to_a - contents.reject! { |line| - first_char = line.strip[0] - first_char == '#' || first_char =~ /\s/ - } - contents + File.read('/etc/fstab').lines.find_all {|line| !line.blank? && !line.strip.starts_with?("#")} end def refresh diff --git a/spec/fstab_spec.rb b/spec/fstab_spec.rb index 4199b8f..d6c8111 100644 --- a/spec/fstab_spec.rb +++ b/spec/fstab_spec.rb @@ -2,8 +2,26 @@ require 'stringio' describe LinuxAdmin::FSTab do + before do + # Reset the singleton so subsequent tests get a new instance + Singleton.send :__init__, LinuxAdmin::FSTab + end + + it "newline, single spaces, tab" do + fstab = <