diff --git a/lib/capistrano/configuration.rb b/lib/capistrano/configuration.rb index ab439e9b..67b65bdb 100644 --- a/lib/capistrano/configuration.rb +++ b/lib/capistrano/configuration.rb @@ -15,7 +15,7 @@ module Capistrano end def ask(key, default=nil, options={}) - question = Question.new(self, key, default, options) + question = Question.new(key, default, options) set(key, question) end diff --git a/lib/capistrano/configuration/question.rb b/lib/capistrano/configuration/question.rb index f087ea5b..4447011f 100644 --- a/lib/capistrano/configuration/question.rb +++ b/lib/capistrano/configuration/question.rb @@ -2,26 +2,22 @@ module Capistrano class Configuration class Question - def initialize(env, key, default, options = {}) - @env, @key, @default, @options = env, key, default, options + def initialize(key, default, options = {}) + @key, @default, @options = key, default, options end def call ask_question - save_response + value_or_default end private - attr_reader :env, :key, :default, :options + attr_reader :key, :default, :options def ask_question $stdout.print question end - def save_response - env.set(key, value_or_default) - end - def value_or_default if response.empty? default diff --git a/spec/lib/capistrano/configuration/question_spec.rb b/spec/lib/capistrano/configuration/question_spec.rb index 7f4b3ca4..289d7f7b 100644 --- a/spec/lib/capistrano/configuration/question_spec.rb +++ b/spec/lib/capistrano/configuration/question_spec.rb @@ -5,11 +5,10 @@ module Capistrano describe Question do - let(:question) { Question.new(env, key, default, options) } - let(:question_without_echo) { Question.new(env, key, default, echo: false) } + let(:question) { Question.new(key, default, options) } + let(:question_without_echo) { Question.new(key, default, echo: false) } let(:default) { :default } let(:key) { :branch } - let(:env) { stub } let(:options) { nil } describe '.new' do @@ -26,20 +25,18 @@ module Capistrano $stdout.expects(:print).with('Please enter branch (default): ') end - it 'sets the echoed value' do + it 'returns the echoed value' do $stdin.expects(:gets).returns(branch) $stdin.expects(:noecho).never - env.expects(:set).with(key, branch) - question.call + expect(question.call).to eq(branch) 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) $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 @@ -51,9 +48,9 @@ module Capistrano $stdin.expects(:gets).returns('') end - it 'sets the default as the value' do - env.expects(:set).with(key, branch) - question.call + + it 'returns the default as the value' do + expect(question.call).to eq(branch) end end end diff --git a/spec/lib/capistrano/configuration_spec.rb b/spec/lib/capistrano/configuration_spec.rb index 09c95637..76fed32d 100644 --- a/spec/lib/capistrano/configuration_spec.rb +++ b/spec/lib/capistrano/configuration_spec.rb @@ -154,7 +154,7 @@ module Capistrano let(:options) { Hash.new } before do - Configuration::Question.expects(:new).with(config, :branch, :default, options). + Configuration::Question.expects(:new).with(:branch, :default, options). returns(question) end