aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test/test_resource.rb
diff options
context:
space:
mode:
authorMarkus Reiter2016-10-21 08:57:39 +0200
committerMarkus Reiter2016-11-16 23:52:37 +0100
commit6b6b27126d7ecc1dde9a6bc166a7e1daa3af35d2 (patch)
tree60fcf247ce650e96a0d8f5588cd1a8d79d57aeb8 /Library/Homebrew/test/test_resource.rb
parentedf042ee97f80955b077724119e717a51eb25e29 (diff)
downloadbrew-6b6b27126d7ecc1dde9a6bc166a7e1daa3af35d2.tar.bz2
Reorder and rename test files.
Diffstat (limited to 'Library/Homebrew/test/test_resource.rb')
-rw-r--r--Library/Homebrew/test/test_resource.rb132
1 files changed, 0 insertions, 132 deletions
diff --git a/Library/Homebrew/test/test_resource.rb b/Library/Homebrew/test/test_resource.rb
deleted file mode 100644
index c1b526cb2..000000000
--- a/Library/Homebrew/test/test_resource.rb
+++ /dev/null
@@ -1,132 +0,0 @@
-require "testing_env"
-require "resource"
-
-class ResourceTests < Homebrew::TestCase
- def setup
- @resource = Resource.new("test")
- end
-
- def test_url
- @resource.url("foo")
- assert_equal "foo", @resource.url
- end
-
- def test_url_with_specs
- @resource.url("foo", branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- end
-
- def test_url_with_custom_download_strategy_class
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy)
- assert_equal "foo", @resource.url
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_specs_and_download_strategy
- strategy = Class.new(AbstractDownloadStrategy)
- @resource.url("foo", using: strategy, branch: "master")
- assert_equal "foo", @resource.url
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_url_with_custom_download_strategy_symbol
- @resource.url("foo", using: :git)
- assert_equal "foo", @resource.url
- assert_equal GitDownloadStrategy, @resource.download_strategy
- end
-
- def test_raises_for_unknown_download_strategy_class
- assert_raises(TypeError) { @resource.url("foo", using: Class.new) }
- end
-
- def test_does_not_mutate_specs_hash
- specs = { using: :git, branch: "master" }
- @resource.url("foo", specs)
- assert_equal({ branch: "master" }, @resource.specs)
- assert_equal(:git, @resource.using)
- assert_equal({ using: :git, branch: "master" }, specs)
- end
-
- def test_version
- @resource.version("1.0")
- assert_version_equal "1.0", @resource.version
- refute_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_from_url
- @resource.url("http://example.com/foo-1.0.tar.gz")
- assert_version_equal "1.0", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_version_with_scheme
- klass = Class.new(Version)
- @resource.version klass.new("1.0")
- assert_version_equal "1.0", @resource.version
- assert_instance_of klass, @resource.version
- end
-
- def test_version_from_tag
- @resource.url("http://example.com/foo-1.0.tar.gz", tag: "v1.0.2")
- assert_version_equal "1.0.2", @resource.version
- assert_predicate @resource.version, :detected_from_url?
- end
-
- def test_rejects_non_string_versions
- assert_raises(TypeError) { @resource.version(1) }
- assert_raises(TypeError) { @resource.version(2.0) }
- assert_raises(TypeError) { @resource.version(Object.new) }
- end
-
- def test_version_when_url_is_not_set
- assert_nil @resource.version
- end
-
- def test_mirrors
- assert_empty @resource.mirrors
- @resource.mirror("foo")
- @resource.mirror("bar")
- assert_equal %w[foo bar], @resource.mirrors
- end
-
- def test_checksum_setters
- assert_nil @resource.checksum
- @resource.sha256(TEST_SHA256)
- assert_equal Checksum.new(:sha256, TEST_SHA256), @resource.checksum
- end
-
- def test_download_strategy
- strategy = Object.new
- DownloadStrategyDetector
- .expects(:detect).with("foo", nil).returns(strategy)
- @resource.url("foo")
- assert_equal strategy, @resource.download_strategy
- end
-
- def test_verify_download_integrity_missing
- fn = Pathname.new("test")
-
- fn.stubs(file?: true)
- fn.expects(:verify_checksum).raises(ChecksumMissingError)
- fn.expects(:sha256)
-
- shutup { @resource.verify_download_integrity(fn) }
- end
-
- def test_verify_download_integrity_mismatch
- fn = stub(file?: true)
- checksum = @resource.sha256(TEST_SHA256)
-
- fn.expects(:verify_checksum).with(checksum)
- .raises(ChecksumMismatchError.new(fn, checksum, Object.new))
-
- shutup do
- assert_raises(ChecksumMismatchError) do
- @resource.verify_download_integrity(fn)
- end
- end
- end
-end