Commit 7d7a92b6 authored by Marin Usalj's avatar Marin Usalj

fixing tests.. still some places broken

parent c7d4cb42
...@@ -42,6 +42,15 @@ module Pod ...@@ -42,6 +42,15 @@ module Pod
class NoKeyError < ArgumentError; end class NoKeyError < ArgumentError; end
# @!group Singleton
# @return [Config] the current config instance creating one if needed.
#
def self.instance
@instance ||= new
end
def get_setting(keypath) def get_setting(keypath)
value = global_config[keypath] || get_environment(keypath) || DEFAULTS[keypath.to_sym] value = global_config[keypath] || get_environment(keypath) || DEFAULTS[keypath.to_sym]
if value.nil? if value.nil?
......
...@@ -36,7 +36,10 @@ module Pod ...@@ -36,7 +36,10 @@ module Pod
autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer' autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator' autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
include Config::Mixin # include Config::Mixin
def config
Config::ConfigManager.instance
end
# @return [Sandbox] The sandbox where the Pods should be installed. # @return [Sandbox] The sandbox where the Pods should be installed.
# #
......
...@@ -17,8 +17,6 @@ module Pod ...@@ -17,8 +17,6 @@ module Pod
class << self class << self
include Config::Mixin
attr_accessor :indentation_level attr_accessor :indentation_level
attr_accessor :title_level attr_accessor :title_level
attr_accessor :warnings attr_accessor :warnings
...@@ -40,8 +38,9 @@ module Pod ...@@ -40,8 +38,9 @@ module Pod
# @todo Refactor to title (for always visible titles like search) # @todo Refactor to title (for always visible titles like search)
# and sections (titles that represent collapsible sections). # and sections (titles that represent collapsible sections).
# #
def section(title, verbose_prefix = '', relative_indentation = 0) def section(title, verbose_prefix = '', relative_indentation = 0)
if config.verbose? if verbose?
title(title, verbose_prefix, relative_indentation) title(title, verbose_prefix, relative_indentation)
elsif title_level < 1 elsif title_level < 1
puts title puts title
...@@ -62,7 +61,7 @@ module Pod ...@@ -62,7 +61,7 @@ module Pod
def titled_section(title, options = {}) def titled_section(title, options = {})
relative_indentation = options[:relative_indentation] || 0 relative_indentation = options[:relative_indentation] || 0
verbose_prefix = options[:verbose_prefix] || '' verbose_prefix = options[:verbose_prefix] || ''
if config.verbose? if verbose?
title(title, verbose_prefix, relative_indentation) title(title, verbose_prefix, relative_indentation)
else else
puts title puts title
...@@ -81,7 +80,7 @@ module Pod ...@@ -81,7 +80,7 @@ module Pod
if(@treat_titles_as_messages) if(@treat_titles_as_messages)
message(title, verbose_prefix) message(title, verbose_prefix)
else else
title = verbose_prefix + title if config.verbose? title = verbose_prefix + title if verbose?
title = "\n#{title}" if @title_level < 2 title = "\n#{title}" if @title_level < 2
if (color = @title_colors[@title_level]) if (color = @title_colors[@title_level])
title = title.send(color) title = title.send(color)
...@@ -106,8 +105,8 @@ module Pod ...@@ -106,8 +105,8 @@ module Pod
# @todo Clean interface. # @todo Clean interface.
# #
def message(message, verbose_prefix = '', relative_indentation = 2) def message(message, verbose_prefix = '', relative_indentation = 2)
message = verbose_prefix + message if config.verbose? message = verbose_prefix + message if verbose?
puts_indented message if config.verbose? puts_indented message if verbose?
self.indentation_level += relative_indentation self.indentation_level += relative_indentation
yield if block_given? yield if block_given?
...@@ -121,7 +120,7 @@ module Pod ...@@ -121,7 +120,7 @@ module Pod
# Any title printed in the optional block is treated as a message. # Any title printed in the optional block is treated as a message.
# #
def info(message) def info(message)
indentation = config.verbose? ? self.indentation_level : 0 indentation = verbose? ? self.indentation_level : 0
indented = wrap_string(message, " " * indentation) indented = wrap_string(message, " " * indentation)
puts(indented) puts(indented)
...@@ -214,7 +213,7 @@ module Pod ...@@ -214,7 +213,7 @@ module Pod
def print_warnings def print_warnings
STDOUT.flush STDOUT.flush
warnings.each do |warning| warnings.each do |warning|
next if warning[:verbose_only] && !config.verbose? next if warning[:verbose_only] && !verbose?
STDERR.puts("\n[!] #{warning[:message]}".yellow) STDERR.puts("\n[!] #{warning[:message]}".yellow)
warning[:actions].each do |action| warning[:actions].each do |action|
indented = wrap_string(action, " - ") indented = wrap_string(action, " - ")
...@@ -231,13 +230,13 @@ module Pod ...@@ -231,13 +230,13 @@ module Pod
# prints a message followed by a new line unless config is silent. # prints a message followed by a new line unless config is silent.
# #
def puts(message = '') def puts(message = '')
STDOUT.puts(message) unless config.silent? STDOUT.puts(message) unless silent?
end end
# prints a message followed by a new line unless config is silent. # prints a message followed by a new line unless config is silent.
# #
def print(message) def print(message)
STDOUT.print(message) unless config.silent? STDOUT.print(message) unless silent?
end end
# Stores important warning to the user optionally followed by actions # Stores important warning to the user optionally followed by actions
...@@ -279,6 +278,18 @@ module Pod ...@@ -279,6 +278,18 @@ module Pod
txt.strip.gsub(/(.{1,#{width}})( +|$)\n?|(.{#{width}})/, indent + "\\1\\3\n") txt.strip.gsub(/(.{1,#{width}})( +|$)\n?|(.{#{width}})/, indent + "\\1\\3\n")
end end
end end
def config
Config::ConfigManager.instance
end
def verbose?
Config::ConfigManager.instance.verbose? && !silent?
end
def silent?
Config::ConfigManager.instance.silent?
end
end end
end end
UI = UserInterface UI = UserInterface
......
...@@ -10,94 +10,91 @@ module Pod ...@@ -10,94 +10,91 @@ module Pod
@config_file_path = temporary_directory + 'config.yaml' @config_file_path = temporary_directory + 'config.yaml'
before do before do
@sut = Config::ConfigManager.new @subject = Config::ConfigManager.instance
@sut.stubs(:home_dir).returns(temporary_directory) @subject.stubs(:home_dir).returns(temporary_directory)
end end
it "creates a global config file if one didn't exist" do it "creates a global config file if one didn't exist" do
FileUtils.rm_rf(@config_file_path) FileUtils.rm_rf(@config_file_path)
@sut.set_global('verbose', 'true') @subject.set_global('verbose', 'true')
@config_file_path.should.exist @config_file_path.should.exist
end end
it "stores a global setting" do it "stores a global setting" do
@sut.set_global('verbose', 'true') @subject.set_global('verbose', 'true')
yaml = YAML.load_file(@config_file_path) yaml = YAML.load_file(@config_file_path)
yaml['verbose'].should == true yaml['verbose'].should == true
end end
it "preserves the existing settings of the configuration file" do it "preserves the existing settings of the configuration file" do
@sut.set_global('user_name', 'Super Marin') @subject.set_global('silent', 'true')
@sut.set_global('verbose', 'true') @subject.set_global('verbose', 'true')
yaml = YAML.load_file(@config_file_path) yaml = YAML.load_file(@config_file_path)
yaml['user_name'].should == 'Super Marin' yaml['silent'].should == true
end end
xit "allows to store a development pod" do xit "allows to store a development pod" do
@sut.set_global('development.ObjectiveSugar', '~/code/OS') @subject.set_global('development.ObjectiveSugar', '~/code/OS')
yaml = YAML.load_file(@config_file_path) yaml = YAML.load_file(@config_file_path)
yaml['development.ObjectiveSugar'].should == '~/code/OS' yaml['development.ObjectiveSugar'].should == '~/code/OS'
end end
it "returns a globally decided setting" do it "returns a globally decided setting" do
@sut.set_global('user_name', 'Super Marin') @subject.set_global('user_name', 'Super Marin')
@sut.get_setting('user_name').should == 'Super Marin' @subject.get_setting('user_name').should == 'Super Marin'
end end
it "verbose by default is false" do it "verbose by default is false" do
@sut.should.not.be.verbose @subject.should.not.be.verbose
end end
it "silent by default is false" do it "silent by default is false" do
@sut.should.not.be.silent @subject.should.not.be.silent
end end
it "skips repo update by default is false" do it "skips repo update by default is false" do
@sut.should.not.skip_repo_update @subject.should.not.skip_repo_update
end end
it "clean by default is true" do it "clean by default is true" do
@sut.should.be.clean @subject.should.be.clean
end end
it "integrate_targets by default is true" do it "integrate_targets by default is true" do
@sut.should.integrate_targets @subject.should.integrate_targets
end end
it "new_version_message by default is true" do it "new_version_message by default is true" do
@sut.should.new_version_message @subject.should.new_version_message
end end
it "cache_root returns the cache root by default" do it "cache_root returns the cache root by default" do
@sut.cache_root.to_s.should.include('Library/Caches/CocoaPods') @subject.cache_root.to_s.should.include('Library/Caches/CocoaPods')
end end
it "max_cache_size is 500 MB by default" do it "max_cache_size is 500 MB by default" do
@sut.max_cache_size.should == 500 @subject.max_cache_size.should == 500
end end
it "aggressive_cache is false by default" do it "aggressive_cache is false by default" do
@sut.should.not.aggressive_cache @subject.should.not.aggressive_cache
end end
it "raises if there is an attempt to access an unrecognized attribute" do it "raises if there is an attempt to access an unrecognized attribute" do
should.raise Config::ConfigManager::NoKeyError do should.raise Config::ConfigManager::NoKeyError do
@sut.get_setting('idafjaeilfjoasijfopasdj') @subject.get_setting('idafjaeilfjoasijfopasdj')
end end
end end
it "can accept aggressive cache from ENV" do it "can accept aggressive cache from ENV" do
ENV.stubs(:[]).returns('TRUE') ENV.stubs(:[]).returns('TRUE')
@sut.get_setting('aggressive_cache').should == true @subject.get_setting('aggressive_cache').should == true
end end
xit "it converts string boolean values"
xit "it support keypath"
# key.keypath = 'my value'
end end
xit "writes local repos for each project" do xit "writes local repos for each project" do
@sut.set_local('verbose', 'true') @subject.set_local('verbose', 'true')
yaml['verbose'].should == true yaml['verbose'].should == true
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