diff --git a/CHANGELOG.md b/CHANGELOG.md index fa46e012..fb16d063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ gem "capistrano", github: "capistrano/capistrano", require: false [master]: https://github.com/capistrano/capistrano/compare/v3.10.2...HEAD * Your contribution here! +* [#1972](https://github.com/capistrano/capistrano/pull/1972): fallback ask to default when used in non interactive session ## [`3.10.2`] (2018-04-15) diff --git a/lib/capistrano/configuration/question.rb b/lib/capistrano/configuration/question.rb index 9435e7db..9f929b58 100644 --- a/lib/capistrano/configuration/question.rb +++ b/lib/capistrano/configuration/question.rb @@ -36,6 +36,8 @@ module Capistrano end def gets + return unless $stdin.tty? + if echo? $stdin.gets else diff --git a/spec/lib/capistrano/configuration/question_spec.rb b/spec/lib/capistrano/configuration/question_spec.rb index 55b6cb2b..4ad36b37 100644 --- a/spec/lib/capistrano/configuration/question_spec.rb +++ b/spec/lib/capistrano/configuration/question_spec.rb @@ -57,6 +57,17 @@ module Capistrano expect(question.call).to eq(branch) end end + + context "tty unavailable" do + before do + $stdin.expects(:gets).never + $stdin.expects(:tty?).returns(false) + end + + it "returns the default as the value" do + expect(question.call).to eq(default) + end + end end end end