[macruby-changes] [4738] DietRB/trunk/spec

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


Revision: 4738
          http://trac.macosforge.org/projects/ruby/changeset/4738
Author:   eloy.de.enige at gmail.com
Date:     2010-10-08 04:07:40 -0700 (Fri, 08 Oct 2010)
Log Message:
-----------
Add readline driver specs

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

Modified Paths:
--------------
    DietRB/trunk/spec/spec_helper.rb

Added Paths:
-----------
    DietRB/trunk/spec/driver/readline_spec.rb

Added: DietRB/trunk/spec/driver/readline_spec.rb
===================================================================
--- DietRB/trunk/spec/driver/readline_spec.rb	                        (rev 0)
+++ DietRB/trunk/spec/driver/readline_spec.rb	2010-10-08 11:07:40 UTC (rev 4738)
@@ -0,0 +1,75 @@
+require File.expand_path("../../spec_helper", __FILE__)
+require "irb/driver/readline"
+
+module Readline
+  extend InputStubMixin
+  extend OutputStubMixin
+
+  def self.input=(input)
+    @given_input = input
+  end
+
+  def self.given_input
+    @given_input
+  end
+
+  def self.output=(output)
+    @given_output = output
+  end
+
+  def self.given_output
+    @given_output
+  end
+
+  def self.use_history=(use_history)
+    @use_history = use_history
+  end
+
+  def self.use_history
+    @use_history
+  end
+
+  def self.readline(prompt, use_history)
+    @use_history = use_history
+    print prompt
+    @input.shift
+  end
+end
+
+describe "IRB::Driver::Readline" do
+  before do
+    @driver = IRB::Driver::Readline.new(InputStub.new, OutputStub.new)
+    @context = IRB::Context.new(Object.new)
+  end
+
+  it "is a subclass of IRB::Driver::TTY" do
+    IRB::Driver::Readline.superclass.should == IRB::Driver::TTY
+  end
+
+  it "assigns the given input and output to the Readline module" do
+    Readline.given_input.should == @driver.input
+    Readline.given_output.should == @driver.output
+  end
+
+  it "assigns a completion object" do
+    Readline.completion_proc.class.should == IRB::Completion
+  end
+
+  it "reads a line through the Readline module" do
+    Readline.stub_input "nom nom nom"
+    @driver.readline(@context).should == "nom nom nom"
+  end
+
+  it "assigns the context as the current context to the completion object" do
+    Readline.stub_input "nom nom nom"
+    @driver.readline(@context)
+    Readline.completion_proc.context.should == @context
+  end
+
+  it "tells the Readline module to use the history" do
+    Readline.use_history = false
+    Readline.stub_input "nom nom nom"
+    @driver.readline(@context)
+    Readline.use_history.should == true
+  end
+end

Modified: DietRB/trunk/spec/spec_helper.rb
===================================================================
--- DietRB/trunk/spec/spec_helper.rb	2010-10-08 11:07:32 UTC (rev 4737)
+++ DietRB/trunk/spec/spec_helper.rb	2010-10-08 11:07:40 UTC (rev 4738)
@@ -16,7 +16,7 @@
 
 require 'irb'
 
-class InputStub
+module InputStubMixin
   def stub_input(*input)
     @input = input
   end
@@ -31,7 +31,11 @@
   end
 end
 
-class OutputStub
+class InputStub
+  include InputStubMixin
+end
+
+module OutputStubMixin
   def printed
     @printed ||= ''
   end
@@ -47,4 +51,8 @@
   def puts(*args)
     print "#{args.join("\n")}\n"
   end
-end
\ No newline at end of file
+end
+
+class OutputStub
+  include OutputStubMixin
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101008/8cf3d894/attachment.html>


More information about the macruby-changes mailing list