Commit e0d9e753 authored by Carson McDonald's avatar Carson McDonald

Replace use of $stdin.gets with UI.gets

parent 5f506b49
......@@ -302,7 +302,7 @@ module Pod
UI.puts message
index = $stdin.gets.chomp.to_i - 1
index = UI.gets.chomp.to_i - 1
if index < 0 || index > array.count - 1
raise Informative, "#{ index + 1 } is invalid [1-#{ array.count }]"
else
......
......@@ -240,6 +240,12 @@ module Pod
STDOUT.print(message) unless config.silent?
end
# gets input from $stdin
#
def gets
$stdin.gets
end
# Stores important warning to the user optionally followed by actions
# that the user should take. To print them use {#print_warnings}.
#
......
......@@ -212,10 +212,9 @@ module Pod
end
it "cats the first podspec from all podspecs" do
$stdin = StringIO.new("1\n", 'r')
UI.next_input = "1\n"
run_command('spec', 'cat', '--show-all', 'AFNetworking')
UI.output.should.include fixture('spec-repos/master/AFNetworking/1.2.0/AFNetworking.podspec').read
$stdin = STDIN
end
end
......@@ -248,19 +247,17 @@ module Pod
describe "#choose_from_array" do
it "should return a valid index for the given array" do
$stdin = StringIO.new("1\n", 'r')
UI.next_input = "1\n"
index = @sut.send(:choose_from_array, ['item1', 'item2', 'item3'], 'A message')
UI.output.should.include "1: item1\n2: item2\n3: item3\nA message\n"
index.should == 0
$stdin = STDIN
end
it "should raise when the index is out of bounds" do
$stdin = StringIO.new("4\n", 'r')
UI.next_input = "4\n"
lambda { @sut.send(:choose_from_array, ['item1', 'item2', 'item3'], 'A message') }.should.raise Pod::Informative
$stdin = StringIO.new("0\n", 'r')
UI.next_input = "0\n"
lambda { @sut.send(:choose_from_array, ['item1', 'item2', 'item3'], 'A message') }.should.raise Pod::Informative
$stdin = STDIN
end
end
......
......@@ -9,10 +9,12 @@ module Pod
module UI
@output = ''
@warnings = ''
@next_input = ''
class << self
attr_accessor :output
attr_accessor :warnings
attr_accessor :next_input
def puts(message = '')
@output << "#{message}\n"
......@@ -25,6 +27,10 @@ module Pod
def print(message)
@output << message
end
def gets
@next_input
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment