Sha256: 014e2ec286fff58d8f3bc26699cf6c83ede1dd9922b5f00385d221d6a2a94408
Contents?: true
Size: 1.11 KB
Versions: 5
Compression:
Stored size: 1.11 KB
Contents
require "spec_helper" describe Object, ".aattr_initialize" do it "creates an initializer and public readers" do klass = Class.new do aattr_initialize :foo, :bar end example = klass.new("Foo", "Bar") example.foo.must_equal "Foo" end it "creates public writers" do klass = Class.new do aattr_initialize :foo, :bar end example = klass.new("Foo", "Bar") example.foo = "Baz" example.foo.must_equal "Baz" end it "works with hash ivars" do klass = Class.new do aattr_initialize :foo, [:bar, :baz!] end example = klass.new("Foo", :bar => "Bar", :baz => "Baz") example.baz.must_equal "Baz" end it "accepts a block for initialization" do klass = Class.new do aattr_initialize :value do @copy = @value end attr_reader :copy end example = klass.new("expected") example.copy.must_equal "expected" end it "accepts the alias attr_accessor_initialize" do klass = Class.new do attr_accessor_initialize :foo, :bar end example = klass.new("Foo", "Bar") example.foo.must_equal "Foo" end end
Version data entries
5 entries across 5 versions & 1 rubygems