[macruby-changes] [4605] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 03:47:31 PDT 2010


Revision: 4605
          http://trac.macosforge.org/projects/ruby/changeset/4605
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 03:47:30 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Refactored processing input into a separate method.

From: Eloy Duran <eloy.de.enige at gmail.com>

Modified Paths:
--------------
    DietRB/trunk/lib/irb/context.rb
    DietRB/trunk/spec/context_spec.rb

Modified: DietRB/trunk/lib/irb/context.rb
===================================================================
--- DietRB/trunk/lib/irb/context.rb	2010-10-08 10:47:21 UTC (rev 4604)
+++ DietRB/trunk/lib/irb/context.rb	2010-10-08 10:47:30 UTC (rev 4605)
@@ -21,14 +21,18 @@
     
     def run
       while line = readline
-        @source << line
-        if @source.valid?
-          evaluate(@source)
-          clear_buffer
-        end
+        process_line(line)
       end
     end
     
+    def process_line(line)
+      @source << line
+      if @source.valid?
+        evaluate(@source)
+        clear_buffer
+      end
+    end
+    
     PROMPT = "irb(%s):%03d:%d> "
     
     def prompt

Modified: DietRB/trunk/spec/context_spec.rb
===================================================================
--- DietRB/trunk/spec/context_spec.rb	2010-10-08 10:47:21 UTC (rev 4604)
+++ DietRB/trunk/spec/context_spec.rb	2010-10-08 10:47:30 UTC (rev 4605)
@@ -75,19 +75,27 @@
     Readline.received.should == ["irb(main):001:0> ", true]
   end
   
-  it "adds the received code, as long as available, to the source buffer while running" do
-    Readline.stub_input("def foo", "p :ok")
+  it "processes the output" do
+    Readline.stub_input("def foo")
+    def @context.process_line(line); @received = line; end
     @context.run
+    @context.instance_variable_get(:@received).should == "def foo"
+  end
+  
+  it "adds the received code to the source buffer" do
+    @context.process_line("def foo")
+    @context.process_line("p :ok")
     @context.source.to_s.should == "def foo\np :ok"
   end
   
   it "evaluates the buffered source once it's a valid code block" do
-    Readline.stub_input("def foo", ":ok", "end; p foo")
-    def @context.evaluate(source)
-      @evaled_source = source
-    end
-    @context.run
-    source = @context.instance_variable_get(:@evaled_source)
+    def @context.evaluate(source); @evaled = source; end
+    
+    @context.process_line("def foo")
+    @context.process_line(":ok")
+    @context.process_line("end; p foo")
+    
+    source = @context.instance_variable_get(:@evaled)
     source.to_s.should == "def foo\n:ok\nend; p foo"
   end
 end
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/7825c01c/attachment-0001.html>


More information about the macruby-changes mailing list