Commit 7ef32e9e authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #2845 from CocoaPods/issue/2845

[Unit Tests] Add specs for `Pod::UI`
parents 8bd9839a 4dd7b38b
......@@ -193,20 +193,16 @@ module Pod
#
def labeled(label, value, justification = 12)
if value
title = "- #{label}:".ljust(justification)
output = begin
if value.is_a?(Array)
lines = [wrap_string(title, self.indentation_level)]
value.each do |v|
lines << wrap_string("- #{v}", self.indentation_level + 2)
end
lines.join("\n")
else
wrap_string(title + "#{value}", self.indentation_level)
end + "\n"
title = "- #{label}:"
if value.is_a?(Array)
lines = [wrap_string(title, self.indentation_level)]
value.each do |v|
lines << wrap_string("- #{v}", self.indentation_level + 2)
end
puts lines.join("\n")
else
puts wrap_string(title.ljust(justification) + "#{value}", self.indentation_level)
end
puts output
output
end
end
......@@ -291,7 +287,7 @@ module Pod
#
def wrap_string(string, indent = 0)
if disable_wrap
string
(' ' * indent) + string
else
first_space = ' ' * indent
indented = CLAide::Command::Banner::TextWrapper.wrap_with_indent(string, indent, 9999)
......
require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe UI do
describe '#section' do
# TODO
end
describe '#titled_section' do
# TODO
end
describe '#title' do
# TODO
end
describe '#message' do
# TODO
end
describe '#info' do
# TODO
end
describe '#notice' do
# TODO
end
describe '#labeled' do
it 'prints nothing if value is nil' do
UI.labeled('label', nil)
UI.output.should == ''
end
it 'prints label and value on one line if value is not an array' do
UI.labeled('label', 'value', 12)
UI.output.should == "- label: value\n"
end
it 'justifies the label' do
UI.labeled('label', 'value', 30)
UI.output.should == "- label:#{' ' * 22}value\n" # 22 = 30 - ('- label:'.length)
end
it 'justifies the label with default justification' do
UI.labeled('label', 'value') # defaults to 12
UI.output.should == "- label: value\n"
end
it 'uses the indentation level' do
UI.indentation_level = 10
UI.labeled('label', 'value') # defaults to 12
UI.output.should == "#{' ' * 10}- label: value\n"
end
it 'prints array values on separate lines, no indentation level' do
UI.labeled('label', %w(value1), 12)
UI.output.should == "- label:\n - value1\n"
end
it 'prints array values (1) on separate lines with indentation level' do
UI.indentation_level = 10
UI.labeled('label', %w(value1), 12)
UI.output.should == "#{' ' * 10}- label:\n#{' ' * 12}- value1\n"
end
it 'prints array values (3) on separate lines with indentation level' do
UI.indentation_level = 10
values = %w(value1 value2 value3)
UI.labeled('label', values, 12)
UI.output.should == "#{' ' * 10}- label:\n" + values.map { |v| "#{' ' * 12}- #{v}\n" }.join
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