Sha256: 03999abe4a70bb8b25fb466414d4057c5441474a9c216b4e03b007dc83f1a32d

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require 'spec_helper'

describe Hari::Keys::Hash do

  let(:node) { Hari.node user: 10 }
  subject    { node.hash :preferences }

  before do
    subject[:genre] = 'afrobeat'
  end

  specify '#hash' do
    node.hash.should be_a(Fixnum)
    node.hash(:preferences).should be_a(Hari::Keys::Hash)
  end

  specify '#hash! + #to_a' do
    node.hash!(:preferences).should eq('genre' => 'afrobeat')
    subject.to_h.should eq('genre' => 'afrobeat')
  end

  specify '#delete' do
    subject.delete :genre
    subject.to_h.should eq({})
  end

  specify '#key? + #[]' do
    subject.key?(:genre).should be_true
    subject.key?(:city).should be_false
    subject.has_key?(:genre).should be_true
    subject.member?(:genre).should be_true

    subject[:genre].should eq('afrobeat')
  end

  specify '#keys + #values + #values_at' do
    subject[:city] = 'Amsterdam'
    subject.keys.sort.should eq %w(city genre)
    subject.values.sort.should eq %w(Amsterdam afrobeat)
    subject[:country] = 'Netherlands'

    subject.values_at(:city, :country).should eq %w(Amsterdam Netherlands)
  end

  specify '#count + #merge!' do
    subject.count.should eq(1)
    subject.merge! one: 'more', and: 'another_one'
    subject.keys.sort.should eq %w(and genre one)

    subject.count.should eq(3)
    subject.size.should eq(3)
    subject.length.should eq(3)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hari-0.0.5 spec/hari/keys/hash_spec.rb