Guest User

Untitled

a guest
Feb 21st, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. class SpecReader
  2. module Test
  3. module Unit
  4. class TestCase
  5. end
  6. end
  7. end
  8.  
  9. def initialize
  10. mock
  11. yield self
  12. unmock
  13. end
  14.  
  15. def require(*args)
  16. # don't do anything
  17. end
  18.  
  19. def context(name)
  20. puts name
  21. yield
  22. end
  23.  
  24. def specify(name)
  25. puts "- #{name}"
  26. end
  27.  
  28. def mock
  29. Object.class_eval do
  30. def method_missing_with_spec_reader_mock(*args)
  31. # don't do anything
  32. end
  33.  
  34. alias_method :method_missing_without_spec_reader_mock, :method_missing
  35. alias_method :method_missing, :method_missing_with_spec_reader_mock
  36. end
  37.  
  38. Module.class_eval do
  39. def const_missing_with_spec_reader_mock(*args)
  40. Object
  41. end
  42.  
  43. alias_method :const_missing_without_spec_reader_mock, :const_missing
  44. alias_method :const_missing, :const_missing_with_spec_reader_mock
  45.  
  46. def include_with_spec_reader_mock(*args)
  47. # don't do anything
  48. end
  49.  
  50. alias_method :include_without_spec_reader_mock, :include
  51. alias_method :include, :include_with_spec_reader_mock
  52. end
  53. end
  54.  
  55. def unmock
  56. Object.send(:alias_method, :method_missing, :method_missing_without_spec_reader_mock)
  57. Module.send(:alias_method, :const_missing, :const_missing_without_spec_reader_mock)
  58. Module.send(:alias_method, :include, :include_without_spec_reader_mock)
  59. end
  60. end
  61.  
  62. namespace :spec do
  63. desc "Prints out the specs without running the associated tests"
  64. task :describe do
  65. SpecReader.new do |reader|
  66. Dir[File.dirname(__FILE__) + '/../../../../test/**/*_test.rb'].each do |path|
  67. reader.instance_eval(File.read(path), path, 1)
  68. end
  69. end
  70. end
  71. end
Add Comment
Please, Sign In to add comment