Permalink
Browse files

Avoid using a global "BlankSlate" class for "AndAnd::BlankSlate"

  • Loading branch information...
foobear committed Mar 8, 2013
1 parent 7c7ccc2 commit 5234c01c2e0722d4ac4d677413c587c5545292c7
Showing with 22 additions and 4 deletions.
  1. +4 −4 lib/andand.rb
  2. +10 −0 test/andand_spec.rb
  3. +8 −0 test/test_helper.rb
@@ -97,9 +97,9 @@ def dont (p = nil)
class Object
include AndAnd::ObjectGoodies
end
unless Module.constants.map { |c| c.to_s }.include?('BlankSlate')
if Module.constants.map { |c| c.to_s }.include?('BasicObject')
unless defined?(::AndAnd::BlankSlate)
if defined?(::BasicObject)
module AndAnd
class BlankSlate < BasicObject
end
@@ -145,4 +145,4 @@ def method_missing(sym, *args, &block)
end
end
end
end
@@ -112,6 +112,16 @@ def to_proc
end
end
describe 'AndAnd::BlankSlate' do
it 'should not respond to Object methods' do
nil.andand.to_s.should == nil
end
it 'should not be based on a global BlankSlate object' do
nil.andand.respond_to?(:method_on_global_blank_slate).should be_false
end
end
class Foo
def frobbish
'fnord'
@@ -1,2 +1,10 @@
class BlankSlate
# A global BlankSlate object. This is bad, because it inherits from Object
# and offers more methods than AndAnd::BlankSlate should offer.
# For example, ActiveSupport creates a global BlankSlate class.
def method_on_global_blank_slate
end
end
require 'test/unit'
require File.dirname(__FILE__) + '/../lib/andand'

0 comments on commit 5234c01

Please sign in to comment.