From d346dbb3e5acf92941a7d37ebc23b1ab949a5f54 Mon Sep 17 00:00:00 2001 From: jimweirich Date: Fri, 16 Feb 2007 12:14:11 +0000 Subject: [PATCH] Removed some tabs from source. Fixed private methods test in BlankSlate. git-svn-id: svn+ssh://rubyforge.org/var/svn/builder/trunk@99 b15df707-ad1a-0410-81b8-e991873a3486 --- CHANGES | 3 +++ Rakefile | 2 +- lib/blankslate.rb | 15 ++++++----- lib/builder/xmlbase.rb | 54 ++++++++++++++++++++-------------------- lib/builder/xmlmarkup.rb | 48 +++++++++++++++++------------------ test/testblankslate.rb | 40 +++++++++++++++++++++++++---- 6 files changed, 97 insertions(+), 65 deletions(-) diff --git a/CHANGES b/CHANGES index fcc7651..4ff5f49 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/Rakefile b/Rakefile index 90a6b91..0b0966c 100644 --- a/Rakefile +++ b/Rakefile @@ -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'] diff --git a/lib/blankslate.rb b/lib/blankslate.rb index a9851d1..f4c1a65 100644 --- a/lib/blankslate.rb +++ b/lib/blankslate.rb @@ -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 @@ -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 @@ -108,5 +108,4 @@ def append_features(mod) end result end -end - +end \ No newline at end of file diff --git a/lib/builder/xmlbase.rb b/lib/builder/xmlbase.rb index 1161c1c..94a5719 100644 --- a/lib/builder/xmlbase.rb +++ b/lib/builder/xmlbase.rb @@ -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 diff --git a/lib/builder/xmlmarkup.rb b/lib/builder/xmlmarkup.rb index 72083c2..abc5666 100644 --- a/lib/builder/xmlmarkup.rb +++ b/lib/builder/xmlmarkup.rb @@ -209,18 +209,18 @@ def declare!(inst, *args, &block) _indent @target << "" _newline @@ -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( - "", - nil, - attrs, - [:version, :encoding, :standalone]) + "", + nil, + attrs, + [:version, :encoding, :standalone]) end # Insert a CDATA section into the XML markup. @@ -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 diff --git a/test/testblankslate.rb b/test/testblankslate.rb index 5d2ffd6..0f5a981 100644 --- a/test/testblankslate.rb +++ b/test/testblankslate.rb @@ -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 } @@ -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