1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Match Hash implementation of fetch

An optional block can be passed to `fetch` that will be called in the
event that the variable is not set.

    fetch(:var) { fail 'var not found' }
This commit is contained in:
seenmyfate 2013-08-09 14:15:50 +01:00
parent 9fd628eab8
commit ca81639e1d
2 changed files with 16 additions and 2 deletions

View file

@ -6,8 +6,8 @@ module Capistrano
env.configure_backend
end
def fetch(key, default=nil)
env.fetch(key, default)
def fetch(key, default=nil, &block)
env.fetch(key, default, &block)
end
def any?(key)

View file

@ -165,6 +165,20 @@ describe Capistrano::DSL do
end
end
context 'with a block' do
context 'when the variables is defined' do
it 'returns the variable' do
expect(dsl.fetch(:scm) { :svn }).to eq :git
end
end
context 'when the variables is undefined' do
it 'calls the block' do
expect(dsl.fetch(:source_control) { :svn }).to eq :svn
end
end
end
end
describe 'asking for a variable' do