class AttrInternalTest

Public Instance Methods

setup() click to toggle source
# File activesupport/test/core_ext/module/attr_internal_test.rb, line 7
def setup
  @target = Class.new
  @instance = @target.new
end
test_accessor() click to toggle source
# File activesupport/test/core_ext/module/attr_internal_test.rb, line 32
def test_accessor
  assert_nothing_raised { @target.attr_internal :foo }

  assert !@instance.instance_variable_defined?("@_foo")
  assert_nothing_raised { assert_equal 1, @instance.foo = 1 }

  assert_equal 1, @instance.instance_variable_get("@_foo")
  assert_nothing_raised { assert_equal 1, @instance.foo }
end
test_naming_format() click to toggle source
# File activesupport/test/core_ext/module/attr_internal_test.rb, line 42
def test_naming_format
  assert_equal "@_%s", Module.attr_internal_naming_format
  assert_nothing_raised { Module.attr_internal_naming_format = "@abc%sdef" }
  @target.attr_internal :foo

  assert !@instance.instance_variable_defined?("@_foo")
  assert !@instance.instance_variable_defined?("@abcfoodef")
  assert_nothing_raised { @instance.foo = 1 }
  assert !@instance.instance_variable_defined?("@_foo")
  assert @instance.instance_variable_defined?("@abcfoodef")
ensure
  Module.attr_internal_naming_format = "@_%s"
end
test_reader() click to toggle source
# File activesupport/test/core_ext/module/attr_internal_test.rb, line 12
def test_reader
  assert_nothing_raised { @target.attr_internal_reader :foo }

  assert !@instance.instance_variable_defined?("@_foo")
  assert_raise(NoMethodError) { @instance.foo = 1 }

  @instance.instance_variable_set("@_foo", 1)
  assert_nothing_raised { assert_equal 1, @instance.foo }
end
test_writer() click to toggle source
# File activesupport/test/core_ext/module/attr_internal_test.rb, line 22
def test_writer
  assert_nothing_raised { @target.attr_internal_writer :foo }

  assert !@instance.instance_variable_defined?("@_foo")
  assert_nothing_raised { assert_equal 1, @instance.foo = 1 }

  assert_equal 1, @instance.instance_variable_get("@_foo")
  assert_raise(NoMethodError) { @instance.foo }
end