From b7a51eab6be0d62674231699d513db310df608b8 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Tue, 3 Oct 2017 19:35:43 +0200 Subject: [PATCH 01/16] improve 'brew cask _stanza' by checking for known stanzas --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index c046197989127..1b15d9386bb68 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -43,6 +43,10 @@ def initialize(*) @stanza = args.shift.to_sym @format = :to_yaml if yaml? + + unless DSL::DSL_METHODS.include?(stanza) + raise ArgumentError, "Illegal stanza: '#{stanza}'" + end end def run From be68f3d7b49f2e9b84e7230d5c22b6522992ea8c Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Wed, 4 Oct 2017 06:03:13 +0200 Subject: [PATCH 02/16] Fix 'brew style' offenses --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 1b15d9386bb68..b0812d27c4321 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -44,9 +44,8 @@ def initialize(*) @format = :to_yaml if yaml? - unless DSL::DSL_METHODS.include?(stanza) - raise ArgumentError, "Illegal stanza: '#{stanza}'" - end + return if DSL::DSL_METHODS.include?(stanza) + raise ArgumentError, "Illegal stanza: '#{stanza}'" end def run From ff2239509d53f86ca48330ddfc6f24fe03ba9768 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sat, 7 Oct 2017 21:32:40 +0200 Subject: [PATCH 03/16] Change behaviour of 'cask _stanza' command. Add tests for 'cask _stanza' command --- .../cask/lib/hbc/cli/internal_stanza.rb | 8 +++++- .../test/cask/cli/internal_stanza_spec.rb | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Library/Homebrew/test/cask/cli/internal_stanza_spec.rb diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index b0812d27c4321..411170010c3f0 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -71,10 +71,16 @@ def run next end + if value == nil || (value.kind_of?(Array) && value.empty?) + opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet? + puts "" + raise ArgumentError, "no such stanza '#{stanza}' on Cask '#{cask}'" + end + if artifact_name && !value.key?(artifact_name) opoo "no such stanza '#{artifact_name}' on Cask '#{cask}'" unless quiet? puts "" - next + raise ArgumentError, "no such stanza '#{artifact_name}' on Cask '#{cask}'" end if stanza == :artifacts diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb new file mode 100644 index 0000000000000..77b065567e8a7 --- /dev/null +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -0,0 +1,28 @@ +describe Hbc::CLI::InternalStanza, :cask do + + it "shows stanza of the Specified Cask" do + command = described_class.new("gpg", "with-gpg"); + command.run + # TODO check result + end + + it "raises an exception when stanza is invalid" do + expect { + described_class.new("invalid_stanza", "with-gpg"); + }.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 { + command.run + }.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 { + command.run + }.to raise_error(/no such stanza/) + end +end From 99b76360081ac92f75792ecea049b3dba496c659 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sat, 7 Oct 2017 23:07:31 +0200 Subject: [PATCH 04/16] Fix 'brew style' issues --- .../cask/lib/hbc/cli/internal_stanza.rb | 2 +- .../test/cask/cli/internal_stanza_spec.rb | 27 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 411170010c3f0..05d939a4b5017 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -71,7 +71,7 @@ def run next end - if value == nil || (value.kind_of?(Array) && value.empty?) + if value.nil? || (value.is_a?(Array) && value.empty?) opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet? puts "" raise ArgumentError, "no such stanza '#{stanza}' on Cask '#{cask}'" diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index 77b065567e8a7..1599ca84378ce 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -1,28 +1,27 @@ describe Hbc::CLI::InternalStanza, :cask do - it "shows stanza of the Specified Cask" do - command = described_class.new("gpg", "with-gpg"); + command = described_class.new("gpg", "with-gpg") command.run - # TODO check result + # TODO: check result end it "raises an exception when stanza is invalid" do - expect { - described_class.new("invalid_stanza", "with-gpg"); - }.to raise_error(/Illegal stanza/); + expect do + described_class.new("invalid_stanza", "with-gpg") + end.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 { - command.run - }.to raise_error(/no such stanza/) + command = described_class.new("caveats", "with-gpg") + expect do + command.run + end.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 { - command.run - }.to raise_error(/no such stanza/) + command = described_class.new("zap", "with-gpg") + expect do + command.run + end.to raise_error(/no such stanza/) end end From dfe4e7641a71aef693831134c8db406e3252fa88 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 8 Oct 2017 09:59:29 +0200 Subject: [PATCH 05/16] combine errors to a single if-statement. fix spec test --- .../cask/lib/hbc/cli/internal_stanza.rb | 18 +++++++++--------- .../test/cask/cli/internal_stanza_spec.rb | 5 +++-- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 05d939a4b5017..4f856944457ca 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -71,16 +71,16 @@ def run next end - if value.nil? || (value.is_a?(Array) && value.empty?) - opoo "no such stanza '#{stanza}' on Cask '#{cask}'" unless quiet? - puts "" - raise ArgumentError, "no such stanza '#{stanza}' on Cask '#{cask}'" - end + if (value.nil? || value.is_a?(Array) && value.empty?) || + (artifact_name && !value.key?(artifact_name)) - if artifact_name && !value.key?(artifact_name) - opoo "no such stanza '#{artifact_name}' on Cask '#{cask}'" unless quiet? - puts "" - raise ArgumentError, "no such stanza '#{artifact_name}' on Cask '#{cask}'" + if artifact_name + thing = artifact_name + else + thing = stanza + end + + raise CaskError, "no such stanza '#{thing}' on Cask '#{cask}'" end if stanza == :artifacts diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index 1599ca84378ce..38fa1b8405eab 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -1,8 +1,9 @@ describe Hbc::CLI::InternalStanza, :cask do it "shows stanza of the Specified Cask" do command = described_class.new("gpg", "with-gpg") - command.run - # TODO: check result + expect do + command.run + end.to output("http://example.com/gpg-signature.asc\n").to_stdout end it "raises an exception when stanza is invalid" do From 7f70080c94b6ef9b772b3464a0c0bb9420a407e0 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 8 Oct 2017 12:34:15 +0200 Subject: [PATCH 06/16] Add another test to increase coverage. --- Library/Homebrew/test/cask/cli/internal_stanza_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index 38fa1b8405eab..f3002e2220e71 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -25,4 +25,11 @@ command.run end.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 + command.run + end.to output("{:app=>[[\"Caffeine.app\"]]}\n").to_stdout + end end From db2c86204b84e70ef6cef912ac410ea93551127f Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 8 Oct 2017 17:41:03 +0200 Subject: [PATCH 07/16] 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 4f856944457ca..49b187216e9be 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 @@ def run 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 @@ def run 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 f3002e2220e71..52bbf4ee0b45d 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 From 255e991cc32da3141afc1a50e1f643d8e028a9f6 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Wed, 11 Oct 2017 19:06:35 +0200 Subject: [PATCH 08/16] Remove obsolete code to fix tests. --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 49b187216e9be..597ff45970dba 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -66,7 +66,6 @@ def run end 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)) From 587c5b07b326c82dc3becf4e4229861c86b1dcfa Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Thu, 12 Oct 2017 19:47:45 +0200 Subject: [PATCH 09/16] Fix handling of artifact set --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 597ff45970dba..1ac5856736035 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -67,7 +67,7 @@ def run if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || (value.respond_to?(:to_s) && value.to_s == "{}") || - (artifact_name && !value.key?(artifact_name)) + (artifact_name && !value.include?(artifact_name)) if artifact_name thing = artifact_name From d03720320ad22c564cb2675d919d09677f368a9b Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sat, 14 Oct 2017 08:38:46 +0200 Subject: [PATCH 10/16] adapt internal_stanza command to work with SortedSet of Artifacts --- .../cask/lib/hbc/cli/internal_stanza.rb | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 1ac5856736035..dd7bf6e9cd502 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -24,6 +24,9 @@ class InternalStanza < AbstractInternalCommand ARTIFACTS = DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) + DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key) + ARTIFACTS_CLASSES = + DSL::ORDINARY_ARTIFACT_CLASSES + + DSL::ARTIFACT_BLOCK_CLASSES option "--table", :table, false option "--quiet", :quiet, false @@ -65,33 +68,29 @@ def run next end - if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || - (value.respond_to?(:to_s) && value.to_s == "{}") || - (artifact_name && !value.include?(artifact_name)) - - if artifact_name - thing = artifact_name - else - thing = stanza + if stanza == :artifacts + result = {} + value.each do |e| + result[e.class.dsl_key] = e.summarize end - - raise CaskError, "no such stanza '#{thing}' on Cask '#{cask}'" + value = result end - if stanza == :artifacts - value = Hash[ - value.map do |k, v| - v = v.map do |a| - next a.to_a if a.respond_to?(:to_a) - next a.to_h if a.respond_to?(:to_h) - a - end - - [k, v] + if artifact_name + result = nil + value.each do |k, v| + if k == artifact_name + result = v + break end - ] + end + value = result + end + + if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || + (value.respond_to?(:to_s) && value.to_s == "{}") # || - value = value.fetch(artifact_name) if artifact_name + raise CaskError, "no such stanza '#{artifact_name ? artifact_name : stanza}' on Cask '#{cask}'" end if format From 52343142a7d9cb871fc1f4affc3edb9caff69ab5 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sat, 14 Oct 2017 17:39:26 +0200 Subject: [PATCH 11/16] Remove unused variables. Refactor code --- .../cask/lib/hbc/cli/internal_stanza.rb | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index dd7bf6e9cd502..5929d05032149 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -24,9 +24,6 @@ class InternalStanza < AbstractInternalCommand ARTIFACTS = DSL::ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key) + DSL::ARTIFACT_BLOCK_CLASSES.map(&:dsl_key) - ARTIFACTS_CLASSES = - DSL::ORDINARY_ARTIFACT_CLASSES + - DSL::ARTIFACT_BLOCK_CLASSES option "--table", :table, false option "--quiet", :quiet, false @@ -69,27 +66,12 @@ def run end if stanza == :artifacts - result = {} - value.each do |e| - result[e.class.dsl_key] = e.summarize - end - value = result - end - - if artifact_name - result = nil - value.each do |k, v| - if k == artifact_name - result = v - break - end - end - value = result + value = Hash[value.map { |v| [v.class.dsl_key, v] }] + value = value[artifact_name] if artifact_name end if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || - (value.respond_to?(:to_s) && value.to_s == "{}") # || - + (value.respond_to?(:to_s) && value.to_s == "{}") raise CaskError, "no such stanza '#{artifact_name ? artifact_name : stanza}' on Cask '#{cask}'" end From 5eab54f892cfac39c78a3d092f3084ce817fca04 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 22 Oct 2017 09:57:40 +0200 Subject: [PATCH 12/16] Reduce verbosity of artifacts hash --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 5929d05032149..bce5db3e1a0e1 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -66,7 +66,7 @@ def run end if stanza == :artifacts - value = Hash[value.map { |v| [v.class.dsl_key, v] }] + value = Hash[value.map { |v| [v.class.dsl_key, v.to_s] }] value = value[artifact_name] if artifact_name end From 2b261ad4a7d0e29f1708be5ae547c29e22635652 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 22 Oct 2017 13:43:17 +0200 Subject: [PATCH 13/16] Refactor code to reduce characters per line --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 6 ++++-- Library/Homebrew/test/cask/cli/internal_stanza_spec.rb | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index bce5db3e1a0e1..b5df67b0ff982 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -45,7 +45,8 @@ def initialize(*) @format = :to_yaml if yaml? return if DSL::DSL_METHODS.include?(stanza) - raise ArgumentError, "Illegal stanza: '#{stanza}'" + raise ArgumentError, + "Unknown/unsupported stanza: '#{stanza}' Check cask reference for supported stanzas." end def run @@ -72,7 +73,8 @@ def run if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || (value.respond_to?(:to_s) && value.to_s == "{}") - raise CaskError, "no such stanza '#{artifact_name ? artifact_name : stanza}' on Cask '#{cask}'" + stanza_name = artifact_name ? artifact_name : stanza + raise CaskError, "no such stanza '#{stanza_name}' on Cask '#{cask}'" end if format diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index 52bbf4ee0b45d..a020b33d49780 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -6,10 +6,10 @@ }.to output("http://example.com/gpg-signature.asc\n").to_stdout end - it "raises an exception when stanza is invalid" do + it "raises an exception when stanza is unknown/unsupported" do expect { - described_class.new("invalid_stanza", "with-gpg") - }.to raise_error(/Illegal stanza/) + described_class.new("this_stanza_does_not_exist", "with-gpg") + }.to raise_error(/Unknown\/unsupported stanza/) end it "raises an exception when normal stanza is not present on cask" do @@ -37,6 +37,6 @@ command = described_class.new("artifacts", "with-gpg") expect { command.run - }.to output("{:app=>[[\"Caffeine.app\"]]}\n").to_stdout + }.to output(/Caffeine\.app/).to_stdout end end From 4e4405e6d78c508929845be30f75bcf897e04d36 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Sun, 22 Oct 2017 15:04:45 +0200 Subject: [PATCH 14/16] split string to stay below 80 characters per line --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index b5df67b0ff982..a0cf17b64d779 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -46,7 +46,8 @@ def initialize(*) return if DSL::DSL_METHODS.include?(stanza) raise ArgumentError, - "Unknown/unsupported stanza: '#{stanza}' Check cask reference for supported stanzas." + "Unknown/unsupported stanza: '#{stanza}' Check cask reference"\ + " for supported stanzas." end def run From fea5350d52de54eca9d6f30c67bd2fa008ca8328 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Mon, 23 Oct 2017 06:49:12 +0200 Subject: [PATCH 15/16] Add line break to string --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 6 ++++-- Library/Homebrew/test/cask/cli/internal_stanza_spec.rb | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index a0cf17b64d779..27f195a4d3aa3 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -46,8 +46,10 @@ def initialize(*) return if DSL::DSL_METHODS.include?(stanza) raise ArgumentError, - "Unknown/unsupported stanza: '#{stanza}' Check cask reference"\ - " for supported stanzas." + <<~EOS + Unknown/unsupported stanza: '#{stanza}' + Check cask reference for supported stanzas. + EOS end def run diff --git a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb index a020b33d49780..47b0fd8b33d77 100644 --- a/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb +++ b/Library/Homebrew/test/cask/cli/internal_stanza_spec.rb @@ -9,7 +9,7 @@ it "raises an exception when stanza is unknown/unsupported" do expect { described_class.new("this_stanza_does_not_exist", "with-gpg") - }.to raise_error(/Unknown\/unsupported stanza/) + }.to raise_error(%r{Unknown/unsupported stanza}) end it "raises an exception when normal stanza is not present on cask" do From 17e001bd306e5cedd207475985052205b6ddeac6 Mon Sep 17 00:00:00 2001 From: Martin Schimandl Date: Mon, 6 Nov 2017 21:24:12 +0100 Subject: [PATCH 16/16] Remove (soon to be) obsolete check Fix small typo --- Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb index 27f195a4d3aa3..bafaadc244b2c 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_stanza.rb @@ -48,7 +48,7 @@ def initialize(*) raise ArgumentError, <<~EOS Unknown/unsupported stanza: '#{stanza}' - Check cask reference for supported stanzas. + Check Cask reference for supported stanzas. EOS end @@ -74,8 +74,7 @@ def run value = value[artifact_name] if artifact_name end - if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) || - (value.respond_to?(:to_s) && value.to_s == "{}") + if value.nil? || (value.respond_to?(:to_a) && value.to_a.empty?) stanza_name = artifact_name ? artifact_name : stanza raise CaskError, "no such stanza '#{stanza_name}' on Cask '#{cask}'" end