Permalink
Browse files

Add specs for irb/io/readline

  • Loading branch information...
alloy committed Jul 4, 2010
1 parent 3641cae commit 44334b2ac8f6aef2764af0bcb05a011ae54611f8
Showing with 33 additions and 0 deletions.
  1. +2 −0 lib/irb/io/readline.rb
  2. +31 −0 spec/io/readline_spec.rb
View
@@ -3,6 +3,8 @@
module IRB
module IO
class Readline
+ attr_reader :input, :output
+
def initialize(input = $stdin, output = $stdout)
::Readline.input = @input = input
::Readline.output = @output = output
View
@@ -0,0 +1,31 @@
+require File.expand_path('../../spec_helper', __FILE__)
+require 'tempfile'
+
+describe "IRB::IO::Readline" do
+ before do
+ @output = File.new("/tmp/dietrb-output-#{Time.now.to_i}", 'w+')
+ @io = IRB::IO::Readline.new($stdin, @output)
+ end
+
+ after do
+ @output.close
+ File.unlink(@output.path)
+ end
+
+ it "returns the input and output objects" do
+ @io.input.should == $stdin
+ @io.output.should == @output
+ end
+
+ it "receives a prompt and should save the history" do
+ def Readline.readline(prompt, save_history); @received = [prompt, save_history]; end
+ @io.readline('PROMPT')
+ Readline.instance_variable_get(:@received).should == ['PROMPT', true]
+ end
+
+ it "forwards #puts to the output object" do
+ @io.puts("chunky banana")
+ @output.rewind
+ @output.read.should == "chunky banana\n"
+ end
+end

0 comments on commit 44334b2

Please sign in to comment.