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 ...@@ -300,10 +300,10 @@ module Pod
UI.puts "#{ index + 1 }: #{ item }" UI.puts "#{ index + 1 }: #{ item }"
end end
print message UI.puts message
index = STDIN.gets.chomp.to_i - 1 index = $stdin.gets.chomp.to_i - 1
if index < 0 || index > array.count if index < 0 || index > array.count - 1
raise Informative, "#{ index + 1 } is invalid [1-#{ array.count }]" raise Informative, "#{ index + 1 } is invalid [1-#{ array.count }]"
else else
index index
......
...@@ -212,9 +212,10 @@ module Pod ...@@ -212,9 +212,10 @@ module Pod
end end
it "cats the first podspec from all podspecs" do 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') run_command('spec', 'cat', '--show-all', 'AFNetworking')
UI.output.should.include fixture('spec-repos/master/AFNetworking/1.2.0/AFNetworking.podspec').read UI.output.should.include fixture('spec-repos/master/AFNetworking/1.2.0/AFNetworking.podspec').read
$stdin = STDIN
end end
end end
...@@ -229,13 +230,13 @@ module Pod ...@@ -229,13 +230,13 @@ module Pod
describe "Private helpers" do 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 end
# TODO Use class methods
@sut = Command::Spec.new(CLAide::ARGV.new([]))
end describe "#get_path_of_spec" do
it "returns the path of the specification with the given name" do it "returns the path of the specification with the given name" do
path = @sut.send(:get_path_of_spec, 'AFNetworking') path = @sut.send(:get_path_of_spec, 'AFNetworking')
...@@ -244,6 +245,26 @@ module Pod ...@@ -244,6 +245,26 @@ module Pod
end 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 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