PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Library/Homebrew/test/test_software_spec.rb

https://bitbucket.org/cocoatomo/homebrew
Ruby | 171 lines | 141 code | 30 blank | 0 comment | 0 complexity | a95b93f9244cb04dfee9e7e76f079624 MD5 | raw file
  1. require 'testing_env'
  2. require 'formula_support'
  3. require 'bottles'
  4. class SoftwareSpecTests < Test::Unit::TestCase
  5. include VersionAssertions
  6. def setup
  7. @spec = SoftwareSpec.new
  8. end
  9. def test_url
  10. @spec.url('foo')
  11. assert_equal 'foo', @spec.url
  12. end
  13. def test_url_with_specs
  14. @spec.url('foo', :branch => 'master')
  15. assert_equal 'foo', @spec.url
  16. assert_equal({ :branch => 'master' }, @spec.specs)
  17. end
  18. def test_url_with_custom_download_strategy_class
  19. strategy = Class.new(AbstractDownloadStrategy)
  20. @spec.url('foo', :using => strategy)
  21. assert_equal 'foo', @spec.url
  22. assert_equal strategy, @spec.download_strategy
  23. end
  24. def test_url_with_specs_and_download_strategy
  25. strategy = Class.new(AbstractDownloadStrategy)
  26. @spec.url('foo', :using => strategy, :branch => 'master')
  27. assert_equal 'foo', @spec.url
  28. assert_equal({ :branch => 'master' }, @spec.specs)
  29. assert_equal strategy, @spec.download_strategy
  30. end
  31. def test_url_with_custom_download_strategy_symbol
  32. @spec.url('foo', :using => :git)
  33. assert_equal 'foo', @spec.url
  34. assert_equal GitDownloadStrategy, @spec.download_strategy
  35. end
  36. def test_version
  37. @spec.version('1.0')
  38. assert_version_equal '1.0', @spec.version
  39. assert !@spec.version.detected_from_url?
  40. end
  41. def test_version_from_url
  42. @spec.url('http://foo.com/bar-1.0.tar.gz')
  43. assert_version_equal '1.0', @spec.version
  44. assert @spec.version.detected_from_url?
  45. end
  46. def test_version_with_scheme
  47. scheme = Class.new(Version)
  48. @spec.version('1.0' => scheme)
  49. assert_version_equal '1.0', @spec.version
  50. assert_instance_of scheme, @spec.version
  51. end
  52. def test_version_from_tag
  53. @spec.url('http://foo.com/bar-1.0.tar.gz', :tag => 'v1.0.2')
  54. assert_version_equal '1.0.2', @spec.version
  55. assert @spec.version.detected_from_url?
  56. end
  57. def test_rejects_non_string_versions
  58. assert_raises(TypeError) { @spec.version(1) }
  59. assert_raises(TypeError) { @spec.version(2.0) }
  60. assert_raises(TypeError) { @spec.version(Object.new) }
  61. end
  62. def test_mirrors
  63. assert_empty @spec.mirrors
  64. @spec.mirror('foo')
  65. @spec.mirror('bar')
  66. assert_equal 'foo', @spec.mirrors.shift
  67. assert_equal 'bar', @spec.mirrors.shift
  68. end
  69. def test_checksum_setters
  70. assert_nil @spec.checksum
  71. @spec.sha1('baadidea'*5)
  72. assert_equal Checksum.new(:sha1, 'baadidea'*5), @spec.checksum
  73. @spec.sha256('baadidea'*8)
  74. assert_equal Checksum.new(:sha256, 'baadidea'*8), @spec.checksum
  75. end
  76. def test_download_strategy
  77. strategy = Object.new
  78. DownloadStrategyDetector.
  79. expects(:detect).with("foo", nil).returns(strategy)
  80. @spec.url("foo")
  81. assert_equal strategy, @spec.download_strategy
  82. end
  83. def test_verify_download_integrity_missing
  84. fn = Object.new
  85. checksum = @spec.sha1('baadidea'*5)
  86. fn.expects(:verify_checksum).
  87. with(checksum).raises(ChecksumMissingError)
  88. fn.expects(:sha1)
  89. shutup { @spec.verify_download_integrity(fn) }
  90. end
  91. def test_verify_download_integrity_mismatch
  92. fn = Object.new
  93. checksum = @spec.sha1('baadidea'*5)
  94. fn.expects(:verify_checksum).with(checksum).
  95. raises(ChecksumMismatchError.new(checksum, Object.new))
  96. shutup do
  97. assert_raises(ChecksumMismatchError) do
  98. @spec.verify_download_integrity(fn)
  99. end
  100. end
  101. end
  102. end
  103. class HeadSoftwareSpecTests < Test::Unit::TestCase
  104. include VersionAssertions
  105. def setup
  106. @spec = HeadSoftwareSpec.new
  107. end
  108. def test_version
  109. assert_version_equal 'HEAD', @spec.version
  110. end
  111. def test_verify_download_integrity
  112. assert_nil @spec.verify_download_integrity(Object.new)
  113. end
  114. end
  115. class BottleTests < Test::Unit::TestCase
  116. def setup
  117. @spec = Bottle.new
  118. end
  119. def test_checksum_setters
  120. checksums = {
  121. :snow_leopard_32 => 'deadbeef'*5,
  122. :snow_leopard => 'faceb00c'*5,
  123. :lion => 'baadf00d'*5,
  124. :mountain_lion => '8badf00d'*5,
  125. }
  126. checksums.each_pair do |cat, sha1|
  127. @spec.sha1(sha1 => cat)
  128. end
  129. checksums.each_pair do |cat, sha1|
  130. assert_equal Checksum.new(:sha1, sha1),
  131. @spec.instance_variable_get(:@sha1)[cat]
  132. end
  133. end
  134. def test_other_setters
  135. double = Object.new
  136. %w{root_url prefix cellar revision}.each do |method|
  137. @spec.send(method, double)
  138. assert_equal double, @spec.send(method)
  139. end
  140. end
  141. end