builder 3.2.4 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 386ed394ff60c6aff710d3304b69fac8ead0e6c89b80f80691b434fcb772290f
4
- data.tar.gz: 42ccc387ac8ba03c586bf3b280977292418e96031e859ea764808a8d132e5654
3
+ metadata.gz: 3806a31277af2b4c8c09c0ff00fefc48c53897b6e15ec50d6a3aaf3c38fddcd6
4
+ data.tar.gz: ab52ac5dfa0d775075f8331a926257cc2f5d6ae2d8b872847694f7073278e7be
5
5
  SHA512:
6
- metadata.gz: 76c76d003cc4198733b46dfb9078d130a298c90a5fda954b521c965ae91c891212be43808b29b0d55824b4f3cdfa96289ea2267a57425713725a3ef30b930d83
7
- data.tar.gz: dba82177c0a2ef38fdafbe1bb875487ad8e112b1f298c06a4a6c001c267172bd1043245229f45839bcdd64e0f2cc8093f7a4d27a5839b65446926560b936463d
6
+ metadata.gz: 5e14cca2d3f260c05a824b26db49271c106b8616b98b41bac4eb4e9ff13326a9309647173240e6ea3a7c84c5f671987b7108d186171b97cc66daa48708dbeef8
7
+ data.tar.gz: 284523129dae9e151677655c21ab3a2d248a3d9f3a38bea5c20eb984b4bfacc9792acc70d4141af744c0815676bca3132b2c25c13e0b406db9599f28ec6967ae
data/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = Change Log
2
2
 
3
+ == Version 3.3.0 (2024-06-06)
4
+
5
+ * Fix broken call to `File.exists?` in `tags.rake`.
6
+ * Use BasicObject instead of BlankSlate for better compatibility with modern rubies.
7
+
8
+ == Version 3.2.4 (2019-12-10)
9
+
10
+ * Strings were frozen by adding `# frozen_string_literal: true` to all files
11
+
3
12
  == Version 3.2.3 (2017-01-13)
4
13
 
5
14
  * Support for Ruby 2.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
3
+
4
+ # Specify your gem's dependencies in heap-profiler.gemspec
5
+ gemspec
6
+
7
+ gem "rake"
8
+ gem "minitest"
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ builder (3.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.23.1)
10
+ rake (13.2.1)
11
+
12
+ PLATFORMS
13
+ arm64-darwin-23
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ builder!
18
+ minitest
19
+ rake
20
+
21
+ BUNDLED WITH
22
+ 2.5.9
data/README.md CHANGED
@@ -245,8 +245,8 @@ incompatibility are:
245
245
  | Description | Link |
246
246
  | :----: | :----: |
247
247
  | Documents | http://builder.rubyforge.org/ |
248
- | Github Clone | git://github.com/tenderlove/builder.git |
249
- | Issue / Bug Reports | https://github.com/tenderlove/builder/issues?state=open |
248
+ | Github Clone | git://github.com/rails/builder.git |
249
+ | Issue / Bug Reports | https://github.com/rails/builder/issues?state=open |
250
250
 
251
251
  ## Contact
252
252
 
data/Rakefile CHANGED
@@ -8,6 +8,7 @@
8
8
  # and distribution of modified versions of this work as long as the
9
9
  # above copyright notice is included.
10
10
 
11
+ require 'bundler/gem_tasks'
11
12
  require 'rake/clean'
12
13
  require 'rake/testtask'
13
14
  begin
@@ -23,7 +24,7 @@ require './lib/builder/version'
23
24
  # Determine the current version of the software
24
25
 
25
26
  CLOBBER.include('pkg', 'html')
26
- CLEAN.include('pkg/builder-*').include('pkg/blankslate-*').exclude('pkg/*.gem')
27
+ CLEAN.include('pkg/builder-*').exclude('pkg/*.gem')
27
28
 
28
29
  PKG_VERSION = Builder::VERSION
29
30
 
