From c97f8dc8b19ca025378311c4e736172458310f95 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 28 Feb 2017 16:31:25 +0100 Subject: [PATCH] Merge Plist spec with SystemCommand::Result spec. --- Library/Homebrew/cask/lib/hbc.rb | 2 - .../Homebrew/cask/lib/hbc/system_command.rb | 11 +-- .../spec/cask/system_command_result_spec.rb | 74 ++++++++++++++---- .../Homebrew/cask/spec/plist/parser_spec.rb | 75 ------------------- 4 files changed, 62 insertions(+), 100 deletions(-) delete mode 100644 Library/Homebrew/cask/spec/plist/parser_spec.rb diff --git a/Library/Homebrew/cask/lib/hbc.rb b/Library/Homebrew/cask/lib/hbc.rb index 80f1f1da0a..c971cbd58b 100644 --- a/Library/Homebrew/cask/lib/hbc.rb +++ b/Library/Homebrew/cask/lib/hbc.rb @@ -37,8 +37,6 @@ require "hbc/verify" require "hbc/version" require "utils" -require "vendor/plist/plist" - module Hbc include Locations include Scopes diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 06ce276dfc..f26be8e62c 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -1,5 +1,6 @@ require "open3" require "shellwords" +require "vendor/plist/plist" require "extend/io" @@ -167,16 +168,6 @@ module Hbc EOS end xml - rescue Plist::ParseError => e - raise CaskError, <<-EOS - Error parsing plist output from command. - command was: - #{command.utf8_inspect} - error was: - #{e} - output we attempted to parse: - #{output} - EOS end end end diff --git a/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb b/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb index a6a51301a0..b15d4d437e 100644 --- a/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb +++ b/Library/Homebrew/cask/spec/cask/system_command_result_spec.rb @@ -1,22 +1,37 @@ +require "hbc/system_command" + describe Hbc::SystemCommand::Result do describe "::_parse_plist" do + subject { described_class._parse_plist(command, input) } let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) } - let(:hdiutil_output) { + let(:plist) { <<-EOS.undent - Hello there! I am in no way XML am I?!?! - - That's a little silly... you were expexting XML here! - - What is a parser to do? - - Hopefully explode! - system-entities + + content-hint + Apple_partition_map + dev-entry + /dev/disk3s1 + potentially-mountable + + unmapped-content-hint + Apple_partition_map + + + content-hint + Apple_partition_scheme + dev-entry + /dev/disk3 + potentially-mountable + + unmapped-content-hint + Apple_partition_scheme + content-hint Apple_HFS @@ -37,11 +52,44 @@ describe Hbc::SystemCommand::Result do EOS } - it "ignores garbage output before xml starts" do - parsed = described_class._parse_plist(command, hdiutil_output) + context "when output contains garbage" do + let(:input) { + <<-EOS.undent + Hello there! I am in no way XML am I?!?! - expect(parsed.keys).to eq(["system-entities"]) - expect(parsed["system-entities"].length).to eq(1) + That's a little silly... you were expexting XML here! + + What is a parser to do? + + Hopefully explode! + + #{plist} + EOS + } + + it "ignores garbage before xml" do + expect(subject.keys).to eq(["system-entities"]) + expect(subject["system-entities"].length).to eq(3) + end + end + + context "given a hdiutil output as input" do + let(:input) { plist } + + it "successfully parses it" do + expect(subject.keys).to eq(["system-entities"]) + expect(subject["system-entities"].length).to eq(3) + expect(subject["system-entities"].map { |e| e["dev-entry"] }) + .to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"]) + end + end + + context "given an empty input" do + let(:input) { "" } + + it "raises an error" do + expect { subject }.to raise_error(Hbc::CaskError, /Empty plist input/) + end end end end diff --git a/Library/Homebrew/cask/spec/plist/parser_spec.rb b/Library/Homebrew/cask/spec/plist/parser_spec.rb deleted file mode 100644 index a71b7ea2ec..0000000000 --- a/Library/Homebrew/cask/spec/plist/parser_spec.rb +++ /dev/null @@ -1,75 +0,0 @@ -require "spec_helper" - -describe Plist do - subject { described_class.parse_xml(input) } - - describe "::parse_xml" do - context "given a hdiutil output as input" do - let(:input) { - <<-EOS.undent - - - - - system-entities - - - content-hint - Apple_partition_map - dev-entry - /dev/disk3s1 - potentially-mountable - - unmapped-content-hint - Apple_partition_map - - - content-hint - Apple_partition_scheme - dev-entry - /dev/disk3 - potentially-mountable - - unmapped-content-hint - Apple_partition_scheme - - - content-hint - Apple_HFS - dev-entry - /dev/disk3s2 - mount-point - /private/tmp/dmg.BhfS2g - potentially-mountable - - unmapped-content-hint - Apple_HFS - volume-kind - hfs - - - - - EOS - } - - it "successfully parses it" do - expect(subject.keys).to eq(["system-entities"]) - expect(subject["system-entities"].length).to eq(3) - expect(subject["system-entities"].map { |e| e["dev-entry"] }).to eq( - %w[ - /dev/disk3s1 - /dev/disk3 - /dev/disk3s2 - ], - ) - end - end - - context "given an empty input" do - let(:input) { "" } - - it { is_expected.to be_nil } - end - end -end