PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/rubygems-0.8.11/test/test_format.rb

https://bitbucket.org/redricko/pragprog-scripting
Ruby | 75 lines | 54 code | 9 blank | 12 comment | 0 complexity | 21eec38f70927b4bd403a1c3f348d0ce MD5 | raw file
  1. #---
  2. # Excerpted from "Everyday Scripting in Ruby"
  3. # We make no guarantees that this code is fit for any purpose.
  4. # Visit http://www.pragmaticprogrammer.com/titles/bmsft for more book information.
  5. #---
  6. require 'rubygems'
  7. Gem::manage_gems
  8. require 'test/unit'
  9. require 'stringio'
  10. class TestFormat < Test::Unit::TestCase
  11. def setup
  12. require File.dirname(__FILE__) + "/simple_gem.rb"
  13. @simple_gem = SIMPLE_GEM
  14. end
  15. def test_garbled_gem_throws_format_exception
  16. assert_raises(RuntimeError) {
  17. # subtly bogus input
  18. Gem::Format.from_io(StringIO.new(@simple_gem.upcase))
  19. }
  20. assert_raises(RuntimeError) {
  21. # Totally bogus input
  22. Gem::Format.from_io(StringIO.new(@simple_gem.reverse))
  23. }
  24. assert_raises(RuntimeError) {
  25. # This was intentionally screws up YAML parsing.
  26. Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
  27. }
  28. end
  29. def test_passing_nonexistent_files_throws_sensible_exception
  30. assert_raises(Gem::Exception) {
  31. Gem::Format.from_file_by_path("/this/path/almost/definitely/will/not/exist")
  32. }
  33. end
  34. end
  35. class TestOldFormat # < Test::Unit::TestCase
  36. def setup
  37. require File.dirname(__FILE__) + "/simple_gem.rb"
  38. @simple_gem = SIMPLE_GEM
  39. end
  40. def test_from_io_returns_format_object
  41. format = Gem::OldFormat.from_io(StringIO.new(@simple_gem))
  42. assert_equal(Gem::OldFormat, format.class)
  43. assert_equal(Gem::Specification, format.spec.class)
  44. # simple_gem.rb's gem has 3 files in it
  45. assert_equal(3, format.file_entries.size)
  46. end
  47. def test_garbled_gem_throws_format_exception
  48. assert_raises(RuntimeError) {
  49. # subtly bogus input
  50. Gem::OldFormat.from_io(StringIO.new(@simple_gem.upcase))
  51. }
  52. assert_raises(RuntimeError) {
  53. # Totally bogus input
  54. Gem::OldFormat.from_io(StringIO.new(@simple_gem.reverse))
  55. }
  56. assert_raises(RuntimeError) {
  57. # This was intentionally screws up YAML parsing.
  58. Gem::OldFormat.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom")))
  59. }
  60. end
  61. def test_passing_nonexistent_files_throws_sensible_exception
  62. assert_raises(Gem::Exception) {
  63. Gem::OldFormat.from_file_by_path("/this/path/almost/definitely/will/not/exist")
  64. }
  65. end
  66. end