PageRenderTime 46ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Library/Homebrew/test/test_software_spec.rb

https://bitbucket.org/mgrimes/homebrew
Ruby | 159 lines | 131 code | 28 blank | 0 comment | 0 complexity | 024836823b4589d907b838a527321a1d 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_mirrors
  53. assert_empty @spec.mirrors
  54. @spec.mirror('foo')
  55. @spec.mirror('bar')
  56. assert_equal 'foo', @spec.mirrors.shift
  57. assert_equal 'bar', @spec.mirrors.shift
  58. end
  59. def test_checksum_setters
  60. assert_nil @spec.checksum
  61. @spec.sha1('baadidea'*5)
  62. assert_equal Checksum.new(:sha1, 'baadidea'*5), @spec.checksum
  63. @spec.sha256('baadidea'*8)
  64. assert_equal Checksum.new(:sha256, 'baadidea'*8), @spec.checksum
  65. end
  66. def test_download_strategy
  67. strategy = Object.new
  68. DownloadStrategyDetector.
  69. expects(:detect).with("foo", nil).returns(strategy)
  70. @spec.url("foo")
  71. assert_equal strategy, @spec.download_strategy
  72. end
  73. def test_verify_download_integrity_missing
  74. fn = Object.new
  75. checksum = @spec.sha1('baadidea'*5)
  76. fn.expects(:verify_checksum).
  77. with(checksum).raises(ChecksumMissingError)
  78. fn.expects(:sha1)
  79. shutup { @spec.verify_download_integrity(fn) }
  80. end
  81. def test_verify_download_integrity_mismatch
  82. fn = Object.new
  83. checksum = @spec.sha1('baadidea'*5)
  84. fn.expects(:verify_checksum).with(checksum).
  85. raises(ChecksumMismatchError.new(checksum, Object.new))
  86. shutup do
  87. assert_raises(ChecksumMismatchError) do
  88. @spec.verify_download_integrity(fn)
  89. end
  90. end
  91. end
  92. end
  93. class HeadSoftwareSpecTests < Test::Unit::TestCase
  94. include VersionAssertions
  95. def setup
  96. @spec = HeadSoftwareSpec.new
  97. end
  98. def test_version
  99. assert_version_equal 'HEAD', @spec.version
  100. end
  101. def test_verify_download_integrity
  102. assert_nil @spec.verify_download_integrity(Object.new)
  103. end
  104. end
  105. class BottleTests < Test::Unit::TestCase
  106. def setup
  107. @spec = Bottle.new
  108. end
  109. def test_checksum_setters
  110. checksums = {
  111. :snow_leopard_32 => 'deadbeef'*5,
  112. :snow_leopard => 'faceb00c'*5,
  113. :lion => 'baadf00d'*5,
  114. :mountain_lion => '8badf00d'*5,
  115. }
  116. checksums.each_pair do |cat, sha1|
  117. @spec.sha1(sha1 => cat)
  118. end
  119. checksums.each_pair do |cat, sha1|
  120. assert_equal Checksum.new(:sha1, sha1),
  121. @spec.instance_variable_get(:@sha1)[cat]
  122. end
  123. end
  124. def test_other_setters
  125. double = Object.new
  126. %w{root_url prefix cellar revision}.each do |method|
  127. @spec.send(method, double)
  128. assert_equal double, @spec.send(method)
  129. end
  130. end
  131. end