mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Merge pull request #1177 from mikz/remove-question-env
remove Question dependency on env
This commit is contained in:
commit
8ae0b7eae1
4 changed files with 15 additions and 22 deletions
|
@ -15,7 +15,7 @@ module Capistrano
|
||||||
end
|
end
|
||||||
|
|
||||||
def ask(key, default=nil, options={})
|
def ask(key, default=nil, options={})
|
||||||
question = Question.new(self, key, default, options)
|
question = Question.new(key, default, options)
|
||||||
set(key, question)
|
set(key, question)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,22 @@ module Capistrano
|
||||||
class Configuration
|
class Configuration
|
||||||
class Question
|
class Question
|
||||||
|
|
||||||
def initialize(env, key, default, options = {})
|
def initialize(key, default, options = {})
|
||||||
@env, @key, @default, @options = env, key, default, options
|
@key, @default, @options = key, default, options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
ask_question
|
ask_question
|
||||||
save_response
|
value_or_default
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
attr_reader :env, :key, :default, :options
|
attr_reader :key, :default, :options
|
||||||
|
|
||||||
def ask_question
|
def ask_question
|
||||||
$stdout.print question
|
$stdout.print question
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_response
|
|
||||||
env.set(key, value_or_default)
|
|
||||||
end
|
|
||||||
|
|
||||||
def value_or_default
|
def value_or_default
|
||||||
if response.empty?
|
if response.empty?
|
||||||
default
|
default
|
||||||
|
|
|
@ -5,11 +5,10 @@ module Capistrano
|
||||||
|
|
||||||
describe Question do
|
describe Question do
|
||||||
|
|
||||||
let(:question) { Question.new(env, key, default, options) }
|
let(:question) { Question.new(key, default, options) }
|
||||||
let(:question_without_echo) { Question.new(env, key, default, echo: false) }
|
let(:question_without_echo) { Question.new(key, default, echo: false) }
|
||||||
let(:default) { :default }
|
let(:default) { :default }
|
||||||
let(:key) { :branch }
|
let(:key) { :branch }
|
||||||
let(:env) { stub }
|
|
||||||
let(:options) { nil }
|
let(:options) { nil }
|
||||||
|
|
||||||
describe '.new' do
|
describe '.new' do
|
||||||
|
@ -26,20 +25,18 @@ module Capistrano
|
||||||
$stdout.expects(:print).with('Please enter branch (default): ')
|
$stdout.expects(:print).with('Please enter branch (default): ')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the echoed value' do
|
it 'returns the echoed value' do
|
||||||
$stdin.expects(:gets).returns(branch)
|
$stdin.expects(:gets).returns(branch)
|
||||||
$stdin.expects(:noecho).never
|
$stdin.expects(:noecho).never
|
||||||
env.expects(:set).with(key, branch)
|
|
||||||
|
|
||||||
question.call
|
expect(question.call).to eq(branch)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the value but does not echo it' do
|
it 'returns the value but does not echo it' do
|
||||||
$stdin.expects(:noecho).returns(branch)
|
$stdin.expects(:noecho).returns(branch)
|
||||||
$stdout.expects(:print).with("\n")
|
$stdout.expects(:print).with("\n")
|
||||||
env.expects(:set).with(key, branch)
|
|
||||||
|
|
||||||
question_without_echo.call
|
expect(question_without_echo.call).to eq(branch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -51,9 +48,9 @@ module Capistrano
|
||||||
$stdin.expects(:gets).returns('')
|
$stdin.expects(:gets).returns('')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets the default as the value' do
|
|
||||||
env.expects(:set).with(key, branch)
|
it 'returns the default as the value' do
|
||||||
question.call
|
expect(question.call).to eq(branch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -154,7 +154,7 @@ module Capistrano
|
||||||
let(:options) { Hash.new }
|
let(:options) { Hash.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Configuration::Question.expects(:new).with(config, :branch, :default, options).
|
Configuration::Question.expects(:new).with(:branch, :default, options).
|
||||||
returns(question)
|
returns(question)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue