From cd0eba1268b8a182e4b160865ee81b6982885339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lovro=20Biki=C4=87?= Date: Tue, 17 Aug 2021 12:28:37 +0200 Subject: [PATCH] Test remaining default tasks (#692) --- spec/support/outputs/environment.txt | 1 + spec/support/outputs/ssh_keyscan_domain.txt | 3 ++ spec/tasks/default_spec.rb | 50 +++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 spec/support/outputs/environment.txt create mode 100644 spec/support/outputs/ssh_keyscan_domain.txt diff --git a/spec/support/outputs/environment.txt b/spec/support/outputs/environment.txt new file mode 100644 index 00000000..c0ed6670 --- /dev/null +++ b/spec/support/outputs/environment.txt @@ -0,0 +1 @@ +environment is DEPRECATED! Please use local_environment and remote_environment \ No newline at end of file diff --git a/spec/support/outputs/ssh_keyscan_domain.txt b/spec/support/outputs/ssh_keyscan_domain.txt new file mode 100644 index 00000000..4d143262 --- /dev/null +++ b/spec/support/outputs/ssh_keyscan_domain.txt @@ -0,0 +1,3 @@ +if ! ssh-keygen -H -F localhost &>/dev/null; then + ssh-keyscan -p 22 localhost >> ~/.ssh/known_hosts +fi \ No newline at end of file diff --git a/spec/tasks/default_spec.rb b/spec/tasks/default_spec.rb index ed154f2d..8fe4c941 100644 --- a/spec/tasks/default_spec.rb +++ b/spec/tasks/default_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' RSpec.describe 'default', type: :rake do + describe 'environment' do + it 'outputs a deprecation warning' do + expect { invoke_all }.to output(output_file('environment')).to_stdout + end + end + describe 'ssh_keyscan_repo' do it 'scans ssh' do Mina::Configuration.instance.set(:repository, 'git@github.com/exapmle') @@ -8,6 +14,50 @@ end end + describe 'ssh_keyscan_domain' do + subject { rake['ssh_keyscan_domain'] } + + context "when domain isn't set" do + around do |example| + original_domain = Mina::Configuration.instance.fetch(:domain) + Mina::Configuration.instance.remove(:domain) + example.run + Mina::Configuration.instance.set(:domain, original_domain) + end + + it 'exits with an error message' do + expect do + invoke_all + end.to raise_error(SystemExit) + .and output(/domain must be defined!/).to_stdout + end + end + + context "when port isn't set" do + around do |example| + original_port = Mina::Configuration.instance.fetch(:port) + Mina::Configuration.instance.remove(:port) + example.run + Mina::Configuration.instance.set(:port, original_port) + end + + it 'exits with an error message' do + expect do + invoke_all + end.to raise_error(SystemExit) + .and output(/port must be defined!/).to_stdout + end + end + + context 'when conditions are met' do + it 'scans ssh' do + expect do + invoke_all + end.to output(output_file('ssh_keyscan_domain')).to_stdout + end + end + end + describe 'run' do it 'runs command' do subject.invoke('ls -al')