Sha256: e00a9ea0ba367156cbed6991c10453db564d417c664c14f05a9cc94ec49db5ad

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

require 'spec/spec_helper'
require 'ramaze/store/default'

context "initialize an Store" do
  db = 'db.yaml'

  def add hash = {}
    Books.merge!(hash)
  end

  specify "Store::Default.new" do
    Books = Ramaze::Store::Default.new(db)
    Books.db.should.is_a?(YAML::Store)
  end

  specify "store and retrieve something" do
    add 'Pickaxe' => 'good book'
    Books['Pickaxe'].should == 'good book'
  end

  specify "empty?" do
    add 'Pickaxe' => 'good book'

    Books.empty?.should == false
    Books.clear
    Books.empty?.should == true
  end

  specify "size" do
    Books.size.should == 0

    {
      'Pickaxe' => 'good book',
      '1984' => 'scary',
      'Brave new World' => 'interesting',
    }.each_with_index do |(title, content), i|
      add title => content
      Books.size.should == i + 1
    end
  end

  specify "Enumerable" do
    add 'Pickaxe' => 'good book', '1984' => 'scary'

    Books.each do |title, content|
      [title, content].compact.empty?.should == false
      Books[title].should == content
    end
  end

  specify "merge and merge!" do
    books = {'Pickaxe' => 'good book', '1984' => 'scary'}
    add books

    bnw = {'Brave new World' => 'interesting'}

    Books.merge(bnw).should == books.merge(bnw)

    Books[bnw.keys.first].should == nil

    Books.merge!(bnw).should == books.merge(bnw)

    Books[bnw.keys.first].should == bnw.values.first
    
    Books.size.should == 3
  end

  teardown do
    FileUtils.rm db
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ramaze-0.0.8 spec/tc_store.rb
ramaze-0.0.9 spec/tc_store.rb