Skip to content

Commit

Permalink
Merge pull request #595 from Korkey128k/patch-1
Browse files Browse the repository at this point in the history
More friendly error message for nonexistent env
  • Loading branch information
alessandro-fazzi authored May 16, 2020
2 parents 70b656f + 3e01e54 commit 110dd6f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/wordmove/movefile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@ def environment(cli_options = {})
available_enviroments = extract_available_envs(options)
options.merge!(cli_options).deep_symbolize_keys!

if available_enviroments.size > 1 && options[:environment].nil?
raise(
UndefinedEnvironment,
"You need to specify an environment with --environment parameter"
)
if options[:environment] != 'local'
if available_enviroments.size > 1 && options[:environment].nil?
raise(
UndefinedEnvironment,
"You need to specify an environment with --environment parameter"
)
end

if options[:environment].present?
unless available_enviroments.include?(options[:environment].to_sym)
raise UndefinedEnvironment, "No environment found for \"#{options[:environment]}\". "\
"Available Environments: #{available_enviroments.join(' ')}"
end
end
end

(options[:environment] || available_enviroments.first).to_sym
Expand Down
10 changes: 10 additions & 0 deletions spec/deployer/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
end
end

context "with more then one environment, but invalid chosen" do
it "raises an exception" do
options[:environment] = "doesnotexist"
options[:simulate] = true

expect { described_class.deployer_for(options) }
.to raise_exception(Wordmove::UndefinedEnvironment)
end
end

context "with ftp remote connection" do
it "returns an instance of FTP deployer" do
options[:environment] = "production"
Expand Down

0 comments on commit 110dd6f

Please sign in to comment.