blankslate 2.1.2.4 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Portions copyright 2011 by Bart ten Brinke (info@retrosync.com).
5
+ # All rights reserved.
6
+
7
+ # Permission is granted for use, copying, modification, distribution,
8
+ # and distribution of modified versions of this work as long as the
9
+ # above copyright notice is included.
10
+ #++
11
+
12
+ require 'test/unit'
13
+ require 'test/preload'
14
+ require 'builder'
15
+
16
+ class TestMethodCaching < Test::Unit::TestCase
17
+
18
+ # We can directly ask if xml object responds to the cache_me or
19
+ # do_not_cache_me methods because xml is derived from BasicObject
20
+ # (and repond_to? is not defined in BasicObject).
21
+ #
22
+ # Instead we are going to stub out method_missing so that it throws
23
+ # an error, and then make sure that error is either thrown or not
24
+ # thrown as appropriate.
25
+
26
+ def teardown
27
+ super
28
+ Builder::XmlBase.cache_method_calls = true
29
+ end
30
+
31
+ def test_caching_does_not_break_weird_symbols
32
+ xml = Builder::XmlMarkup.new
33
+ xml.__send__("work-order", 1)
34
+ assert_equal "<work-order>1</work-order>", xml.target!
35
+ end
36
+
37
+ def test_method_call_caching
38
+ xml = Builder::XmlMarkup.new
39
+ xml.cache_me
40
+
41
+ def xml.method_missing(*args)
42
+ ::Kernel.fail StandardError, "SHOULD NOT BE CALLED"
43
+ end
44
+ assert_nothing_raised do
45
+ xml.cache_me
46
+ end
47
+ end
48
+
49
+ def test_method_call_caching_disabled
50
+ Builder::XmlBase.cache_method_calls = false
51
+ xml = Builder::XmlMarkup.new
52
+ xml.do_not_cache_me
53
+
54
+ def xml.method_missing(*args)
55
+ ::Kernel.fail StandardError, "SHOULD BE CALLED"
56
+ end
57
+ assert_raise(StandardError, /SHOULD BE CALLED/) do
58
+ xml.do_not_cache_me
59
+ end
60
+ end
61
+
62
+ end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
+ # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
6
+ # All rights reserved.
7
+
8
+ # Permission is granted for use, copying, modification, distribution,
9
+ # and distribution of modified versions of this work as long as the
10
+ # above copyright notice is included.
11
+ #++
12
+
13
+ require 'test/unit'
14
+ require 'builder/xchar'
15
+
16
+ class TestNameCollisions < Test::Unit::TestCase
17
+ module Collide
18
+ def xchr
19
+ end
20
+ end
21
+
22
+ def test_no_collision
23
+ assert_nothing_raised do
24
+ Builder.check_for_name_collision(Collide, :not_defined)
25
+ end
26
+ end
27
+
28
+ def test_collision
29
+ assert_raise RuntimeError do
30
+ Builder.check_for_name_collision(Collide, "xchr")
31
+ end
32
+ end
33
+
34
+ def test_collision_with_symbol
35
+ assert_raise RuntimeError do
36
+ Builder.check_for_name_collision(Collide, :xchr)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #--
4
+ # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
5
+ # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
6
+ # All rights reserved.
7
+
8
+ # Permission is granted for use, copying, modification, distribution,
9
+ # and distribution of modified versions of this work as long as the
10
+ # above copyright notice is included.
11
+ #++
12
+
13
+ #!/usr/bin/env ruby
14
+
15
+ require 'test/unit'
16
+ require 'builder/xchar'
17
+
18
+ if String.method_defined?(:encode)
19
+ class String
20
+ ENCODING_BINARY = Encoding.find('BINARY')
21
+
22
+ # shim method for testing purposes
23
+ def to_xs(escape=true)
24
+ raise NameError.new('to_xs') unless caller[0].index(__FILE__)
25
+
26
+ result = Builder::XChar.encode(self)
27
+ if escape
28
+ result.gsub(/[^\u0000-\u007F]/) {|c| "&##{c.ord};"}
29
+ else
30
+ # really only useful for testing purposes
31
+ result.force_encoding(ENCODING_BINARY)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ class TestXmlEscaping < Test::Unit::TestCase
38
+ REPLACEMENT_CHAR = Builder::XChar::REPLACEMENT_CHAR.to_xs
39
+
40
+ def test_ascii
41
+ assert_equal 'abc', 'abc'.to_xs
42
+ end
43
+
44
+ def test_predefined
45
+ assert_equal '&amp;', '&'.to_xs # ampersand
46
+ assert_equal '&lt;', '<'.to_xs # left angle bracket
47
+ assert_equal '&gt;', '>'.to_xs # right angle bracket
48
+ end
49
+
50
+ def test_invalid
51
+ assert_equal REPLACEMENT_CHAR, "\x00".to_xs # null
52
+ assert_equal REPLACEMENT_CHAR, "\x0C".to_xs # form feed
53
+ assert_equal REPLACEMENT_CHAR, "\xEF\xBF\xBF".to_xs # U+FFFF
54
+ end
55
+
56
+ def test_iso_8859_1
57
+ assert_equal '&#231;', "\xE7".to_xs # small c cedilla
58
+ assert_equal '&#169;', "\xA9".to_xs # copyright symbol
59
+ end
60
+
61
+ def test_win_1252
62
+ assert_equal '&#8217;', "\x92".to_xs # smart quote
63
+ assert_equal '&#8364;', "\x80".to_xs # euro
64
+ end
65
+
66
+ def test_utf8
67
+ assert_equal '&#8217;', "\xE2\x80\x99".to_xs # right single quote
68
+ assert_equal '&#169;', "\xC2\xA9".to_xs # copy
69
+ end
70
+
71
+ def test_utf8_verbatim
72
+ assert_equal "\xE2\x80\x99", "\xE2\x80\x99".to_xs(false) # right single quote
73
+ assert_equal "\xC2\xA9", "\xC2\xA9".to_xs(false) # copy
74
+ assert_equal "\xC2\xA9&amp;\xC2\xA9",
75
+ "\xC2\xA9&\xC2\xA9".to_xs(false) # copy with ampersand
76
+ end
77
+ end
metadata CHANGED
@@ -1,64 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blankslate
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 7
4
5
  prerelease:
