Guest User

Untitled

a guest
Apr 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. ## The relevant code
  2. module Attrist
  3.  
  4. class ::Module
  5. alias_method :__public__, :public
  6. alias_method :__private__, :private
  7. alias_method :__protected__, :protected
  8.  
  9. def public(*args)
  10. @__access__ = :public
  11. __public__(*args)
  12. end
  13.  
  14. def private(*args)
  15. @__access__ = :private
  16. __private__(*args)
  17. end
  18.  
  19. def protected(*args)
  20. @__access__ = :protected
  21. __protected__(*args)
  22. end
  23. end
  24. end
  25.  
  26. ## The relevant specs
  27. require File.join( File.dirname(__FILE__), "..", "spec_helper" )
  28. require 'attrist'
  29.  
  30. describe Attrist do
  31. before(:each) do
  32. module AttristSpecHelper; end
  33. class AttristSpecHelperClass
  34. include AttristSpecHelper
  35. end
  36. end
  37.  
  38. describe '-', Module do
  39.  
  40. describe '#private' do
  41. it "should allow access to the current access level" do
  42. module AttristSpecHelper
  43. private
  44. @__access__.should == :private
  45. end
  46. end
  47.  
  48. it "shouldn't mess with normal functionality" do
  49. class AttristSpecHelperClass
  50. def a; end
  51. private :a
  52.  
  53. private
  54. def b; end
  55. end
  56.  
  57. @helper = AttristSpecHelperClass.new
  58. # pending('Doesn\'t let private work normally in the second case')
  59. lambda { @helper.a }.should raise_error(NoMethodError,
  60. /private method .a. called /)
  61. lambda { @helper.b }.should raise_error(NoMethodError,
  62. /private method .b. called /)
  63. end
  64. end
  65.  
  66. describe '#protected' do
  67. it "should allow access to the current access level" do
  68. module AttristSpecHelper
  69. protected
  70. @__access__.should == :protected
  71. end
  72. end
  73.  
  74. it "shouldn't mess with normal functionality" do
  75. class AttristSpecHelperClass
  76. def a; end
  77. protected :a
  78.  
  79. protected
  80. def b; end
  81. end
  82.  
  83. @helper = AttristSpecHelperClass.new
  84. # pending('Doesn\'t let protected work normally in the second case')
  85. lambda { @helper.a }.should raise_error(NoMethodError,
  86. /protected method .a. called /)
  87. lambda { @helper.b }.should raise_error(NoMethodError,
  88. /protected method .b. called /)
  89. end
  90. end
  91.  
  92. describe '#public' do
  93. it "should allow access to the current access level" do
  94. module AttristSpecHelper
  95. private
  96. public
  97. @__access__.should == :public
  98. end
  99. end
  100.  
  101. it "shouldn't mess with normal functionality" do
  102. class AttristSpecHelperClass
  103. private
  104. def a; end
  105. public :a
  106.  
  107. private
  108. public
  109. def b; end
  110. end
  111.  
  112. @helper = AttristSpecHelperClass.new
  113. lambda { @helper.a }.should_not raise_error
  114. lambda { @helper.b }.should_not raise_error
  115. end
  116. end
  117.  
  118. end
  119.  
  120. after(:each) do
  121. Object.send(:remove_const, :AttristSpecHelper)
  122. Object.send(:remove_const, :AttristSpecHelperClass)
  123. end
  124. end
Add Comment
Please, Sign In to add comment