/spec/driver/readline_spec.rb

http://github.com/alloy/dietrb · Ruby · 70 lines · 56 code · 14 blank · 0 comment · 6 complexity · ff68c688af296195ba896ff269692c4b MD5 · raw file

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