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

fixing tests.. still some places broken

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