5
- version: 2.1.2.4
6
+ segments:
7
+ - 3
8
+ - 1
9
+ - 2
10
+ version: 3.1.2
6
11
  platform: ruby
7
12
  authors:
8
13
  - Jim Weirich
9
- - David Masover
10
- - Jack Danger Canty
11
14
  autorequire:
12
15
  bindir: bin
13
16
  cert_chain: []
14
17
 
15
- date: 2011-03-16 00:00:00 -07:00
16
- default_executable:
17
- dependencies:
18
- - !ruby/object:Gem::Dependency
19
- name: rspec
20
- prerelease: false
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: "0"
27
- type: :development
28
- version_requirements: *id001
29
- - !ruby/object:Gem::Dependency
30
- name: bundler
31
- prerelease: false
32
- requirement: &id002 !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ">="
36
- - !ruby/object:Gem::Version
37
- version: "0"
38
- type: :development
39
- version_requirements: *id002
40
- description:
41
- email: rubygems@6brand.com
18
+ date: 2012-09-07 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: |
22
+ BlankSlate provides a base class where almost all of the methods from Object and
23
+ Kernel have been removed. This is useful when providing proxy object and other
24
+ classes that make heavy use of method_missing.
25
+
26
+ email: jim.weirich@gmail.com
42
27
  executables: []
43
28
 
44
29
  extensions: []
45
30
 
46
- extra_rdoc_files: []
47
-
48
- files:
49
- - README
31
+ extra_rdoc_files:
32
+ - CHANGES
33
+ - MIT-LICENSE
50
34
  - Rakefile
51
- - VERSION
52
- - blankslate.gemspec
35
+ - README.rdoc
36
+ - doc/releases/builder-1.2.4.rdoc
37
+ - doc/releases/builder-2.0.0.rdoc
38
+ - doc/releases/builder-2.1.1.rdoc
39
+ files:
53
40
  - lib/blankslate.rb
54
- - spec/blankslate_spec.rb
55
- has_rdoc: true
56
- homepage: http://github.com/masover/blankslate
57
- licenses: []
58
-
41
+ - test/test_blankslate.rb
42
+ - test/test_eventbuilder.rb
43
+ - test/test_markupbuilder.rb
44
+ - test/test_method_caching.rb
45
+ - test/test_namecollision.rb
46
+ - test/test_xchar.rb
47
+ - CHANGES
48
+ - MIT-LICENSE
49
+ - Rakefile
50
+ - README.rdoc
51
+ - doc/releases/builder-1.2.4.rdoc
52
+ - doc/releases/builder-2.0.0.rdoc
53
+ - doc/releases/builder-2.1.1.rdoc
54
+ homepage: http://onestepback.org
55
+ licenses:
56
+ - MIT
59
57
  post_install_message:
