From 42c4f74c732fa531c9493f7eacac9fae41da2a31 Mon Sep 17 00:00:00 2001 From: Kentaro Hayashi Date: Mon, 24 Aug 2020 13:41:52 +0900 Subject: [PATCH] Windows: support check_is_installed_by_gem Example: describe package("#{spec.name}") do it { should be_installed.by("gem").with_version(spec.version) } end This commit fixes the following error: check_is_installed_by_gem is not implemented in Specinfra::Command::Windows::Base::Package --- .../powershell/support/find_installed_gem.ps1 | 20 +++++++++++++++++++ lib/specinfra/command/windows/base/package.rb | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 lib/specinfra/backend/powershell/support/find_installed_gem.ps1 diff --git a/lib/specinfra/backend/powershell/support/find_installed_gem.ps1 b/lib/specinfra/backend/powershell/support/find_installed_gem.ps1 new file mode 100644 index 000000000..815a10252 --- /dev/null +++ b/lib/specinfra/backend/powershell/support/find_installed_gem.ps1 @@ -0,0 +1,20 @@ +function FindInstalledGem +{ + param($gemName, $gemVersion) + + $nameVer = $(Invoke-Expression "gem list --local" | Select-String "$gemName").Line + if ($nameVer.StartsWith($gemName)) { + if ($gemVersion) { + if ($nameVer.EndsWith("$gemVersion)")) { + $true + } else { + $false + } + } else { + $true + } + } else { + $false + } +} + diff --git a/lib/specinfra/command/windows/base/package.rb b/lib/specinfra/command/windows/base/package.rb index e52acd78f..0b953c041 100644 --- a/lib/specinfra/command/windows/base/package.rb +++ b/lib/specinfra/command/windows/base/package.rb @@ -7,5 +7,13 @@ def check_is_installed(package, version=nil) exec "(FindInstalledApplication -appName '#{package}' #{version_selection}) -eq $true" end end + + def check_is_installed_by_gem(name, version=nil, gem_binary="gem") + version_selection = version.nil? ? "" : "-gemVersion '#{version}'" + Backend::PowerShell::Command.new do + using 'find_installed_gem.ps1' + exec "(FindInstalledGem -gemName '#{name}' #{version_selection}) -eq $true" + end + end end end