Commit b68d61df authored by Carson McDonald's avatar Carson McDonald Committed by Fabio Pelosin

Add more Spec command test coverage

Change STDIN to $stdin so it can be reassigned
Use UI.puts instead of print
Add test coverage for Spec#choose_from_array
Fix off by one issue in Spec#choose_from_array

Closes #1675
parent 65ca1aae
......@@ -300,10 +300,10 @@ module Pod
UI.puts "#{ index + 1 }: #{ item }"
end
print message
UI.puts message
index = STDIN.gets.chomp.to_i - 1
if index < 0 || index > array.count
index = $stdin.gets.chomp.to_i - 1
if index < 0 || index > array.count - 1
raise Informative, "#{ index + 1 } is invalid [1-#{ array.count }]"
else
index
......
......@@ -212,9 +212,10 @@ module Pod
end
it "cats the first podspec from all podspecs" do
STDIN = StringIO.new("1\n", 'r')
$stdin = StringIO.new("1\n", 'r')
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
......@@ -229,13 +230,13 @@ module Pod
describe "Private helpers" do
describe "#get_path_of_spec" do
before do
# TODO Use class methods
@sut = Command::Spec.new(CLAide::ARGV.new([]))
before do
# TODO Use class methods
@sut = Command::Spec.new(CLAide::ARGV.new([]))
end
end
describe "#get_path_of_spec" do
it "returns the path of the specification with the given name" do
path = @sut.send(:get_path_of_spec, 'AFNetworking')
......@@ -244,6 +245,26 @@ module Pod
end
describe "#choose_from_array" do
it "should return a valid index for the given array" do
$stdin = StringIO.new("1\n", 'r')
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')
lambda { @sut.send(:choose_from_array, ['item1', 'item2', 'item3'], 'A message') }.should.raise Pod::Informative
$stdin = StringIO.new("0\n", 'r')
lambda { @sut.send(:choose_from_array, ['item1', 'item2', 'item3'], 'A message') }.should.raise Pod::Informative
$stdin = STDIN
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