aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/cask/dsl
diff options
context:
space:
mode:
authorMarkus Reiter2017-03-05 06:31:36 +0100
committerMarkus Reiter2017-03-05 23:08:14 +0100
commit9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2 (patch)
tree43e99a683329471c1dc965dcc92daccb57df7e8d /Library/Homebrew/test/cask/dsl
parent67ec76d1492fbb03959a782a85c4fb985d6a5884 (diff)
downloadbrew-9fc6c7b2be300ff35dc52d80f4dc38d36d52ddc2.tar.bz2
Move Cask specs into `brew tests`.
Diffstat (limited to 'Library/Homebrew/test/cask/dsl')
-rw-r--r--Library/Homebrew/test/cask/dsl/caveats_spec.rb10
-rw-r--r--Library/Homebrew/test/cask/dsl/postflight_spec.rb13
-rw-r--r--Library/Homebrew/test/cask/dsl/preflight_spec.rb13
-rw-r--r--Library/Homebrew/test/cask/dsl/stanza_proxy_spec.rb32
-rw-r--r--Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb8
-rw-r--r--Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb13
-rw-r--r--Library/Homebrew/test/cask/dsl/version_spec.rb232
7 files changed, 321 insertions, 0 deletions
diff --git a/Library/Homebrew/test/cask/dsl/caveats_spec.rb b/Library/Homebrew/test/cask/dsl/caveats_spec.rb
new file mode 100644
index 000000000..aa662e4d0
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/caveats_spec.rb
@@ -0,0 +1,10 @@
+require "test/support/helper/spec/shared_examples/hbc_dsl_base"
+
+describe Hbc::DSL::Caveats, :cask do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:dsl) { Hbc::DSL::Caveats.new(cask) }
+
+ it_behaves_like Hbc::DSL::Base
+
+ # TODO: add tests for Caveats DSL methods
+end
diff --git a/Library/Homebrew/test/cask/dsl/postflight_spec.rb b/Library/Homebrew/test/cask/dsl/postflight_spec.rb
new file mode 100644
index 000000000..d2b080ca3
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/postflight_spec.rb
@@ -0,0 +1,13 @@
+require "test/support/helper/spec/shared_examples/hbc_dsl_base"
+require "test/support/helper/spec/shared_examples/hbc_staged"
+
+describe Hbc::DSL::Postflight, :cask do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:dsl) { Hbc::DSL::Postflight.new(cask, Hbc::FakeSystemCommand) }
+
+ it_behaves_like Hbc::DSL::Base
+
+ it_behaves_like Hbc::Staged do
+ let(:staged) { dsl }
+ end
+end
diff --git a/Library/Homebrew/test/cask/dsl/preflight_spec.rb b/Library/Homebrew/test/cask/dsl/preflight_spec.rb
new file mode 100644
index 000000000..b93be95ff
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/preflight_spec.rb
@@ -0,0 +1,13 @@
+require "test/support/helper/spec/shared_examples/hbc_dsl_base"
+require "test/support/helper/spec/shared_examples/hbc_staged"
+
+describe Hbc::DSL::Preflight, :cask do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:dsl) { Hbc::DSL::Preflight.new(cask, Hbc::FakeSystemCommand) }
+
+ it_behaves_like Hbc::DSL::Base
+
+ it_behaves_like Hbc::Staged do
+ let(:staged) { dsl }
+ end
+end
diff --git a/Library/Homebrew/test/cask/dsl/stanza_proxy_spec.rb b/Library/Homebrew/test/cask/dsl/stanza_proxy_spec.rb
new file mode 100644
index 000000000..2bb7ae633
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/stanza_proxy_spec.rb
@@ -0,0 +1,32 @@
+describe Hbc::DSL::StanzaProxy do
+ let(:stanza_proxy) {
+ described_class.new(Array) { [:foo, :bar, :cake] }
+ }
+
+ subject { stanza_proxy }
+ it { is_expected.to be_a_proxy }
+ it { is_expected.to respond_to(:pop) }
+ its(:pop) { is_expected.to eq(:cake) }
+ its(:type) { is_expected.to eq(Array) }
+ its(:to_s) { is_expected.to eq("[:foo, :bar, :cake]") }
+
+ describe "when initialized" do
+ let(:initializing) {
+ proc { |b| described_class.new(Array, &b) }
+ }
+
+ it "does not evaluate the block" do
+ expect(&initializing).not_to yield_control
+ end
+ end
+
+ describe "when receiving a message" do
+ let(:receiving_a_message) {
+ proc { |b| described_class.new(Array, &b).to_s }
+ }
+
+ it "evaluates the block" do
+ expect(&receiving_a_message).to yield_with_no_args
+ end
+ end
+end
diff --git a/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb
new file mode 100644
index 000000000..f89a181ce
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/uninstall_postflight_spec.rb
@@ -0,0 +1,8 @@
+require "test/support/helper/spec/shared_examples/hbc_dsl_base"
+
+describe Hbc::DSL::UninstallPostflight, :cask do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:dsl) { Hbc::DSL::UninstallPostflight.new(cask, Hbc::FakeSystemCommand) }
+
+ it_behaves_like Hbc::DSL::Base
+end
diff --git a/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb
new file mode 100644
index 000000000..15a0ea156
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/uninstall_preflight_spec.rb
@@ -0,0 +1,13 @@
+require "test/support/helper/spec/shared_examples/hbc_dsl_base"
+require "test/support/helper/spec/shared_examples/hbc_staged"
+
+describe Hbc::DSL::UninstallPreflight, :cask do
+ let(:cask) { Hbc::CaskLoader.load_from_file(TEST_FIXTURE_DIR/"cask/Casks/basic-cask.rb") }
+ let(:dsl) { Hbc::DSL::UninstallPreflight.new(cask, Hbc::FakeSystemCommand) }
+
+ it_behaves_like Hbc::DSL::Base
+
+ it_behaves_like Hbc::Staged do
+ let(:staged) { dsl }
+ end
+end
diff --git a/Library/Homebrew/test/cask/dsl/version_spec.rb b/Library/Homebrew/test/cask/dsl/version_spec.rb
new file mode 100644
index 000000000..acf3db3ab
--- /dev/null
+++ b/Library/Homebrew/test/cask/dsl/version_spec.rb
@@ -0,0 +1,232 @@
+describe Hbc::DSL::Version do
+ shared_examples "expectations hash" do |input_name, expectations|
+ expectations.each do |input_value, expected_output|
+ context "when #{input_name} is #{input_value.inspect}" do
+ let(input_name.to_sym) { input_value }
+ it { is_expected.to eq expected_output }
+ end
+ end
+ end
+
+ shared_examples "version equality" do
+ let(:raw_version) { "1.2.3" }
+
+ context "when other is nil" do
+ let(:other) { nil }
+ it { is_expected.to be false }
+ end
+
+ context "when other is a String" do
+ context "when other == self.raw_version" do
+ let(:other) { "1.2.3" }
+ it { is_expected.to be true }
+ end
+
+ context "when other != self.raw_version" do
+ let(:other) { "1.2.3.4" }
+ it { is_expected.to be false }
+ end
+ end
+
+ context "when other is a #{described_class}" do
+ context "when other.raw_version == self.raw_version" do
+ let(:other) { described_class.new("1.2.3") }
+ it { is_expected.to be true }
+ end
+
+ context "when other.raw_version != self.raw_version" do
+ let(:other) { described_class.new("1.2.3.4") }
+ it { is_expected.to be false }
+ end
+ end
+ end
+
+ let(:version) { described_class.new(raw_version) }
+
+ describe "#==" do
+ subject { version == other }
+ include_examples "version equality"
+ end
+
+ describe "#eql?" do
+ subject { version.eql?(other) }
+ include_examples "version equality"
+ end
+
+ shared_examples "version expectations hash" do |method, hash|
+ subject { version.send(method) }
+ include_examples "expectations hash", :raw_version,
+ { :latest => "latest",
+ "latest" => "latest",
+ "" => "",
+ nil => "" }.merge(hash)
+ end
+
+ describe "#latest?" do
+ include_examples "version expectations hash", :latest?,
+ :latest => true,
+ "latest" => true,
+ "" => false,
+ nil => false,
+ "1.2.3" => false
+ end
+
+ describe "string manipulation helpers" do
+ describe "#major" do
+ include_examples "version expectations hash", :major,
+ "1" => "1",
+ "1.2" => "1",
+ "1.2.3" => "1",
+ "1.2.3_4-5" => "1"
+ end
+
+ describe "#minor" do
+ include_examples "version expectations hash", :minor,
+ "1" => "",
+ "1.2" => "2",
+ "1.2.3" => "2",
+ "1.2.3_4-5" => "2"
+ end
+
+ describe "#patch" do
+ include_examples "version expectations hash", :patch,
+ "1" => "",
+ "1.2" => "",
+ "1.2.3" => "3",
+ "1.2.3_4-5" => "3"
+ end
+
+ describe "#major_minor" do
+ include_examples "version expectations hash", :major_minor,
+ "1" => "1",
+ "1.2" => "1.2",
+ "1.2.3" => "1.2",
+ "1.2.3_4-5" => "1.2"
+ end
+
+ describe "#major_minor_patch" do
+ include_examples "version expectations hash", :major_minor_patch,
+ "1" => "1",
+ "1.2" => "1.2",
+ "1.2.3" => "1.2.3",
+ "1.2.3_4-5" => "1.2.3"
+ end
+
+ describe "#before_comma" do
+ include_examples "version expectations hash", :before_comma,
+ "1.2.3" => "1.2.3",
+ "1.2.3," => "1.2.3",
+ ",abc" => "",
+ "1.2.3,abc" => "1.2.3"
+ end
+
+ describe "#after_comma" do
+ include_examples "version expectations hash", :after_comma,
+ "1.2.3" => "",
+ "1.2.3," => "",
+ ",abc" => "abc",
+ "1.2.3,abc" => "abc"
+ end
+
+ describe "#before_colon" do
+ include_examples "version expectations hash", :before_colon,
+ "1.2.3" => "1.2.3",
+ "1.2.3:" => "1.2.3",
+ ":abc" => "",
+ "1.2.3:abc" => "1.2.3"
+ end
+
+ describe "#after_colon" do
+ include_examples "version expectations hash", :after_colon,
+ "1.2.3" => "",
+ "1.2.3:" => "",
+ ":abc" => "abc",
+ "1.2.3:abc" => "abc"
+ end
+
+ describe "#dots_to_hyphens" do
+ include_examples "version expectations hash", :dots_to_hyphens,
+ "1.2.3_4-5" => "1-2-3_4-5"
+ end
+
+ describe "#dots_to_underscores" do
+ include_examples "version expectations hash", :dots_to_underscores,
+ "1.2.3_4-5" => "1_2_3_4-5"
+ end
+
+ describe "#dots_to_slashes" do
+ include_examples "version expectations hash", :dots_to_slashes,
+ "1.2.3_4-5" => "1/2/3_4-5"
+ end
+
+ describe "#hyphens_to_dots" do
+ include_examples "version expectations hash", :hyphens_to_dots,
+ "1.2.3_4-5" => "1.2.3_4.5"
+ end
+
+ describe "#hyphens_to_underscores" do
+ include_examples "version expectations hash", :hyphens_to_underscores,
+ "1.2.3_4-5" => "1.2.3_4_5"
+ end
+
+ describe "#hyphens_to_slashes" do
+ include_examples "version expectations hash", :hyphens_to_slashes,
+ "1.2.3_4-5" => "1.2.3_4/5"
+ end
+
+ describe "#underscores_to_dots" do
+ include_examples "version expectations hash", :underscores_to_dots,
+ "1.2.3_4-5" => "1.2.3.4-5"
+ end
+
+ describe "#underscores_to_hyphens" do
+ include_examples "version expectations hash", :underscores_to_hyphens,
+ "1.2.3_4-5" => "1.2.3-4-5"
+ end
+
+ describe "#underscores_to_slashes" do
+ include_examples "version expectations hash", :underscores_to_slashes,
+ "1.2.3_4-5" => "1.2.3/4-5"
+ end
+
+ describe "#slashes_to_dots" do
+ include_examples "version expectations hash", :slashes_to_dots,
+ "1.2.3/abc" => "1.2.3.abc"
+ end
+
+ describe "#slashes_to_hyphens" do
+ include_examples "version expectations hash", :slashes_to_hyphens,
+ "1.2.3/abc" => "1.2.3-abc"
+ end
+
+ describe "#slashes_to_underscores" do
+ include_examples "version expectations hash", :slashes_to_underscores,
+ "1.2.3/abc" => "1.2.3_abc"
+ end
+
+ describe "#no_dots" do
+ include_examples "version expectations hash", :no_dots,
+ "1.2.3_4-5" => "123_4-5"
+ end
+
+ describe "#no_hyphens" do
+ include_examples "version expectations hash", :no_hyphens,
+ "1.2.3_4-5" => "1.2.3_45"
+ end
+
+ describe "#no_underscores" do
+ include_examples "version expectations hash", :no_underscores,
+ "1.2.3_4-5" => "1.2.34-5"
+ end
+
+ describe "#no_slashes" do
+ include_examples "version expectations hash", :no_slashes,
+ "1.2.3/abc" => "1.2.3abc"
+ end
+
+ describe "#no_dividers" do
+ include_examples "version expectations hash", :no_dividers,
+ "1.2.3_4-5" => "12345"
+ end
+ end
+end