Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Being able to tackle 'BlankObject instances' when extending:
A BlankObject class is considered not to have meta_class and unextend defined, but does respond to extend (e.g. Liquid::Strainer) See also: http://rubydoc.info/gems/liquid/2.3.0/Liquid/Strainer
- Loading branch information
Paul Engel
committed
Jan 9, 2012
1 parent
a0706ca
commit 7484100
Showing
2 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.expand_path("../test_helper", __FILE__) | ||
|
||
class BlankObjectTest < Test::Unit::TestCase | ||
|
||
# ================================================================================================================================== | ||
# A BlankObject class is considered not to have meta_class and unextend defined, but does respond to extend (e.g. Liquid::Strainer) | ||
# See also: http://rubydoc.info/gems/liquid/2.3.0/Liquid/Strainer | ||
# ================================================================================================================================== | ||
|
||
context "A blank object instance" do | ||
setup do | ||
module Hi | ||
unextendable | ||
def say_hi | ||
"Hi!" | ||
end | ||
end | ||
class BlankObject | ||
def meta_class | ||
raise NoMethodError | ||
end | ||
def unextend | ||
raise NoMethodError | ||
end | ||
def respond_to?(symbol, include_private = false) | ||
return false if %w(meta_class unextend).include? symbol.to_s | ||
super | ||
end | ||
end | ||
end | ||
|
||
should "have extend defined" do | ||
assert BlankObject.new.extend(Hi) | ||
end | ||
|
||
should "not have meta_class and unextend defined" do | ||
assert_raises NoMethodError do | ||
BlankObject.new.meta_class | ||
end | ||
assert_raises NoMethodError do | ||
BlankObject.new.unextend | ||
end | ||
end | ||
|
||
should "be extendable" do | ||
b = BlankObject.new | ||
b.extend Hi | ||
assert_equal "Hi!", b.say_hi | ||
end | ||
end | ||
|
||
end |