Sha256: b4f81b59e7081f02be006aa0b34a25459f510ba5439d8d22a8018e0d2a0e64c1

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

require 'test_helper'

module Vedeu
  EntityNotFound = Class.new(StandardError)

  class RepositoryTestClass
    include Repository

    def in_memory
      {}
    end
    alias_method :storage, :in_memory

    def not_found(name)
      fail EntityNotFound
    end
  end # RepositoryTestClass

  describe Repository do

    describe '#all' do
      it 'returns a Hash' do
        RepositoryTestClass.new.all.must_be_instance_of(Hash)
      end

      it 'returns the whole repository' do
        RepositoryTestClass.new.all.must_equal({})
      end
    end

    describe '#find' do
      it 'raises an exception when the entity cannot be found' do
        proc { RepositoryTestClass.new.find('terbium') }
          .must_raise(EntityNotFound)
      end
    end

    describe '#registered' do
      it 'returns an Array' do
        RepositoryTestClass.new.registered.must_be_instance_of(Array)
      end

      it 'returns a collection of the names of all the registered entities' do
        RepositoryTestClass.new.registered.must_equal([])
      end
    end

    describe '#registered?' do
      it 'returns a FalseClass' do
        RepositoryTestClass.new.registered?('terbium')
          .must_be_instance_of(FalseClass)
      end

      it 'returns false when the entity is not registered' do
        RepositoryTestClass.new.registered?('terbium').must_equal(false)
      end
    end

    describe '#reset' do
      it 'returns a Hash' do
        RepositoryTestClass.new.reset.must_be_instance_of(Hash)
      end

      it 'resets the repository' do
        RepositoryTestClass.new.reset.must_equal({})
      end
    end

  end # Repository

end # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.2.7 test/lib/vedeu/support/repository_test.rb
vedeu-0.2.6 test/lib/vedeu/support/repository_test.rb
vedeu-0.2.5 test/lib/vedeu/support/repository_test.rb