Permalink
Browse files

Start on the tty spec

  • Loading branch information...
alloy committed Jul 14, 2010
1 parent 0344d6c commit b1f3607f8eea478fa46b620b9d48149a6e9009d0
Showing with 39 additions and 20 deletions.
  1. +0 −9 lib/irb/driver/tty.rb
  2. +22 −0 spec/driver/tty_spec.rb
  3. +1 −1 spec/driver_spec.rb
  4. +16 −10 spec/spec_helper.rb
View
@@ -23,15 +23,6 @@ def consume(context)
""
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)
View
@@ -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
View
@@ -31,7 +31,7 @@ def output
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
View
@@ -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 print(string)
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

0 comments on commit b1f3607

Please sign in to comment.