@@ -77,11 +78,6 @@ PKG_FILES.exclude('test/test_cssbuilder.rb')
77
78
  PKG_FILES.exclude('lib/builder/css.rb')
78
79
  PKG_FILES.exclude('TAGS')
79
80
 
80
- BLANKSLATE_FILES = FileList[
81
- 'lib/blankslate.rb',
82
- 'test/test_blankslate.rb'
83
- ]
84
-
85
81
  if ! defined?(Gem)
86
82
  puts "Package Target requires RubyGEMs"
87
83
  else
@@ -117,49 +113,13 @@ simple to do. Currently the following builder objects are supported:
117
113
  s.license = 'MIT'
118
114
  end
119
115
 
120
- blankslate_spec = Gem::Specification.new do |s|
121
-
122
- #### Basic information.
123
-
124
- s.name = 'blankslate'
125
- s.version = PKG_VERSION
126
- s.summary = "Blank Slate base class."
127
- s.description = %{\
128
- BlankSlate provides a base class where almost all of the methods from Object and
129
- Kernel have been removed. This is useful when providing proxy object and other
130
- classes that make heavy use of method_missing.
131
- }
132
-
133
- s.files = BLANKSLATE_FILES.to_a
134
- s.require_path = 'lib'
135
-
136
- s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
137
-
138
- s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
139
- s.rdoc_options <<
140
- '--title' << 'BlankSlate -- Base Class for building proxies.' <<
141
- '--main' << 'README.rdoc' <<
142
- '--line-numbers'
143
-
144
- s.author = "Jim Weirich"
145
- s.email = "jim.weirich@gmail.com"
146
- s.homepage = "http://onestepback.org"
147
- s.license = 'MIT'
148
- end
149
-
150
116
  namespace 'builder' do
151
117
  Gem::PackageTask.new(spec) do |t|
152
118
  t.need_tar = false
153
119
  end
154
120
  end
155
121
 
156
- namespace 'blankslate' do
157
- Gem::PackageTask.new(blankslate_spec) do |t|
158
- t.need_tar = false
159
- end
160
- end
161
-
162
- task :package => [:remove_tags, 'builder:package', 'blankslate:package']
122
+ task :package => [:remove_tags, 'builder:package']
163
123
  end
164
124
 
165
125
  task :remove_tags do
data/builder.gemspec CHANGED
@@ -1,22 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  require './lib/builder/version'
3
3
 
4
- PKG_VERSION = Builder::VERSION
5
-
6
- PKG_FILES = Dir[
7
- '[A-Z]*',
8
- 'doc/**/*',
9
- 'lib/**/*.rb',
10
- 'test/**/*.rb',
11
- 'rakelib/**/*'
12
- ]
13
-
14
4
  Gem::Specification.new do |s|
15
5
 
16
6
  #### Basic information.
17
7
 
18
8
  s.name = 'builder'
19
- s.version = PKG_VERSION
9
+ s.version = Builder::VERSION
20
10
  s.summary = "Builders for MarkUp."
21
11
  s.description = %{\
22
12
  Builder provides a number of builder objects that make creating structured data
@@ -26,12 +16,19 @@ simple to do. Currently the following builder objects are supported:
26
16
  * XML Events
27
17
  }
28
18
 
29
- s.files = PKG_FILES
19
+ pkg_files = Dir[
20
+ '[A-Z]*',
21
+ 'doc/**/*',
22
+ 'lib/**/*.rb',
23
+ 'test/**/*.rb',
24
+ 'rakelib/**/*'
25
+ ]
26
+
27
+ s.files = pkg_files
30
28
  s.require_path = 'lib'
31
29
 
32
- s.test_files = PKG_FILES.select { |fn| fn =~ /^test\/test/ }
30
+ s.test_files = pkg_files.select { |fn| fn =~ /^test\/test/ }
33
31
 
34
- s.has_rdoc = true
35
32
  # s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
36
33
  s.rdoc_options <<
37
34
  '--title' << 'Builder -- Easy XML Building' <<
