From 146dc05e37ef01d4a90d28d8d9fdaf10aa3c44b9 Mon Sep 17 00:00:00 2001 From: Raphael Reitzig <4246780+reitzig@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:53:01 +0200 Subject: [PATCH] feat(test): Adopt `BeforeAll` and `AfterAll` --- test/features/autoenv.feature | 3 +-- test/features/completions.feature | 3 +-- test/features/step_definitions/setup.rb | 8 -------- test/features/support/hooks.rb | 11 +++++------ test/features/wrapper.feature | 3 +-- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/test/features/autoenv.feature b/test/features/autoenv.feature index f13209d..1c9c498 100644 --- a/test/features/autoenv.feature +++ b/test/features/autoenv.feature @@ -3,8 +3,7 @@ Feature: Support autoenv setting candidates specified in `./.sdkmanrc`, if any. Background: - Given SDKMAN! candidate list is up to date - And candidate ant is installed at version 1.9.7 + Given candidate ant is installed at version 1.9.7 And candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 And candidate kscript is installed at version 1.5.0 diff --git a/test/features/completions.feature b/test/features/completions.feature index 6565e10..543b915 100644 --- a/test/features/completions.feature +++ b/test/features/completions.feature @@ -2,8 +2,7 @@ Feature: Shell Completion We want to get the correct completion on the CLI. Background: - Given SDKMAN! candidate list is up to date - And candidate ant is installed at version 1.9.9 + Given candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 And candidate kscript is installed diff --git a/test/features/step_definitions/setup.rb b/test/features/step_definitions/setup.rb index a295e3b..a19ee46 100644 --- a/test/features/step_definitions/setup.rb +++ b/test/features/step_definitions/setup.rb @@ -1,14 +1,6 @@ require 'fileutils' require 'tempfile' -$index_updated = false # TODO: Hack since Cucumber doesn't have Feature-level hooks -Given(/^SDKMAN! candidate list is up to date$/) do - unless $index_updated - run_bash_command('sdk update') - $index_updated = true - end -end - Given(/^candidate (\w+) is installed at version (\d+(?:\.\d+)*)$/) do |candidate, version| # TODO: Can we mock-install instead? # Something like diff --git a/test/features/support/hooks.rb b/test/features/support/hooks.rb index ea524cb..d26980e 100644 --- a/test/features/support/hooks.rb +++ b/test/features/support/hooks.rb @@ -1,6 +1,10 @@ require_relative '../step_definitions/setup' require_relative '../step_definitions/corner_cases.rb' +BeforeAll do + run_bash_command('sdk update') +end + After do |scenario| _remove_fish_configs _restore_fish_config @@ -9,12 +13,7 @@ After do |scenario| end # Uninstall all SDKMAN! candidates -# TODO: Run after every scenario, this makes tests very slow. -# Currently, Cucumber doesn't have Feature-level hooks, so we have to work around: -# --> install only if not already installed; -# if the test needs a candidate to _not_ be there, make it explicit. -# --> clean up after _all_ features at least -at_exit do +AfterAll do Dir["#{ENV['HOME']}/.sdkman/candidates/*/*"].each do |candidate_dir| _uninstall_candidate_version(candidate_dir) end diff --git a/test/features/wrapper.feature b/test/features/wrapper.feature index f6942f5..0f2c7be 100644 --- a/test/features/wrapper.feature +++ b/test/features/wrapper.feature @@ -7,8 +7,7 @@ Feature: Wrapping of Bash We verify equality of (standard) output, exit code, and environment variables. Background: - Given SDKMAN! candidate list is up to date - And candidate ant is installed at version 1.9.9 + Given candidate ant is installed at version 1.9.9 And candidate ant is installed at version 1.10.1 And file /tmp/env-test/.sdkmanrc exists with content """