Sha256: 8ce0be8c7cd23c048853f43be67a6c9c333a9ff81ffe55b296104b3a2f4738b0

Contents?: true

Size: 1.85 KB

Versions: 5

Compression:

Stored size: 1.85 KB

Contents

require 'spec_helper'

describe CaptainHoog::Hoogfile do
  let(:path) do
    File.expand_path(File.join(File.dirname(__FILE__),
                              '..', '..','fixtures', 'config', 'spec'))
  end

  let(:plugins_dir) do
    File.expand_path(File.join(File.dirname(__FILE__),
                              '..', '..','fixtures', 'plugins'))
  end

  describe 'class methods' do
    it 'provides .read' do
      expect(described_class).to respond_to(:read)
    end

    it 'provides .config' do
      expect(described_class).to respond_to(:config)
    end

    describe '.new' do
      it 'is not callable' do
        expect do
          described_class.new
        end.to raise_error NoMethodError
      end
    end

    describe '.read' do

      subject{ described_class.read(path) }

      it 'returns an instance of Hoogfile' do
        expect(subject).to be_instance_of(CaptainHoog::Hoogfile)
      end

      it 'evaluates erb' do
        expect(subject.plugins_dir).to include(plugins_dir)
        expect(subject.plugins_env).to have_key('foo plugin')
        expect(subject.plugins_env['foo plugin']).to be_instance_of(Hash)
        expect(subject.plugins_env['foo plugin']).to have_key('bar')
      end
    end

    describe 'instance methods' do

      subject{ described_class.read(path) }

      it 'provides #fetch' do
        expect(subject).to respond_to(:fetch)
      end

      describe 'fetch' do
        it 'returns the value for a given key' do
          expect(subject.fetch(:plugins_dir)).to include(plugins_dir)
        end

        it 'returns default value if give isnt found' do
          expect(subject.fetch(:foo, [])).to eq []
        end

        it 'raises an error if no default value is given and key not exists' do
          expect do
            subject.fetch(:foo)
          end.to raise_error IndexError
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
captain_hoog-2.0.0 spec/lib/captain_hoog/hoogfile_spec.rb
captain_hoog-1.1.1 spec/lib/captain_hoog/hoogfile_spec.rb
captain_hoog-1.1.0 spec/lib/captain_hoog/hoogfile_spec.rb
captain_hoog-1.0.2 spec/lib/captain_hoog/hoogfile_spec.rb
captain_hoog-1.0.1 spec/lib/captain_hoog/hoogfile_spec.rb