@@ -40,6 +37,13 @@ simple to do. Currently the following builder objects are supported:
40
37
 
41
38
  s.authors = ["Jim Weirich", "Aaron Patterson"]
42
39
  s.email = "aron.patterson@gmail.com"
43
- s.homepage = "https://github.com/tenderlove/builder"
40
+ s.homepage = "https://github.com/rails/builder"
44
41
  s.license = 'MIT'
42
+ s.metadata = {
43
+ "bug_tracker_uri" => "#{s.homepage}/issues",
44
+ "changelog_uri" => "#{s.homepage}/blob/master/CHANGES",
45
+ "documentation_uri" => "https://www.rubydoc.info/gems/builder/#{s.version}",
46
+ "homepage_uri" => s.homepage,
47
+ "source_code_uri" => "#{s.homepage}/tree/v#{s.version}"
48
+ }
45
49
  end
File without changes
@@ -2,8 +2,8 @@
2
2
  module Builder
3
3
  VERSION_NUMBERS = [
4
4
  VERSION_MAJOR = 3,
5
- VERSION_MINOR = 2,
6
- VERSION_BUILD = 4,
5
+ VERSION_MINOR = 3,
6
+ VERSION_BUILD = 0,
7
7
  ]
8
8
  VERSION = VERSION_NUMBERS.join(".")
9
9
  end
@@ -1,8 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'builder/blankslate'
5
-
6
4
  module Builder
7
5
 
8
6
  # Generic error for builder
@@ -10,7 +8,7 @@ module Builder
10
8
 
11
9
  # XmlBase is a base class for building XML builders. See
12
10
  # Builder::XmlMarkup and Builder::XmlEvents for examples.
13
- class XmlBase < BlankSlate
11
+ class XmlBase < BasicObject
14
12
 
15
13
  class << self
16
14
  attr_accessor :cache_method_calls
@@ -118,15 +118,15 @@ module Builder
118
118
  #
119
119
  # Example:
120
120
  #
121
- # xm = Builder.new(:indent=>2)
121
+ # xm = Builder::XmlMarkup.new(:indent=>2)
122
122
  # # xm will produce nicely formatted and indented XML.
123
123
  #
124
- # xm = Builder.new(:indent=>2, :margin=>4)
124
+ # xm = Builder::XmlMarkup.new(:indent=>2, :margin=>4)
125
125
  # # xm will produce nicely formatted and indented XML with 2
126
126
  # # spaces per indent and an over all indentation level of 4.
127
127
  #
128
128
  # builder = Builder::XmlMarkup.new(:target=>$stdout, :indent=>2)
129
- # builder.name { |b| b.first("Jim"); b.last("Weirich) }
129
+ # builder.name { |b| b.first("Jim"); b.last("Weirich") }
130
130
  # # prints:
131
131
  # # <name>
132
132
  # # <first>Jim</first>
@@ -155,7 +155,7 @@ module Builder
155
155
  #
156
156
  # xml_builder = Builder::XmlMarkup.new
157
157
  # xml_builder.div { |xml|
158
- # xml.stong("text")
158
+ # xml.strong("text")
159
159
  # }
160
160
  #
161
161
  class XmlMarkup < XmlBase
data/rakelib/tags.rake CHANGED
@@ -14,7 +14,7 @@ module Tags
14
14
  PROJECT_DIR = ['.']
15
15
 
16
16
  RVM_GEMDIR = File.join(`rvm gemdir`.strip, "gems") rescue nil
17
- SYSTEM_DIRS = RVM_GEMDIR && File.exists?(RVM_GEMDIR) ? RVM_GEMDIR : []
17
+ SYSTEM_DIRS = RVM_GEMDIR && File.exist?(RVM_GEMDIR) ? RVM_GEMDIR : []
18
18
 
19
19
  module_function
20
20
 
@@ -12,7 +12,6 @@
12
12
  #++
13
13
 
14
14
  require 'helper'
15
- require 'preload'
16
15
  require 'builder'
17
16
  require 'builder/xmlevents'
18
17
 
@@ -12,7 +12,6 @@
12
12
  #++
13
13
 
14
14
  require 'helper'
15
- require 'preload'
16
15
  require 'builder'
17
16
  require 'builder/xmlmarkup'
18
17
 
@@ -11,7 +11,6 @@
11
11
  #++
12
12
 
13
13
  require 'helper'
14
- require 'preload'
15
14
  require 'builder'
16
15
 
17
16
  class TestMethodCaching < Builder::Test
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.4
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Weirich
8
- autorequire:
8
+ - Aaron Patterson
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-12-10 00:00:00.000000000 Z
12
+ date: 2024-06-06 00:00:00.000000000 Z
12
13
  dependencies: []
13
14
  description: |
14
15
  Builder provides a number of builder objects that make creating structured data
@@ -16,21 +17,14 @@ description: |
16
17
 
17
18
  * XML Markup
18
19
  * XML Events
19
- email: jim.weirich@gmail.com
20
+ email: aron.patterson@gmail.com
20
21
  executables: []
21
22
  extensions: []
22
- extra_rdoc_files:
23
- - CHANGES
24
- - MIT-LICENSE
25
- - README.md
26
- - Rakefile
27
- - builder.blurb
28
- - builder.gemspec
29
- - doc/releases/builder-1.2.4.rdoc
30
- - doc/releases/builder-2.0.0.rdoc
31
- - doc/releases/builder-2.1.1.rdoc
23
+ extra_rdoc_files: []
32
24
  files:
33
25
  - CHANGES
26
+ - Gemfile
27
+ - Gemfile.lock
34
28
  - MIT-LICENSE
35
29
  - README.md
36
30
  - Rakefile
@@ -40,9 +34,7 @@ files:
40
34
  - doc/releases/builder-1.2.4.rdoc
41
35
  - doc/releases/builder-2.0.0.rdoc
42
36
  - doc/releases/builder-2.1.1.rdoc
43
- - lib/blankslate.rb
44
37
  - lib/builder.rb
45
- - lib/builder/blankslate.rb
46
38
  - lib/builder/version.rb
47
39
  - lib/builder/xchar.rb
48
40
  - lib/builder/xmlbase.rb
@@ -53,18 +45,21 @@ files:
53
45
  - rakelib/testing.rake
54
46
  - test/helper.rb
55
47
  - test/performance.rb
56
- - test/preload.rb
57
- - test/test_blankslate.rb
58
48
  - test/test_eventbuilder.rb
59
49
  - test/test_markupbuilder.rb
60
50
  - test/test_method_caching.rb
61
51
  - test/test_namecollision.rb
62
52
  - test/test_xchar.rb
63
- homepage: http://onestepback.org
53
+ homepage: https://github.com/rails/builder
64
54
  licenses:
65
55
  - MIT
66
- metadata: {}
67
- post_install_message:
56
+ metadata:
57
+ bug_tracker_uri: https://github.com/rails/builder/issues
58
+ changelog_uri: https://github.com/rails/builder/blob/master/CHANGES
59
+ documentation_uri: https://www.rubydoc.info/gems/builder/3.3.0
60
+ homepage_uri: https://github.com/rails/builder
61
+ source_code_uri: https://github.com/rails/builder/tree/v3.3.0
62
+ post_install_message:
68
63
  rdoc_options:
69
64
  - "--title"
70
65
  - Builder -- Easy XML Building
@@ -84,12 +79,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
79
  - !ruby/object:Gem::Version
85
80
  version: '0'
86
81
  requirements: []
87
- rubygems_version: 3.1.0.pre3
88
- signing_key:
82
+ rubygems_version: 3.5.9
83
+ signing_key:
89
84
  specification_version: 4
90
85
  summary: Builders for MarkUp.
91
86
  test_files:
92
- - test/test_blankslate.rb
93
87
  - test/test_eventbuilder.rb
94
88
  - test/test_markupbuilder.rb
95
89
  - test/test_method_caching.rb
data/lib/blankslate.rb DELETED
@@ -1,138 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #--
4
- # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
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
- class String
13
- if instance_methods.first.is_a?(Symbol)
14
- def _blankslate_as_name
15
- to_sym
16
- end
17
- else
18
- def _blankslate_as_name
19
- self
20
- end
21
- end
22
- end
23
-
24
- class Symbol
25
- if instance_methods.first.is_a?(Symbol)
26
- def _blankslate_as_name
27
- self
28
- end
29
- else
30
- def _blankslate_as_name
31
- to_s
32
- end
33
- end
34
- end
35
-
36
- ######################################################################
37
- # BlankSlate provides an abstract base class with no predefined
38
- # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
39
- # BlankSlate is useful as a base class when writing classes that
40
- # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
41
- #
42
- class BlankSlate
43
- class << self
44
-
45
- # Hide the method named +name+ in the BlankSlate class. Don't
46
- # hide +instance_eval+ or any method beginning with "__".
47
- def hide(name)
48
- warn_level = $VERBOSE
49
- $VERBOSE = nil
50
- if instance_methods.include?(name._blankslate_as_name) &&
51
- name !~ /^(__|instance_eval$)/
52
- @hidden_methods ||= {}
53
- @hidden_methods[name.to_sym] = instance_method(name)
54
- undef_method name
55
- end
56
- ensure
57
- $VERBOSE = warn_level
58
- end
59
-
60
- def find_hidden_method(name)
61
- @hidden_methods ||= {}
62
- @hidden_methods[name] || superclass.find_hidden_method(name)
63
- end
64
-
65
- # Redefine a previously hidden method so that it may be called on a blank
66
- # slate object.
67
- def reveal(name)
68
- hidden_method = find_hidden_method(name)
69
- fail "Don't know how to reveal method '#{name}'" unless hidden_method
70
- define_method(name, hidden_method)
71
- end
72
- end
73
-
74
- instance_methods.each { |m| hide(m) }
75
- end
76
-
77
- ######################################################################
78
- # Since Ruby is very dynamic, methods added to the ancestors of
79
- # BlankSlate <em>after BlankSlate is defined</em> will show up in the
80
- # list of available BlankSlate methods. We handle this by defining a
81
- # hook in the Object and Kernel classes that will hide any method
82
- # defined after BlankSlate has been loaded.
83
- #
84
- module Kernel
85
- class << self
86
- alias_method :blank_slate_method_added, :method_added
87
-
88
- # Detect method additions to Kernel and remove them in the
89
- # BlankSlate class.
90
- def method_added(name)
91
- result = blank_slate_method_added(name)
92
- return result if self != Kernel
93
- BlankSlate.hide(name)
94
- result
95
- end
96
- end
97
- end
98
-
99
- ######################################################################
100
- # Same as above, except in Object.
101
- #
102
- class Object
103
- class << self
104
- alias_method :blank_slate_method_added, :method_added
105
-
106
- # Detect method additions to Object and remove them in the
107
- # BlankSlate class.
108
- def method_added(name)
109
- result = blank_slate_method_added(name)
110
- return result if self != Object
111
- BlankSlate.hide(name)
112
- result
113
- end
114
-
115
- def find_hidden_method(name)
116
- nil
117
- end
118
- end
119
- end
120
-
121
- ######################################################################
122
- # Also, modules included into Object need to be scanned and have their
123
- # instance methods removed from blank slate. In theory, modules
124
- # included into Kernel would have to be removed as well, but a
125
- # "feature" of Ruby prevents late includes into modules from being
126
- # exposed in the first place.
127
- #
128
- class Module
129
- alias blankslate_original_append_features append_features
130
- def append_features(mod)
131
- result = blankslate_original_append_features(mod)
132
- return result if mod != Object
133
- instance_methods.each do |name|
134
- BlankSlate.hide(name)
135
- end
136
- result
137
- end
138
- end
@@ -1,24 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #--
4
- # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
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
- ######################################################################
13
- # BlankSlate has been promoted to a top level name and is now
14
- # available as a standalone gem. We make the name available in the
15
- # Builder namespace for compatibility.
16
- #
17
- module Builder
18
- if Object::const_defined?(:BasicObject)
19
- BlankSlate = ::BasicObject
20
- else
21
- require 'blankslate'
22
- BlankSlate = ::BlankSlate
23
- end
24
- end
data/test/preload.rb DELETED
@@ -1,40 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #--
5
- # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
6
- # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
7
- # All rights reserved.
8
-
9
- # Permission is granted for use, copying, modification, distribution,
10
- # and distribution of modified versions of this work as long as the
11
- # above copyright notice is included.
12
- #++
13
-
14
- # We are defining method_added in Kernel and Object so that when
15
- # BlankSlate overrides them later, we can verify that it correctly
16
- # calls the older hooks.
17
-
18
- module Kernel
19
- class << self
20
- attr_reader :k_added_names
21
- alias_method :preload_method_added, :method_added
22
- def method_added(name)
23
- preload_method_added(name)
24
- @k_added_names ||= []
25
- @k_added_names << name
26
- end
27
- end
28
- end
29
-
30
- class Object
31
- class << self
32
- attr_reader :o_added_names
33
- alias_method :preload_method_added, :method_added
34
- def method_added(name)
35
- preload_method_added(name)
36
- @o_added_names ||= []
37
- @o_added_names << name
38
- end
39
- end
40
- end
@@ -1,208 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
4
- #--
5
- # Portions copyright 2004 by Jim Weirich (jim@weirichhouse.org).
6
- # Portions copyright 2005 by Sam Ruby (rubys@intertwingly.net).
7
- # All rights reserved.
8
-
9
- # Permission is granted for use, copying, modification, distribution,
10
- # and distribution of modified versions of this work as long as the
11
- # above copyright notice is included.
12
- #++
13
-
14
- require 'helper'
15
- require 'preload'
16
- require 'blankslate'
17
- require 'stringio'
18
-
19
- # Methods to be introduced into the Object class late.
20
- module LateObject
21
- def late_object
22
- 33
23
- end
24
- def LateObject.included(mod)
25
- # Modules defining an included method should not prevent blank
26
- # slate erasure!
27
- end
28
- end
29
-
30
- # Methods to be introduced into the Kernel module late.
31
- module LateKernel
32
- def late_kernel
33
- 44
34
- end
35
- def LateKernel.included(mod)
36
- # Modules defining an included method should not prevent blank
37
- # slate erasure!
38
- end
39
- end
40
-
41
- # Introduce some late methods (both module and direct) into the Kernel
42
- # module.
43
- module Kernel
44
- include LateKernel
45
-
46
- def late_addition
47
- 1234
48
- end
49
-
50
- def double_late_addition
51
- 22
52
- end
53
- end
54
-
55
-
56
- # Introduce some late methods (both module and direct) into the Object
57
- # class.
58
- class Object
59
- include LateObject
60
- def another_late_addition
61
- 4321
62
- end
63
- end
64
-
65
- # Introduce some late methods by inclusion.
66
- module GlobalModule
67
- def global_inclusion
68
- 42
69
- end
70
- end
71
- include GlobalModule
72
-
73
- def direct_global
74
- 43
75
- end
76
-
77
- ######################################################################
78
- # Test case for blank slate.
79
- #
80
- class TestBlankSlate < Builder::Test
81
- def setup
82
- @bs = BlankSlate.new
83
- end
84
-
85
- def test_undefined_methods_remain_undefined
86
- assert_raise(NoMethodError) { @bs.no_such_method }
87
- assert_raise(NoMethodError) { @bs.nil? }
88
- end
89
-
90
-
91
- # NOTE: NameError is acceptable because the lack of a '.' means that
92
- # Ruby can't tell if it is a method or a local variable.
93
- def test_undefined_methods_remain_undefined_during_instance_eval
94
- assert_raise(NoMethodError, NameError) do
95
- @bs.instance_eval do nil? end
96
- end
97
- assert_raise(NoMethodError, NameError) do
98
- @bs.instance_eval do no_such_method end
99
- end
100
- end
101
-
102
- def test_private_methods_are_undefined
103
- assert_raise(NoMethodError) do
104
- @bs.puts "HI"
105
- end
106
- end
107
-
108
- def test_untargetted_private_methods_are_defined_during_instance_eval
109
- oldstdout = $stdout
110
- $stdout = StringIO.new
111
- @bs.instance_eval do
112
- puts "HI"
113
- end
114
- ensure
115
- $stdout = oldstdout
116
- end
117
-
118
- def test_methods_added_late_to_kernel_remain_undefined
119
- assert_equal 1234, nil.late_addition
120
- assert_raise(NoMethodError) { @bs.late_addition }
121
- end
122
-
123
- def test_methods_added_late_to_object_remain_undefined
124
- assert_equal 4321, nil.another_late_addition
125
- assert_raise(NoMethodError) { @bs.another_late_addition }
126
- end
127
-
128
- def test_methods_added_late_to_global_remain_undefined
129
- assert_equal 42, global_inclusion
130
- assert_raise(NoMethodError) { @bs.global_inclusion }
131
- end
132
-
133
- def test_preload_method_added
134
- assert Kernel.k_added_names.include?(:late_addition)
135
- assert Object.o_added_names.include?(:another_late_addition)
136
- end
137
-
138
- def test_method_defined_late_multiple_times_remain_undefined
139
- assert_equal 22, nil.double_late_addition
140
- assert_raise(NoMethodError) { @bs.double_late_addition }
141
- end
142
-
143
- def test_late_included_module_in_object_is_ok
144
- assert_equal 33, 1.late_object
145
- assert_raise(NoMethodError) { @bs.late_object }
146
- end
147
-
148
- def test_late_included_module_in_kernel_is_ok
149
- assert_raise(NoMethodError) { @bs.late_kernel }
150
- end
151
-
152
- def test_revealing_previously_hidden_methods_are_callable
153
- with_to_s = Class.new(BlankSlate) do
154
- reveal :to_s
155
- end
156
- assert_match(/^#<.*>$/, with_to_s.new.to_s)
157
- end
158
-
159
- def test_revealing_previously_hidden_methods_are_callable_with_block
160
- Object.class_eval <<-EOS
161
- def given_block(&block)
162
- block
163
- end
164
- EOS
165
-
166
- with_given_block = Class.new(BlankSlate) do
167
- reveal :given_block
168
- end
169
- assert_not_nil with_given_block.new.given_block {}
170
- end
171
-
172
- def test_revealing_a_hidden_method_twice_is_ok
173
- with_to_s = Class.new(BlankSlate) do
174
- reveal :to_s
175
- reveal :to_s
176
- end
177
- assert_match(/^#<.*>$/, with_to_s.new.to_s)
178
- end
179
-
180
- def test_revealing_unknown_hidden_method_is_an_error
181
- assert_raises(RuntimeError) do
182
- Class.new(BlankSlate) do
183
- reveal :xyz
184
- end
185
- end
186
- end
187
-
188
- def test_global_includes_still_work
189
- assert_nothing_raised do
190
- assert_equal 42, global_inclusion
191
- assert_equal 42, Object.new.global_inclusion
192
- assert_equal 42, "magic number".global_inclusion
193
- assert_equal 43, direct_global
194
- end
195
- end
196
-
197
- def test_reveal_should_not_bind_to_an_instance
198
- with_object_id = Class.new(BlankSlate) do
199
- reveal(:object_id)
200
- end
201
-
202
- obj1 = with_object_id.new
203
- obj2 = with_object_id.new
204
-
205
- assert obj1.object_id != obj2.object_id,
206
- "Revealed methods should not be bound to a particular instance"
207
- end
208
- end