diff options
| author | Markus Reiter | 2017-02-08 07:50:42 +0100 |
|---|---|---|
| committer | Markus Reiter | 2017-02-10 17:19:19 +0100 |
| commit | fe0b68a5ad76bc3a91518f54a97bdd7a9144eda5 (patch) | |
| tree | 4233a90fb48487c16f117f6accf1492fa14d9056 /Library | |
| parent | 943959b4f2b127496488cf8bf5544cc7ddc410b0 (diff) | |
| download | brew-fe0b68a5ad76bc3a91518f54a97bdd7a9144eda5.tar.bz2 | |
Convert `Plist` test to spec.
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cask/spec/plist/parser_spec.rb | 75 | ||||
| -rw-r--r-- | Library/Homebrew/cask/test/plist/parser_test.rb | 65 |
2 files changed, 75 insertions, 65 deletions
diff --git a/Library/Homebrew/cask/spec/plist/parser_spec.rb b/Library/Homebrew/cask/spec/plist/parser_spec.rb new file mode 100644 index 000000000..9d4a59fdc --- /dev/null +++ b/Library/Homebrew/cask/spec/plist/parser_spec.rb @@ -0,0 +1,75 @@ +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 + <?xml version="1.0" encoding="UTF-8"?> + <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> + <plist version="1.0"> + <dict> + <key>system-entities</key> + <array> + <dict> + <key>content-hint</key> + <string>Apple_partition_map</string> + <key>dev-entry</key> + <string>/dev/disk3s1</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_map</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_partition_scheme</string> + <key>dev-entry</key> + <string>/dev/disk3</string> + <key>potentially-mountable</key> + <false/> + <key>unmapped-content-hint</key> + <string>Apple_partition_scheme</string> + </dict> + <dict> + <key>content-hint</key> + <string>Apple_HFS</string> + <key>dev-entry</key> + <string>/dev/disk3s2</string> + <key>mount-point</key> + <string>/private/tmp/dmg.BhfS2g</string> + <key>potentially-mountable</key> + <true/> + <key>unmapped-content-hint</key> + <string>Apple_HFS</string> + <key>volume-kind</key> + <string>hfs</string> + </dict> + </array> + </dict> + </plist> + 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 diff --git a/Library/Homebrew/cask/test/plist/parser_test.rb b/Library/Homebrew/cask/test/plist/parser_test.rb deleted file mode 100644 index 7f844e377..000000000 --- a/Library/Homebrew/cask/test/plist/parser_test.rb +++ /dev/null @@ -1,65 +0,0 @@ -require "test_helper" - -describe Plist do - it "parses some hdiutil output okay" do - hdiutil_output = <<-EOS.undent - <?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> - <plist version="1.0"> - <dict> - <key>system-entities</key> - <array> - <dict> - <key>content-hint</key> - <string>Apple_partition_map</string> - <key>dev-entry</key> - <string>/dev/disk3s1</string> - <key>potentially-mountable</key> - <false/> - <key>unmapped-content-hint</key> - <string>Apple_partition_map</string> - </dict> - <dict> - <key>content-hint</key> - <string>Apple_partition_scheme</string> - <key>dev-entry</key> - <string>/dev/disk3</string> - <key>potentially-mountable</key> - <false/> - <key>unmapped-content-hint</key> - <string>Apple_partition_scheme</string> - </dict> - <dict> - <key>content-hint</key> - <string>Apple_HFS</string> - <key>dev-entry</key> - <string>/dev/disk3s2</string> - <key>mount-point</key> - <string>/private/tmp/dmg.BhfS2g</string> - <key>potentially-mountable</key> - <true/> - <key>unmapped-content-hint</key> - <string>Apple_HFS</string> - <key>volume-kind</key> - <string>hfs</string> - </dict> - </array> - </dict> - </plist> - EOS - - parsed = Plist.parse_xml(hdiutil_output) - - parsed.keys.must_equal ["system-entities"] - parsed["system-entities"].length.must_equal 3 - parsed["system-entities"].map { |e| e["dev-entry"] }.must_equal %w[ - /dev/disk3s1 - /dev/disk3 - /dev/disk3s2 - ] - end - - it "does not choke on empty input" do - Plist.parse_xml("").must_equal {} - end -end |
