Sha256: 3d06b3025af2c0e7b39c084c0880f607da40dc9c9002dd1f994a78c05b3dd0c7

Contents?: true

Size: 1.71 KB

Versions: 8

Compression:

Stored size: 1.71 KB

Contents

require 'spec_helper'

describe Hashme::Attributes do


  before :each do
    @model = Class.new do
      include Hashme
    end
    @obj = @model.new
  end

  let :attribs do
    @obj.send(:_attributes)
  end

  describe "forwarded methods" do
    before :each do
      @hash = {:key1 => 'value1', :key2 => 'value2'}
      @obj[:key1] = 'value1'
      @obj[:key2] = 'value2'
    end

    it "should assign some of the basic hash methods" do
      expect(@obj == @hash).to be_truthy
      expect(@obj.keys).to eql(@hash.keys)
      expect(@obj.values).to eql(@hash.values)
      expect(@obj.to_hash).to eql(@hash)
    end
  end

  describe "#[]=" do
    it "should assign values to attributes hash" do
      @obj[:akey] = "test"
      expect(attribs[:akey]).to eql("test")
      @obj['akey'] = "anothertest"
      expect(attribs[:akey]).to eql("anothertest")
      expect(attribs['akey']).to be_nil
    end
  end

  describe "#delete" do
    it "should remove attribtue entry" do
      @obj[:key] = 'value'
      @obj.delete(:key)
      expect(@obj[:key]).to be_nil
    end
  end

  describe "#dup" do
    it "should duplicate attributes" do
      @obj[:key] = 'value'
      @obj2 = @obj.dup
      expect(@obj2.send(:_attributes).object_id).to_not eql(@obj.send(:_attributes).object_id)
    end
  end

  describe "#clone" do
    it "should clone attributes" do
      @obj[:key] = 'value'
      @obj2 = @obj.clone
      expect(@obj2.send(:_attributes).object_id).to_not eql(@obj.send(:_attributes).object_id)
    end
  end


  describe "#inspect" do

    it "should provide something useful" do
      @obj[:key1] = 'value1'
      @obj[:key2] = 'value2'
      expect(@obj.inspect).to match(/#<.+ key1: "value1", key2: "value2">/)
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hashme-0.3.0 spec/hashme/attributes_spec.rb
hashme-0.2.6 spec/hashme/attributes_spec.rb
hashme-0.2.5 spec/hashme/attributes_spec.rb
hashme-0.2.4 spec/hashme/attributes_spec.rb
hashme-0.2.3 spec/hashme/attributes_spec.rb
hashme-0.2.2 spec/hashme/attributes_spec.rb
hashme-0.2.1 spec/hashme/attributes_spec.rb
hashme-0.2.0 spec/hashme/attributes_spec.rb