Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
2baab807
Commit
2baab807
authored
May 06, 2015
by
Samuel E. Giddins
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3523 from CocoaPods/seg-config-with-changes
[Config] Add #with_changes
parents
6601e251
07e7dd1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
config.rb
lib/cocoapods/config.rb
+15
-0
config_spec.rb
spec/unit/config_spec.rb
+42
-0
No files found.
lib/cocoapods/config.rb
View file @
2baab807
...
...
@@ -24,6 +24,21 @@ module Pod
:cache_root
=>
Pathname
.
new
(
Dir
.
home
)
+
'Library/Caches/CocoaPods'
,
}
# Applies the given changes to the config for the duration of the given
# block.
#
def
with_changes
(
changes
)
old
=
{}
changes
.
keys
.
each
do
|
key
|
key
=
key
.
to_sym
old
[
key
]
=
send
(
key
)
if
respond_to?
(
key
)
end
configure_with
(
changes
)
yield
if
block_given?
ensure
configure_with
(
old
)
end
public
#-------------------------------------------------------------------------#
...
...
spec/unit/config_spec.rb
View file @
2baab807
...
...
@@ -45,6 +45,48 @@ module Pod
#-------------------------------------------------------------------------#
describe
'#with_changes'
do
it
'doesnt raise when using an unknown key'
do
should
.
not
.
raise
{
@config
.
with_changes
(
:foo_bar
=>
false
)
}
end
it
'uses the new value inside the block'
do
@config
.
verbose
=
true
called
=
false
@config
.
with_changes
(
:verbose
=>
false
)
do
@config
.
should
.
not
.
be
.
verbose
called
=
true
end
called
.
should
.
be
.
true
end
it
'reverts to the previous value after the block'
do
@config
.
verbose
=
true
@config
.
with_changes
(
:verbose
=>
false
)
@config
.
should
.
be
.
verbose
end
it
'reverts to the previous value even when an exception is raised'
do
@config
.
verbose
=
true
should
.
raise
do
@config
.
with_changes
(
:verbose
=>
false
)
do
raise
'foo'
end
end
@config
.
should
.
be
.
verbose
end
it
'returns the return value of the block'
do
@config
.
with_changes
({})
do
'foo'
end
.
should
==
'foo'
@config
.
with_changes
({}).
should
.
be
.
nil
end
end
#-------------------------------------------------------------------------#
describe
'Paths'
do
it
'returns the working directory as the installation root if a Podfile can be found'
do
Dir
.
chdir
(
temporary_directory
)
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment