class InputFaker def initialize(strings) @strings = Array(strings) end def gets next_string = @strings.shift # Uncomment the following line if you'd like to see the faked $stdin#gets # puts "(DEBUG) Faking #gets with: #{next_string}" next_string end def noecho @strings.shift end def tty? true end def self.with_fake_input(strings) $stdin = new(strings) yield ensure $stdin = STDIN end end