OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Skip tests whose needed CLI command is unavailable
Christophe Bliarddaf70b50540e
diff --git a/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb b/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rbindex a6166599534..603f3d63d61 100644--- a/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb+++ b/spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb@@ -70,7 +70,7 @@ describe OpenProject::SCM::Adapters::Subversion doenddescribe 'invalid repository' do- describe '.check_availability!' do+ describe '.check_availability!', skip_if_command_unavailable: 'svnadmin' doit 'is not available' doexpect(Dir.exist?(url)).to be falseexpect(adapter).not_to be_available@@ -130,7 +130,7 @@ describe OpenProject::SCM::Adapters::Subversion doinclude_context 'with tmpdir'let(:root_url) { tmpdir }- describe '.create_empty_svn' do+ describe '.create_empty_svn', skip_if_command_unavailable: 'svnadmin' docontext 'with valid root_url' doit 'creates the repository' doexpect(Dir.exist?(root_url)).to be true@@ -154,7 +154,7 @@ describe OpenProject::SCM::Adapters::Subversion doendend- describe '.check_availability!' do+ describe '.check_availability!', skip_if_command_unavailable: 'svnadmin' doit 'is marked empty' doadapter.create_empty_svnexpect { adapter.check_availability! }diff --git a/spec/models/ldap_auth_source_spec.rb b/spec/models/ldap_auth_source_spec.rbindex eb96d0af3d1..0933ded64b6 100644--- a/spec/models/ldap_auth_source_spec.rb+++ b/spec/models/ldap_auth_source_spec.rb@@ -216,7 +216,7 @@ describe LdapAuthSource doendend- describe 'with live LDAP' do+ describe 'with live LDAP', skip_if_command_unavailable: 'java' dobefore(:all) doldif = Rails.root.join('spec/fixtures/ldap/users.ldif')@ldap_server = Ladle::Server.new(quiet: false, port: ParallelHelper.port_for_ldap.to_s, domain: 'dc=example,dc=com',@@ -224,7 +224,7 @@ describe LdapAuthSource doendafter(:all) do- @ldap_server.stop+ @ldap_server&.stop # rubocop:disable RSpec/InstanceVariableend# Ldap has three users aa729, bb459, cc414diff --git a/spec/support/repository_helpers.rb b/spec/support/repository_helpers.rbindex 487184f6d4d..b579dcee977 100644--- a/spec/support/repository_helpers.rb+++ b/spec/support/repository_helpers.rb@@ -35,19 +35,17 @@# of isolation.def with_filesystem_repository(vendor, command = nil, &block)repo_dir = Dir.mktmpdir("#{vendor}_repository")- fixture = File.join(Rails.root, "spec/fixtures/repositories/#{vendor}_repository.tar.gz")+ fixture = Rails.root.join("spec/fixtures/repositories/#{vendor}_repository.tar.gz")- ['tar', command].compact.each do |cmd|- # Avoid `which`, as it's not POSIX- Open3.capture2e(cmd, '--version')- rescue Errno::ENOENT- skip "#{cmd} was not found in PATH. Skipping local repository specs"+ before do+ skip_if_commands_unavailable('tar', command)endafter(:all) doFileUtils.remove_dir repo_dirend+ skip_if_command_unavailable('tar')system "tar -xzf #{fixture} -C #{repo_dir}"block.call(repo_dir)enddiff --git a/spec/support/skip_if_command_unavailable.rb b/spec/support/skip_if_command_unavailable.rbnew file mode 100644index 00000000000..5f4484fd11b--- /dev/null+++ b/spec/support/skip_if_command_unavailable.rb@@ -0,0 +1,68 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module SkipIfCommandUnavailableMixin+ # Ensure given command(s) exist by running it with `--help`.+ # If the command does not exist, the test is skipped.+ #+ # The test is not skipped if in continuous integration environment.+ def skip_if_commands_unavailable(*commands)+ return if ENV['CI']++ commands.flatten.compact.each do |cmd|+ # Avoid `which`, as it's not POSIX+ Open3.capture2e(cmd, '--version')+ rescue Errno::ENOENT+ skip "Skipped because '#{cmd}' command not found in PATH"+ end+ end++ alias :skip_if_command_unavailable :skip_if_commands_unavailable+end++RSpec.configure do |config|+ include SkipIfCommandUnavailableMixin++ config.before :all, :skip_if_command_unavailable do+ skip_if_command_unavailable(self.class.metadata[:skip_if_command_unavailable])+ end++ config.before :all, :skip_if_commands_unavailable do+ skip_if_command_unavailable(self.class.metadata[:skip_if_commands_unavailable])+ end++ config.before :example, :skip_if_command_unavailable do |example|+ skip_if_command_unavailable(example.metadata[:skip_if_command_unavailable])+ end++ config.before :example, :skip_if_commands_unavailable do |example|+ skip_if_command_unavailable(example.metadata[:skip_if_commands_unavailable])+ end+end