[macruby-changes] [4736] DietRB/trunk

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 8 04:07:21 PDT 2010


Revision: 4736
          http://trac.macosforge.org/projects/ruby/changeset/4736
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:07:20 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Start on the tty spec

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

Modified Paths:
--------------
    DietRB/trunk/lib/irb/driver/tty.rb
    DietRB/trunk/spec/driver/tty_spec.rb
    DietRB/trunk/spec/driver_spec.rb
    DietRB/trunk/spec/spec_helper.rb

Modified: DietRB/trunk/lib/irb/driver/tty.rb
===================================================================
--- DietRB/trunk/lib/irb/driver/tty.rb	2010-10-08 11:07:09 UTC (rev 4735)
+++ DietRB/trunk/lib/irb/driver/tty.rb	2010-10-08 11:07:20 UTC (rev 4736)
@@ -23,15 +23,6 @@
         ""
       end
       
-      def puts(*args)
-        @output.puts(*args)
-      end
-      
-      def print(*args)
-        @output.print(*args)
-        @output.flush
-      end
-      
       def run(context)
         ensure_output_redirector do
           while line = consume(context)

Modified: DietRB/trunk/spec/driver/tty_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/tty_spec.rb	2010-10-08 11:07:09 UTC (rev 4735)
+++ DietRB/trunk/spec/driver/tty_spec.rb	2010-10-08 11:07:20 UTC (rev 4736)
@@ -1,5 +1,27 @@
 require File.expand_path('../../spec_helper', __FILE__)
+require 'irb/driver/tty'
 
 describe "IRB::Driver::TTY" do
+  before do
+    @driver = IRB::Driver::TTY.new(InputStub.new, OutputStub.new)
+    @context = IRB::Context.new(Object.new)
+  end
   
+  it "prints the prompt and reads a line of input" do
+    @driver.input.stub_input "calzone"
+    @driver.readline(@context).should == "calzone"
+    @driver.output.printed.should == @context.prompt
+  end
+  
+  it "consumes input" do
+    @driver.input.stub_input "calzone"
+    @driver.consume(@context).should == "calzone"
+  end
+  
+  it "clears the context buffer if an Interrupt signal is received while consuming input" do
+    @context.process_line("class A")
+    def @driver.readline(_); raise Interrupt; end
+    @driver.consume(@context).should == ""
+    @context.source.to_s.should == ""
+  end
 end
\ No newline at end of file

Modified: DietRB/trunk/spec/driver_spec.rb
===================================================================
--- DietRB/trunk/spec/driver_spec.rb	2010-10-08 11:07:09 UTC (rev 4735)
+++ DietRB/trunk/spec/driver_spec.rb	2010-10-08 11:07:20 UTC (rev 4736)
@@ -31,7 +31,7 @@
 describe "IRB::Driver::OutputRedirector" do
   before :each do
     @driver = StubDriver.new
-    @driver.output = CaptureIO.new
+    @driver.output = OutputStub.new
     IRB::Driver.current = @driver
     
     @redirector = IRB::Driver::OutputRedirector.new

Modified: DietRB/trunk/spec/spec_helper.rb
===================================================================
--- DietRB/trunk/spec/spec_helper.rb	2010-10-08 11:07:09 UTC (rev 4735)
+++ DietRB/trunk/spec/spec_helper.rb	2010-10-08 11:07:20 UTC (rev 4736)
@@ -16,7 +16,22 @@
 
 require 'irb'
 
-class CaptureIO
+class InputStub
+  def stub_input(*input)
+    @input = input
+  end
+  
+  def readline(prompt)
+    # print prompt
+    @input.shift
+  end
+  
+  def gets
+    @input.shift
+  end
+end
+
+class OutputStub
   def printed
     @printed ||= ''
   end
@@ -32,13 +47,4 @@
   def puts(*args)
     print "#{args.join("\n")}\n"
   end
-  
-  def stub_input(*input)
-    @input = input
-  end
-  
-  def readline(prompt)
-    print prompt
-    @input.shift
-  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/eac5524e/attachment.html>


More information about the macruby-changes mailing list