60
- rdoc_options: []
61
-
58
+ rdoc_options:
59
+ - --title
60
+ - BlankSlate -- Base Class for building proxies.
61
+ - --main
62
+ - README.rdoc
63
+ - --line-numbers
62
64
  require_paths:
63
65
  - lib
64
66
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -66,19 +68,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
69
  - - ">="
68
70
  - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
69
74
  version: "0"
70
75
  required_rubygems_version: !ruby/object:Gem::Requirement
71
76
  none: false
72
77
  requirements:
73
78
  - - ">="
74
79
  - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
75
83
  version: "0"
76
84
  requirements: []
77
85
 
78
86
  rubyforge_project:
79
- rubygems_version: 1.6.2
87
+ rubygems_version: 1.8.23
80
88
  signing_key:
81
89
  specification_version: 3
82
- summary: BlankSlate extracted from Builder.
90
+ summary: Blank Slate base class.
83
91
  test_files:
84
- - spec/blankslate_spec.rb
92
+ - test/test_blankslate.rb
93
+ - test/test_eventbuilder.rb
94
+ - test/test_markupbuilder.rb
95
+ - test/test_method_caching.rb
96
+ - test/test_namecollision.rb
97
+ - test/test_xchar.rb
data/README DELETED
@@ -1,31 +0,0 @@
1
- BlankSlate
2
- ===
3
-
4
- BlankSlate provides an abstract base class with no predefined
5
- methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
6
- BlankSlate is useful as a base class when writing classes that
7
- depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
8
-
9
- Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
10
- All rights reserved.
11
-
12
-
13
- Extracted from Builder because, for no conceivable reason,
14
- blankslate isn't in its own gem. Gemified by David Masover,
15
- moved to gemcutter by Jack Danger Canty (gemcutter@6brand.com
16
- if you'd like to own this gem).
17
-
18
- Explanation on extraction from David Masover:
19
-
20
- So, Builder seems to have the most complete implementation of
21
- BlankSlate, short of Ruby 1.9's BasicObject. The problem is,
22
- this is part of Builder, and still inside the Builder gem.
23
-
24
- It's especially frustrating, because the Builder source
25
- (lib/builder/blankslate.rb) seems to acknowledge that there
26
- should be a separate gem. But the only reference I can find
27
- refers to onestepback.org's gem repository, which isn't working.
28
-
29
- So I built my own. I'll try to keep it up to date with Builder.
30
- The first three parts of the version number are
31
- the Builder version; the last part is my revision.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.1.2.4
@@ -1,22 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "blankslate"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "blankslate"
7
- s.version = File.read('VERSION')
8
- s.platform = Gem::Platform::RUBY
9
- s.summary = 'BlankSlate extracted from Builder.'
10
- s.email = 'rubygems@6brand.com'
11
- s.authors = ['Jim Weirich', 'David Masover', 'Jack Danger Canty']
12
- s.email = "rubygems@6brand.com"
13
- s.homepage = "http://github.com/masover/blankslate"
14
-
15
- s.add_development_dependency 'rspec'
16
- s.add_development_dependency 'bundler'
17
-
18
- s.files = `git ls-files`.split("\n")
19
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.require_paths = ["lib"]
22
- end
@@ -1,39 +0,0 @@
1
- require 'blankslate'
2
- require 'rspec'
3
-
4
- describe BlankSlate do
5
- let(:blank_slate) { BlankSlate.new }
6
-
7
- def call(obj, meth, *args)
8
- BlankSlate.find_hidden_method(meth).bind(obj).call(*args)
9
- end
10
-
11
- describe "cleanliness" do
12
- it "should not have many methods" do
13
- BlankSlate.instance_methods.
14
- map(&:to_s).sort.
15
- should == ["__id__", "__send__", "instance_eval", "object_id"]
16
- end
17
- end
18
-
19
- context "when methods are added to Object" do
20
- after(:each) {
21
- class Object
22
- undef :foo
23
- end
24
- }
25
-
26
- it "should still be blank" do
27
- class Object
28
- def foo
29
- end
30
- end
31
- Object.new.foo
32
-
33
- lambda {
34
- BlankSlate.new.foo
35
- }.should raise_error(NoMethodError)
36
- end
37
-
38
- end
39
- end