/spec/driver/readline_spec.rb
Ruby | 70 lines | 56 code | 14 blank | 0 comment | 6 complexity | ff68c688af296195ba896ff269692c4b MD5 | raw file
1require File.expand_path("../../spec_helper", __FILE__) 2require "irb/driver/readline" 3 4module Readline 5 extend InputStubMixin 6 extend OutputStubMixin 7 8 def self.input=(input) 9 @given_input = input 10 end 11 12 def self.given_input 13 @given_input 14 end 15 16 def self.output=(output) 17 @given_output = output 18 end 19 20 def self.given_output 21 @given_output 22 end 23 24 def self.use_history=(use_history) 25 @use_history = use_history 26 end 27 28 def self.use_history 29 @use_history 30 end 31 32 def self.readline(prompt, use_history) 33 @use_history = use_history 34 print prompt 35 @input.shift 36 end 37end 38 39describe "IRB::Driver::Readline" do 40 before do 41 @driver = IRB::Driver::Readline.new(InputStub.new, OutputStub.new) 42 @context = IRB::Context.new(Object.new) 43 @driver.context_stack << @context 44 end 45 46 it "is a subclass of IRB::Driver::TTY" do 47 IRB::Driver::Readline.superclass.should == IRB::Driver::TTY 48 end 49 50 it "assigns the given input and output to the Readline module" do 51 Readline.given_input.should == @driver.input 52 Readline.given_output.should == @driver.output 53 end 54 55 it "assigns a completion object" do 56 Readline.completion_proc.class.should == IRB::Completion 57 end 58 59 it "reads a line through the Readline module" do 60 Readline.stub_input "nom nom nom" 61 @driver.readline.should == "nom nom nom" 62 end 63 64 it "tells the Readline module to use the history" do 65 Readline.use_history = false 66 Readline.stub_input "nom nom nom" 67 @driver.readline 68 Readline.use_history.should == true 69 end 70end