brew/Library/Homebrew/test/cask/cmd/outdated_spec.rb

197 lines
5.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-10-03 10:49:58 +02:00
require_relative "shared_examples/invalid_option"
2018-09-06 08:29:14 +02:00
describe Cask::Cmd::Outdated, :cask do
2017-02-27 22:33:34 +02:00
let(:installed) do
[
2018-09-06 08:29:14 +02:00
Cask::CaskLoader.load(cask_path("basic-cask")),
Cask::CaskLoader.load(cask_path("outdated/local-caffeine")),
Cask::CaskLoader.load(cask_path("outdated/local-transmission")),
Cask::CaskLoader.load(cask_path("version-latest-string")),
Cask::CaskLoader.load(cask_path("outdated/auto-updates")),
2017-02-27 22:33:34 +02:00
]
end
before do
2017-07-29 19:55:05 +02:00
installed.each { |cask| InstallHelper.install_with_caskfile(cask) }
2017-02-27 22:33:34 +02:00
end
2017-10-03 10:49:58 +02:00
it_behaves_like "a command that handles invalid options"
2019-08-19 14:27:29 +10:00
describe 'without --greedy it ignores the Casks with "version latest" or "auto_updates true"' do
2017-02-27 22:33:34 +02:00
it "checks all the installed Casks when no token is provided" do
expect {
2017-05-21 02:32:46 +02:00
described_class.run
2020-08-01 02:30:46 +02:00
}.to output(<<~EOS).to_stdout.as_tty
2017-02-27 22:33:34 +02:00
local-caffeine (1.2.2) != 1.2.3
local-transmission (2.60) != 2.61
EOS
end
it "checks only the tokens specified in the command line" do
expect {
2017-05-21 02:32:46 +02:00
described_class.run("local-caffeine")
2020-08-01 02:30:46 +02:00
}.to output(<<~EOS).to_stdout.as_tty
2017-02-27 22:33:34 +02:00
local-caffeine (1.2.2) != 1.2.3
EOS
end
it 'ignores "auto_updates" and "latest" Casks even when their tokens are provided in the command line' do
expect {
2017-05-21 02:32:46 +02:00
described_class.run("local-caffeine", "auto-updates", "version-latest-string")
2020-08-01 02:30:46 +02:00
}.to output(<<~EOS).to_stdout.as_tty
2017-02-27 22:33:34 +02:00
local-caffeine (1.2.2) != 1.2.3
EOS
end
end
2020-08-01 02:30:46 +02:00
describe "--quiet overrides TTY" do
it "lists only the names (no versions) of the outdated Casks with --quiet" do
expect {
described_class.run("--quiet")
}.to output(<<~EOS).to_stdout.as_tty
local-caffeine
local-transmission
EOS
2017-05-21 02:32:46 +02:00
end
2020-08-01 02:30:46 +02:00
end
2017-05-21 02:32:46 +02:00
2020-08-01 02:30:46 +02:00
describe "--quiet overrides --verbose" do
2017-05-21 02:32:46 +02:00
it "lists only the names (no versions) of the outdated Casks with --quiet" do
expect {
described_class.run("--verbose", "--quiet")
2017-10-15 02:28:32 +02:00
}.to output(<<~EOS).to_stdout
2017-05-21 02:32:46 +02:00
local-caffeine
local-transmission
EOS
end
2017-02-27 22:33:34 +02:00
end
describe "with --greedy it checks additional Casks" do
it 'includes the Casks with "auto_updates true" or "version latest" with --greedy' do
expect {
2017-05-21 02:32:46 +02:00
described_class.run("--greedy")
2020-08-01 02:30:46 +02:00
}.to output(<<~EOS).to_stdout.as_tty
2017-02-27 22:33:34 +02:00
auto-updates (2.57) != 2.61
local-caffeine (1.2.2) != 1.2.3
local-transmission (2.60) != 2.61
version-latest-string (latest) != latest
EOS
end
it 'does not include the Casks with "auto_updates true" when the version did not change' do
2018-09-06 08:29:14 +02:00
cask = Cask::CaskLoader.load(cask_path("auto-updates"))
2017-02-27 22:33:34 +02:00
InstallHelper.install_with_caskfile(cask)
expect {
2017-05-21 02:32:46 +02:00
described_class.run("--greedy")
2020-08-01 02:30:46 +02:00
}.to output(<<~EOS).to_stdout.as_tty
2017-02-27 22:33:34 +02:00
local-caffeine (1.2.2) != 1.2.3
local-transmission (2.60) != 2.61
version-latest-string (latest) != latest
EOS
end
end
describe "--json" do
it "lists outdated Casks in JSON format" do
result = [
{
2020-04-26 21:31:21 +08:00
name: "local-caffeine",
installed_versions: "1.2.2",
2020-04-26 21:31:21 +08:00
current_version: "1.2.3",
},
{
2020-04-26 21:31:21 +08:00
name: "local-transmission",
installed_versions: "2.60",
2020-04-26 21:31:21 +08:00
current_version: "2.61",
},
].to_json
expect {
described_class.run("--json")
2020-08-19 17:12:32 +01:00
}.to output("#{result}\n").to_stdout
end
end
describe "--json overrides --quiet" do
it "ignores --quiet and lists outdated Casks in JSON format" do
result = [
{
2020-04-26 21:31:21 +08:00
name: "local-caffeine",
installed_versions: "1.2.2",
2020-04-26 21:31:21 +08:00
current_version: "1.2.3",
},
{
2020-04-26 21:31:21 +08:00
name: "local-transmission",
installed_versions: "2.60",
2020-04-26 21:31:21 +08:00
current_version: "2.61",
},
].to_json
expect {
described_class.run("--json", "--quiet")
2020-08-19 17:12:32 +01:00
}.to output("#{result}\n").to_stdout
end
end
describe "--json and --greedy" do
it 'includes the Casks with "auto_updates true" or "version latest" in JSON format' do
result = [
{
2020-04-26 21:31:21 +08:00
name: "auto-updates",
installed_versions: "2.57",
2020-04-26 21:31:21 +08:00
current_version: "2.61",
},
{
2020-04-26 21:31:21 +08:00
name: "local-caffeine",
installed_versions: "1.2.2",
2020-04-26 21:31:21 +08:00
current_version: "1.2.3",
},
{
2020-04-26 21:31:21 +08:00
name: "local-transmission",
installed_versions: "2.60",
2020-04-26 21:31:21 +08:00
current_version: "2.61",
},
{
2020-04-26 21:31:21 +08:00
name: "version-latest-string",
installed_versions: "latest",
2020-04-26 21:31:21 +08:00
current_version: "latest",
},
].to_json
expect {
described_class.run("--json", "--greedy")
2020-08-19 17:12:32 +01:00
}.to output("#{result}\n").to_stdout
end
it 'does not include the Casks with "auto_updates true" with no version change in JSON format' do
cask = Cask::CaskLoader.load(cask_path("auto-updates"))
InstallHelper.install_with_caskfile(cask)
result = [
{
2020-04-26 21:31:21 +08:00
name: "local-caffeine",
installed_versions: "1.2.2",
2020-04-26 21:31:21 +08:00
current_version: "1.2.3",
},
{
2020-04-26 21:31:21 +08:00
name: "local-transmission",
installed_versions: "2.60",
2020-04-26 21:31:21 +08:00
current_version: "2.61",
},
{
2020-04-26 21:31:21 +08:00
name: "version-latest-string",
installed_versions: "latest",
2020-04-26 21:31:21 +08:00
current_version: "latest",
},
].to_json
expect {
described_class.run("--json", "--greedy")
2020-08-19 17:12:32 +01:00
}.to output("#{result}\n").to_stdout
end
end
2017-02-27 22:33:34 +02:00
end