[macruby-changes] [4686] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:59:34 PDT 2010


Revision: 4686
          http://trac.macosforge.org/projects/ruby/changeset/4686
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:59:33 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Don't break if ~/.irb_history doesn't exist yet

From: Eloy Duran <eloy at Eloy-Durans-Mac-Pro.local>

Modified Paths:
--------------
    DietRB/trunk/lib/irb/ext/history.rb
    DietRB/trunk/spec/history_spec.rb

Modified: DietRB/trunk/lib/irb/ext/history.rb
===================================================================
--- DietRB/trunk/lib/irb/ext/history.rb	2010-10-08 10:59:24 UTC (rev 4685)
+++ DietRB/trunk/lib/irb/ext/history.rb	2010-10-08 10:59:33 UTC (rev 4686)
@@ -26,7 +26,8 @@
     end
     
     def to_a
-      File.read(self.class.file).split("\n")
+      file = self.class.file
+      File.exist?(file) ? File.read(file).split("\n") : []
     end
     
     def clear!

Modified: DietRB/trunk/spec/history_spec.rb
===================================================================
--- DietRB/trunk/spec/history_spec.rb	2010-10-08 10:59:24 UTC (rev 4685)
+++ DietRB/trunk/spec/history_spec.rb	2010-10-08 10:59:33 UTC (rev 4686)
@@ -34,6 +34,18 @@
     @history.to_a.should == ["puts :ok", "foo(x)"]
   end
   
+  it "returns an empty array if the history file doesn't exist yet and create it once input is added" do
+    @file.close
+    FileUtils.rm(@file.path)
+    
+    @history.to_a.should == []
+    File.should.not.exist @file.path
+    
+    @history.input "puts :ok"
+    File.should.exist @file.path
+    @history.to_a.should == ["puts :ok"]
+  end
+  
   it "stores the contents of the history file in Readline::HISTORY once" do
     Readline::HISTORY.clear
     
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/4f18b9c9/attachment-0001.html>


More information about the macruby-changes mailing list