Sha256: c0429718468f35d2bca8807ac772629444a7792b9dfeb85d8aa9a314c7fef80a

Contents?: true

Size: 949 Bytes

Versions: 6

Compression:

Stored size: 949 Bytes

Contents

require "spec_helper"

describe Object, ".rattr_initialize" do
  it "creates both initializer and public readers" do
    klass = Class.new do
      rattr_initialize :foo, :bar
    end

    example = klass.new("Foo", "Bar")
    _(example.public_send(:foo)).must_equal "Foo"
  end

  it "works with hash ivars" do
    klass = Class.new do
      rattr_initialize :foo, [ :bar, :baz! ]
    end

    example = klass.new("Foo", bar: "Bar", baz: "Baz")
    _(example.public_send(:baz)).must_equal "Baz"
  end

  it "works with hash ivars and default values" do
    klass = Class.new do
      rattr_initialize :foo, [ bar: "Bar", baz!: "Baz" ]
    end

    example = klass.new("Foo")
    _(example.send(:baz)).must_equal "Baz"
  end

  it "accepts the alias attr_reader_initialize" do
    klass = Class.new do
      attr_reader_initialize :foo, :bar
    end

    example = klass.new("Foo", "Bar")
    _(example.public_send(:foo)).must_equal "Foo"
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
attr_extras-7.1.0 spec/attr_extras/rattr_initialize_spec.rb
attr_extras-7.0.0 spec/attr_extras/rattr_initialize_spec.rb
attr_extras-6.2.5 spec/attr_extras/rattr_initialize_spec.rb
attr_extras-6.2.4 spec/attr_extras/rattr_initialize_spec.rb
attr_extras-6.2.3 spec/attr_extras/rattr_initialize_spec.rb
attr_extras-6.2.2 spec/attr_extras/rattr_initialize_spec.rb