From db2c86204b84e70ef6cef912ac410ea93551127f Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 8 Oct 2017 17:41:03 +0200 Subject: [PATCH] internal_stanza.rb: Remove obsolete code. Improve detection of missing stanzas internal_stanza_spec.rb: change do ... end blocks to { } blocks --- .../cask/lib/hbc/cli/internal_stanza.rb | 10 +++---- .../test/cask/cli/internal_stanza_spec.rb | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 4f85694445..49b187216e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -57,12 +57,6 @@ module Hbc casks(alternative: -> { Hbc.all }).each do |cask| print "#{cask}\t" if table? - unless cask.respond_to?(stanza) - opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet? - puts "" - next - end - begin value = cask.send(stanza) rescue StandardError @@ -71,7 +65,9 @@ module Hbc next end - if (value.nil? || value.is_a?(Array) && value.empty?) || + if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || + (value.respond_to?(:to_h) && value.to_h.empty?) || + (value.respond_to?(:to_s) && value.to_s == "{}") || (artifact_name && !value.key?(artifact_name)) if artifact_name diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index f3002e2220..52bbf4ee0b 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -1,35 +1,42 @@ describe Hbc::CLI::InternalStanza, :cask do it "shows stanza of the Specified Cask" do command = described_class.new("gpg", "with-gpg") - expect do + expect { command.run - end.to output("http://example.com/gpg-signature.asc\n").to_stdout + }.to output("http://example.com/gpg-signature.asc\n").to_stdout end it "raises an exception when stanza is invalid" do - expect do + expect { described_class.new("invalid_stanza", "with-gpg") - end.to raise_error(/Illegal stanza/) + }.to raise_error(/Illegal stanza/) end it "raises an exception when normal stanza is not present on cask" do command = described_class.new("caveats", "with-gpg") - expect do + expect { command.run - end.to raise_error(/no such stanza/) + }.to raise_error(/no such stanza/) end it "raises an exception when artifact stanza is not present on cask" do command = described_class.new("zap", "with-gpg") - expect do + expect { command.run - end.to raise_error(/no such stanza/) + }.to raise_error(/no such stanza/) + end + + it "raises an exception when 'depends_on' stanza is not present on cask" do + command = described_class.new("depends_on", "with-gpg") + expect { + command.run + }.to raise_error(/no such stanza/) end it "shows all artifact stanzas when using 'artifacts' keyword" do command = described_class.new("artifacts", "with-gpg") - expect do + expect { command.run - end.to output("{:app=>[[\"Caffeine.app\"]]}\n").to_stdout + }.to output("{:app=>[[\"Caffeine.app\"]]}\n").to_stdout end end