aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Reiter2017-02-20 23:28:13 +0100
committerMarkus Reiter2017-02-21 02:58:38 +0100
commit1be7852493cee7f7af9b31cef4547aca23bebb0b (patch)
treed477b2fdc1676973a82f93f9f9a75961d31b270d
parentbd0a1314c8a2676a69b81ba840fb7ea6e50ae736 (diff)
downloadbrew-1be7852493cee7f7af9b31cef4547aca23bebb0b.tar.bz2
Convert SoftwareSpec test to spec.
-rw-r--r--Library/Homebrew/test/software_spec_spec.rb184
-rw-r--r--Library/Homebrew/test/software_spec_test.rb184
2 files changed, 184 insertions, 184 deletions
diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb
new file mode 100644
index 000000000..5fd4f598a
--- /dev/null
+++ b/Library/Homebrew/test/software_spec_spec.rb
@@ -0,0 +1,184 @@
+require "software_spec"
+
+RSpec::Matchers.alias_matcher :have_defined_resource, :be_resource_defined
+RSpec::Matchers.alias_matcher :have_defined_option, :be_option_defined
+
+describe SoftwareSpec do
+ let(:owner) { double(name: "some_name", full_name: "some_name", tap: "homebrew/core") }
+
+ describe "#resource" do
+ it "defines a resource" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect(subject).to have_defined_resource("foo")
+ end
+
+ it "sets itself to be the resource's owner" do
+ subject.resource("foo") { url "foo-1.0" }
+ subject.owner = owner
+ subject.resources.each_value do |r|
+ expect(r.owner).to eq(subject)
+ end
+ end
+
+ it "receives the owner's version if it has no own version" do
+ subject.url("foo-42")
+ subject.resource("bar") { url "bar" }
+ subject.owner = owner
+
+ expect(subject.resource("bar").version).to eq("42")
+ end
+
+ it "raises an error when duplicate resources are defined" do
+ subject.resource("foo") { url "foo-1.0" }
+ expect {
+ subject.resource("foo") { url "foo-1.0" }
+ }.to raise_error(DuplicateResourceError)
+ end
+
+ it "raises an error when accessing missing resources" do
+ subject.owner = owner
+ expect {
+ subject.resource("foo")
+ }.to raise_error(ResourceMissingError)
+ end
+ end
+
+ describe "#owner" do
+ it "sets the owner" do
+ subject.owner = owner
+ expect(subject.owner).to eq(owner)
+ end
+
+ it "sets the name" do
+ subject.owner = owner
+ expect(subject.name).to eq(owner.name)
+ end
+ end
+
+ describe "#option" do
+ it "defines an option" do
+ subject.option("foo")
+ expect(subject).to have_defined_option("foo")
+ end
+
+ it "raises an error when it begins with dashes" do
+ expect {
+ subject.option("--foo")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "raises an error when name is empty" do
+ expect {
+ subject.option("")
+ }.to raise_error(ArgumentError)
+ end
+
+ it "special cases the cxx11 option" do
+ subject.option(:cxx11)
+ expect(subject).to have_defined_option("c++11")
+ expect(subject).not_to have_defined_option("cxx11")
+ end
+
+ it "supports options with descriptions" do
+ subject.option("bar", "description")
+ expect(subject.options.first.description).to eq("description")
+ end
+
+ it "defaults to an empty string when no description is given" do
+ subject.option("foo")
+ expect(subject.options.first.description).to eq("")
+ end
+ end
+
+ describe "#deprecated_option" do
+ it "allows specifying deprecated options" do
+ subject.deprecated_option("foo" => "bar")
+ expect(subject.deprecated_options).not_to be_empty
+ expect(subject.deprecated_options.first.old).to eq("foo")
+ expect(subject.deprecated_options.first.current).to eq("bar")
+ end
+
+ it "allows specifying deprecated options as a Hash from an Array/String to an Array/String" do
+ subject.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo1", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo2", "bar1"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar2"))
+ expect(subject.deprecated_options).to include(DeprecatedOption.new("foo3", "bar3"))
+ end
+
+ it "raises an error when empty" do
+ expect {
+ subject.deprecated_option({})
+ }.to raise_error(ArgumentError)
+ end
+ end
+
+ describe "#depends_on" do
+ it "allows specifying dependencies" do
+ subject.depends_on("foo")
+ expect(subject.deps.first.name).to eq("foo")
+ end
+
+ it "allows specifying optional dependencies" do
+ subject.depends_on "foo" => :optional
+ expect(subject).to have_defined_option("with-foo")
+ end
+
+ it "allows specifying recommended dependencies" do
+ subject.depends_on "bar" => :recommended
+ expect(subject).to have_defined_option("without-bar")
+ end
+ end
+
+ specify "explicit options override defaupt depends_on option description" do
+ subject.option("with-foo", "blah")
+ subject.depends_on("foo" => :optional)
+ expect(subject.options.first.description).to eq("blah")
+ end
+
+ describe "#patch" do
+ it "adds a patch" do
+ subject.patch(:p1, :DATA)
+ expect(subject.patches.count).to eq(1)
+ expect(subject.patches.first.strip).to eq(:p1)
+ end
+ end
+end
+
+describe HeadSoftwareSpec do
+ specify "#version" do
+ expect(subject.version).to eq(Version.create("HEAD"))
+ end
+
+ specify "#verify_download_integrity" do
+ expect(subject.verify_download_integrity(Object.new)).to be nil
+ end
+end
+
+describe BottleSpecification do
+ specify "#sha256" do
+ checksums = {
+ snow_leopard_32: "deadbeef" * 8,
+ snow_leopard: "faceb00c" * 8,
+ lion: "baadf00d" * 8,
+ mountain_lion: "8badf00d" * 8,
+ }
+
+ checksums.each_pair do |cat, digest|
+ subject.sha256(digest => cat)
+ end
+
+ checksums.each_pair do |cat, digest|
+ checksum, = subject.checksum_for(cat)
+ expect(Checksum.new(:sha256, digest)).to eq(checksum)
+ end
+ end
+
+ %w[root_url prefix cellar rebuild].each do |method|
+ specify "##{method}" do
+ object = Object.new
+ subject.public_send(method, object)
+ expect(subject.public_send(method)).to eq(object)
+ end
+ end
+end
diff --git a/Library/Homebrew/test/software_spec_test.rb b/Library/Homebrew/test/software_spec_test.rb
deleted file mode 100644
index 026265a4a..000000000
--- a/Library/Homebrew/test/software_spec_test.rb
+++ /dev/null
@@ -1,184 +0,0 @@
-require "testing_env"
-require "software_spec"
-
-class SoftwareSpecTests < Homebrew::TestCase
- def setup
- super
- @spec = SoftwareSpec.new
- end
-
- def test_resource
- @spec.resource("foo") { url "foo-1.0" }
- assert @spec.resource_defined?("foo")
- end
-
- def test_raises_when_duplicate_resources_are_defined
- @spec.resource("foo") { url "foo-1.0" }
- assert_raises(DuplicateResourceError) do
- @spec.resource("foo") { url "foo-1.0" }
- end
- end
-
- def test_raises_when_accessing_missing_resources
- @spec.owner = Class.new do
- def name
- "test"
- end
-
- def full_name
- "test"
- end
-
- def tap
- "homebrew/core"
- end
- end.new
- assert_raises(ResourceMissingError) { @spec.resource("foo") }
- end
-
- def test_set_owner
- owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- @spec.owner = owner
- assert_equal owner, @spec.owner
- end
-
- def test_resource_owner
- @spec.resource("foo") { url "foo-1.0" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_equal "some_name", @spec.name
- @spec.resources.each_value { |r| assert_equal @spec, r.owner }
- end
-
- def test_resource_without_version_receives_owners_version
- @spec.url("foo-42")
- @spec.resource("bar") { url "bar" }
- @spec.owner = stub name: "some_name",
- full_name: "some_name",
- tap: "homebrew/core"
- assert_version_equal "42", @spec.resource("bar").version
- end
-
- def test_option
- @spec.option("foo")
- assert @spec.option_defined?("foo")
- end
-
- def test_option_raises_when_begins_with_dashes
- assert_raises(ArgumentError) { @spec.option("--foo") }
- end
-
- def test_option_raises_when_name_empty
- assert_raises(ArgumentError) { @spec.option("") }
- end
-
- def test_cxx11_option_special_case
- @spec.option(:cxx11)
- assert @spec.option_defined?("c++11")
- refute @spec.option_defined?("cxx11")
- end
-
- def test_option_description
- @spec.option("bar", "description")
- assert_equal "description", @spec.options.first.description
- end
-
- def test_option_description_defaults_to_empty_string
- @spec.option("foo")
- assert_equal "", @spec.options.first.description
- end
-
- def test_deprecated_option
- @spec.deprecated_option("foo" => "bar")
- refute_empty @spec.deprecated_options
- assert_equal "foo", @spec.deprecated_options.first.old
- assert_equal "bar", @spec.deprecated_options.first.current
- end
-
- def test_deprecated_options
- @spec.deprecated_option(["foo1", "foo2"] => "bar1", "foo3" => ["bar2", "bar3"])
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo1", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo2", "bar1")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar2")
- assert_includes @spec.deprecated_options, DeprecatedOption.new("foo3", "bar3")
- end
-
- def test_deprecated_option_raises_when_empty
- assert_raises(ArgumentError) { @spec.deprecated_option({}) }
- end
-
- def test_depends_on
- @spec.depends_on("foo")
- assert_equal "foo", @spec.deps.first.name
- end
-
- def test_dependency_option_integration
- @spec.depends_on "foo" => :optional
- @spec.depends_on "bar" => :recommended
- assert @spec.option_defined?("with-foo")
- assert @spec.option_defined?("without-bar")
- end
-
- def test_explicit_options_override_default_dep_option_description
- @spec.option("with-foo", "blah")
- @spec.depends_on("foo" => :optional)
- assert_equal "blah", @spec.options.first.description
- end
-
- def test_patch
- @spec.patch :p1, :DATA
- assert_equal 1, @spec.patches.length
- assert_equal :p1, @spec.patches.first.strip
- end
-end
-
-class HeadSoftwareSpecTests < Homebrew::TestCase
- def setup
- super
- @spec = HeadSoftwareSpec.new
- end
-
- def test_version
- assert_version_equal "HEAD", @spec.version
- end
-
- def test_verify_download_integrity
- assert_nil @spec.verify_download_integrity(Object.new)
- end
-end
-
-class BottleSpecificationTests < Homebrew::TestCase
- def setup
- super
- @spec = BottleSpecification.new
- end
-
- def test_checksum_setters
- checksums = {
- snow_leopard_32: "deadbeef"*8,
- snow_leopard: "faceb00c"*8,
- lion: "baadf00d"*8,
- mountain_lion: "8badf00d"*8,
- }
-
- checksums.each_pair do |cat, digest|
- @spec.sha256(digest => cat)
- end
-
- checksums.each_pair do |cat, digest|
- checksum, = @spec.checksum_for(cat)
- assert_equal Checksum.new(:sha256, digest), checksum
- end
- end
-
- def test_other_setters
- double = Object.new
- %w[root_url prefix cellar rebuild].each do |method|
- @spec.send(method, double)
- assert_equal double, @spec.send(method)
- end
- end
-end