Skip to content

Commit

Permalink
Removed some tabs from source. Fixed private methods test in BlankSlate.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/builder/trunk@99 b15df707-ad1a-0410-81b8-e991873a3486
  • Loading branch information
jimweirich committed Feb 16, 2007
1 parent 61c236d commit d346dbb
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 65 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -5,6 +5,9 @@
* Fixed typo in XmlMarkup class docs (ident => indent). (from Martin
Fowler).
* Removed extra directory indirection from legacy CVS to SVN move.
* Removed some extraneous tabs from source.
* Fixed test on private methods in blankslate to differentiate between
targetted and untargetted private methods.

== Version 2.1.0

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -21,7 +21,7 @@ end

CLOBBER.include('pkg')

CURRENT_VERSION = '2.0.0.99'
CURRENT_VERSION = '2.0.1.1'
PKG_VERSION = ENV['REL'] ? ENV['REL'] : CURRENT_VERSION

SRC_RB = FileList['lib/**/*.rb']
Expand Down
15 changes: 7 additions & 8 deletions lib/blankslate.rb
Expand Up @@ -21,10 +21,10 @@ class << self
# hide +instance_eval+ or any method beginning with "__".
def hide(name)
if instance_methods.include?(name.to_s) and
name !~ /^(__|instance_eval)/
@hidden_methods ||= {}
@hidden_methods[name.to_sym] = instance_method(name)
undef_method name
name !~ /^(__|instance_eval)/
@hidden_methods ||= {}
@hidden_methods[name.to_sym] = instance_method(name)
undef_method name
end
end

Expand All @@ -38,8 +38,8 @@ def reveal(name)
unbound_method = find_hidden_method(name)
fail "Don't know how to reveal method '#{name}'" unless unbound_method
define_method(name) do |*args|
bound_method ||= unbound_method.bind(self)
bound_method.call(*args)
bound_method ||= unbound_method.bind(self)
bound_method.call(*args)
end
end
end
Expand Down Expand Up @@ -108,5 +108,4 @@ def append_features(mod)
end
result
end
end

end
54 changes: 27 additions & 27 deletions lib/builder/xmlbase.rb
Expand Up @@ -39,37 +39,37 @@ def method_missing(sym, *args, &block)
attrs = nil
sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
args.each do |arg|
case arg
when Hash
attrs ||= {}
attrs.merge!(arg)
else
text ||= ''
text << arg.to_s
end
case arg
when Hash
attrs ||= {}
attrs.merge!(arg)
else
text ||= ''
text << arg.to_s
end
end
if block
unless text.nil?
raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
end
_capture_outer_self(block) if @self.nil?
_indent
_start_tag(sym, attrs)
_newline
_nested_structures(block)
_indent
_end_tag(sym)
_newline
unless text.nil?
raise ArgumentError, "XmlMarkup cannot mix a text argument with a block"
end
_capture_outer_self(block) if @self.nil?
_indent
_start_tag(sym, attrs)
_newline
_nested_structures(block)
_indent
_end_tag(sym)
_newline
elsif text.nil?
_indent
_start_tag(sym, attrs, true)
_newline
_indent
_start_tag(sym, attrs, true)
_newline
else
_indent
_start_tag(sym, attrs)
text! text
_end_tag(sym)
_newline
_indent
_start_tag(sym, attrs)
text! text
_end_tag(sym)
_newline
end
@target
end
Expand Down
48 changes: 24 additions & 24 deletions lib/builder/xmlmarkup.rb
Expand Up @@ -209,18 +209,18 @@ def declare!(inst, *args, &block)
_indent
@target << "<!#{inst}"
args.each do |arg|
case arg
when String
@target << %{ "#{arg}"} # " WART
when Symbol
@target << " #{arg}"
end
case arg
when String
@target << %{ "#{arg}"} # " WART
when Symbol
@target << " #{arg}"
end
end
if block_given?
@target << " ["
_newline
_nested_structures(block)
@target << "]"
@target << " ["
_newline
_nested_structures(block)
@target << "]"
end
@target << ">"
_newline
Expand All @@ -238,15 +238,15 @@ def declare!(inst, *args, &block)
def instruct!(directive_tag=:xml, attrs={})
_ensure_no_block block_given?
if directive_tag == :xml
a = { :version=>"1.0", :encoding=>"UTF-8" }
attrs = a.merge attrs
a = { :version=>"1.0", :encoding=>"UTF-8" }
attrs = a.merge attrs
end
_special(
"<?#{directive_tag}",
"?>",
nil,
attrs,
[:version, :encoding, :standalone])
"<?#{directive_tag}",
"?>",
nil,
attrs,
[:version, :encoding, :standalone])
end

# Insert a CDATA section into the XML markup.
Expand Down Expand Up @@ -299,27 +299,27 @@ def _end_tag(sym)
def _insert_attributes(attrs, order=[])
return if attrs.nil?
order.each do |k|
v = attrs[k]
@target << %{ #{k}="#{_attr_value(v)}"} if v # " WART
v = attrs[k]
@target << %{ #{k}="#{_attr_value(v)}"} if v # " WART
end
attrs.each do |k, v|
@target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) # " WART
@target << %{ #{k}="#{_attr_value(v)}"} unless order.member?(k) # " WART
end
end

def _attr_value(value)
case value
when Symbol
value.to_s
value.to_s
else
_escape_quote(value.to_s)
_escape_quote(value.to_s)
end
end

def _ensure_no_block(got_block)
if got_block
fail IllegalBlockError,
"Blocks are not allowed on XML instructions"
fail IllegalBlockError,
"Blocks are not allowed on XML instructions"
end
end

Expand Down
40 changes: 35 additions & 5 deletions test/testblankslate.rb
Expand Up @@ -62,16 +62,46 @@ class TestBlankSlate < Test::Unit::TestCase
def setup
@bs = BlankSlate.new
end

def test_create
assert nil != @bs
end

def test_undefined_methods_remain_undefined
assert_raise(NoMethodError) { @bs.no_such_method }
assert_raise(NoMethodError) { @bs.nil? }
end


# NOTE: NameError is acceptable because the lack of a '.' means that
# Ruby can't tell if it is a method or a local variable.
def test_undefined_methods_remain_undefined_during_instance_eval
assert_raise(NoMethodError, NameError) do
@bs.instance_eval do nil? end
end
assert_raise(NoMethodError, NameError) do
@bs.instance_eval do no_such_method end
end
end

def test_private_methods_are_undefined
assert_raise(NoMethodError) do
@bs.puts "HI"
end
end

def test_targetted_private_methods_are_undefined_during_instance_eval
assert_raise(NoMethodError, NameError) do
@bs.instance_eval do self.puts "HI" end
end
end

def test_untargetted_private_methods_are_defined_during_instance_eval
oldstdout = $stdout
$stdout = StringIO.new
@bs.instance_eval do
puts "HI"
end
ensure
$stdout = oldstdout
end

def test_methods_added_late_to_kernel_remain_undefined
assert_equal 1234, nil.late_addition
assert_raise(NoMethodError) { @bs.late_addition }
Expand Down Expand Up @@ -119,7 +149,7 @@ def test_revealing_a_hidden_method_twice_is_ok
def test_revealing_unknown_hidden_method_is_an_error
assert_raises(RuntimeError) do
Class.new(BlankSlate) do
reveal :xyz
reveal :xyz
end
end
end
Expand Down

0 comments on commit d346dbb

Please sign in to comment.