Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. module Abstract
  2. def self.included(base)
  3. base.extend(ClassMethods)
  4. end
  5.  
  6. module ClassMethods
  7. def abstract_methods(*args)
  8. args.each do |name|
  9. class_eval(<<-END, __FILE__, __LINE__)
  10. def #{name}(*args)
  11. raise NotImplementedError.new("You must implement #{name}.")
  12. end
  13. end
  14. end
  15. end
  16. end
  17. end
  18.  
  19. require 'rubygems'
  20. require 'spec'
  21.  
  22. describe "abstract methods" do
  23. before(:each) do
  24. @klass = Class.new do
  25. include Abstract
  26.  
  27. abstract_methods :foo, :bar
  28. end
  29. end
  30.  
  31. it "raises NotImplementedError" do
  32. proc {
  33. @klass.new.foo
  34. }.should raise_error(NotImplementedError)
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement