Class: TestBlankSlate

Inherits:
Builder::Test show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb

Overview

Test case for blank slate.

Constant Summary

Constants inherited from Minitest::Test

Minitest::Test::PASSTHROUGH_EXCEPTIONS, Minitest::Test::SETUP_METHODS, Minitest::Test::TEARDOWN_METHODS

Constants included from Minitest::Assertions

Minitest::Assertions::E, Minitest::Assertions::UNDEFINED

Constants inherited from Minitest::Runnable

Minitest::Runnable::SIGNALS

Instance Attribute Summary

Attributes inherited from Minitest::Runnable

#assertions, #failures, #time

Instance Method Summary collapse

Methods inherited from Builder::Test

#assert_nothing_raised

Methods inherited from Minitest::Test

#capture_exceptions, #class_name, #clean, i_suck_and_my_tests_are_order_dependent!, make_my_diffs_pretty!, #neuter_exception, #new_exception, parallelize_me!, #run, runnable_methods, #sanitize_exception, test_order, #with_empty_backtrace_filter, #with_info_handler

Methods included from Minitest::Guard

#jruby?, #maglev?, #mri?, #osx?, #rubinius?, #windows?

Methods included from Minitest::Test::LifecycleHooks

#after_setup, #after_teardown, #before_setup, #before_teardown, #teardown

Methods included from Minitest::Reportable

#class_name, #error?, #location, #passed?, #result_code, #skipped?

Methods included from Minitest::Assertions

#_synchronize, #assert, #assert_empty, #assert_equal, #assert_in_delta, #assert_in_epsilon, #assert_includes, #assert_instance_of, #assert_kind_of, #assert_match, #assert_mock, #assert_nil, #assert_operator, #assert_output, #assert_path_exists, #assert_predicate, #assert_raises, #assert_respond_to, #assert_same, #assert_send, #assert_silent, #assert_throws, #capture_io, #capture_subprocess_io, #diff, diff, diff=, #exception_details, #fail_after, #flunk, #message, #mu_pp, #mu_pp_for_diff, #pass, #refute, #refute_empty, #refute_equal, #refute_in_delta, #refute_in_epsilon, #refute_includes, #refute_instance_of, #refute_kind_of, #refute_match, #refute_nil, #refute_operator, #refute_path_exists, #refute_predicate, #refute_respond_to, #refute_same, #skip, #skip_until, #skipped?, #things_to_diff

Methods inherited from Minitest::Runnable

#failure, inherited, #initialize, #marshal_dump, #marshal_load, methods_matching, #name, #name=, on_signal, #passed?, reset, #result_code, run, #run, run_one_method, runnable_methods, runnables, #skipped?, #time_it, #whatever, with_info_handler

Constructor Details

This class inherits a constructor from Minitest::Runnable

Instance Method Details

#setupObject



81
82
83
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 81

def setup
  @bs = BlankSlate.new
end

#test_global_includes_still_workObject



188
189
190
191
192
193
194
195
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 188

def test_global_includes_still_work
  assert_nothing_raised do
    assert_equal 42, global_inclusion
    assert_equal 42, Object.new.global_inclusion
    assert_equal 42, "magic number".global_inclusion
    assert_equal 43, direct_global
  end
end

#test_late_included_module_in_kernel_is_okObject



148
149
150
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 148

def test_late_included_module_in_kernel_is_ok
  assert_raise(NoMethodError) { @bs.late_kernel }
end

#test_late_included_module_in_object_is_okObject



143
144
145
146
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 143

def test_late_included_module_in_object_is_ok
  assert_equal 33, 1.late_object
  assert_raise(NoMethodError) { @bs.late_object }
end

#test_method_defined_late_multiple_times_remain_undefinedObject



138
139
140
141
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 138

def test_method_defined_late_multiple_times_remain_undefined
  assert_equal 22, nil.double_late_addition
  assert_raise(NoMethodError) { @bs.double_late_addition }
end

#test_methods_added_late_to_global_remain_undefinedObject



128
129
130
131
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 128

def test_methods_added_late_to_global_remain_undefined
  assert_equal 42, global_inclusion
  assert_raise(NoMethodError) { @bs.global_inclusion }
end

#test_methods_added_late_to_kernel_remain_undefinedObject



118
119
120
121
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 118

def test_methods_added_late_to_kernel_remain_undefined
  assert_equal 1234, nil.late_addition
  assert_raise(NoMethodError) { @bs.late_addition }
end

#test_methods_added_late_to_object_remain_undefinedObject



123
124
125
126
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 123

def test_methods_added_late_to_object_remain_undefined
  assert_equal 4321, nil.another_late_addition
  assert_raise(NoMethodError) { @bs.another_late_addition }
end

#test_preload_method_addedObject



133
134
135
136
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 133

def test_preload_method_added
  assert Kernel.k_added_names.include?(:late_addition)
  assert Object.o_added_names.include?(:another_late_addition)
end

#test_private_methods_are_undefinedObject



102
103
104
105
106
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 102

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

#test_reveal_should_not_bind_to_an_instanceObject



197
198
199
200
201
202
203
204
205
206
207
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 197

def test_reveal_should_not_bind_to_an_instance
  with_object_id = Class.new(BlankSlate) do
    reveal(:object_id)
  end

  obj1 = with_object_id.new
  obj2 = with_object_id.new

  assert obj1.object_id != obj2.object_id,
     "Revealed methods should not be bound to a particular instance"
end

#test_revealing_a_hidden_method_twice_is_okObject



172
173
174
175
176
177
178
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 172

def test_revealing_a_hidden_method_twice_is_ok
  with_to_s = Class.new(BlankSlate) do
    reveal :to_s
    reveal :to_s
  end
  assert_match(/^#<.*>$/, with_to_s.new.to_s)
end

#test_revealing_previously_hidden_methods_are_callableObject



152
153
154
155
156
157
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 152

def test_revealing_previously_hidden_methods_are_callable
  with_to_s = Class.new(BlankSlate) do
    reveal :to_s
  end
  assert_match(/^#<.*>$/, with_to_s.new.to_s)
end

#test_revealing_previously_hidden_methods_are_callable_with_blockObject



159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 159

def test_revealing_previously_hidden_methods_are_callable_with_block
  Object.class_eval <<-EOS
    def given_block(&block)
      block
    end
  EOS

  with_given_block = Class.new(BlankSlate) do
    reveal :given_block
  end
  assert_not_nil with_given_block.new.given_block {}
end

#test_revealing_unknown_hidden_method_is_an_errorObject



180
181
182
183
184
185
186
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 180

def test_revealing_unknown_hidden_method_is_an_error
  assert_raises(RuntimeError) do
    Class.new(BlankSlate) do
      reveal :xyz
    end
  end
end

#test_undefined_methods_remain_undefinedObject



85
86
87
88
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 85

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

#test_undefined_methods_remain_undefined_during_instance_evalObject

NOTE: NameError is acceptable because the lack of a ‘.’ means that Ruby can’t tell if it is a method or a local variable.



93
94
95
96
97
98
99
100
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 93

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

#test_untargetted_private_methods_are_defined_during_instance_evalObject



108
109
110
111
112
113
114
115
116
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 108

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