Sha256: 6786c69c314e322359d236ad4d1fa8b161d6bc140acfc4ad6307a44318f586f5

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

describe StatusCat::Checkers::Base do

  let(:checker) { StatusCat::Checkers::Base.new }

  describe '#name' do

    it 'generates a symbolized class name' do
      expect(checker.name).to be(:base)
    end
  end

  describe 'attributes' do

    it 'has value and status readers' do
      expect(checker.value).to be_nil
      expect(checker.status).to be_nil
    end
  end

  describe '#to_s' do

    before(:each) do
      allow(checker).to receive(:value).and_return('secret')
      allow(checker).to receive(:status).and_return('fail')
    end

    it 'generates a string' do
      expect(checker.to_s).to eql("base | secret | fail\n")
    end

    it 'accepts a format' do
      expect(checker.to_s('%s * %s * %s')).to eql('base * secret * fail')
    end
  end

  describe '#fail_on_exception' do

    it 'returns an exception if raised from the block given' do
      error = 'test'
      status = checker.send(:fail_on_exception) { raise error }
      expect(status.to_s).to eql(error)
    end

    it 'returns the results of the block when there is no exception' do
      status = checker.send(:fail_on_exception) { true }
      expect(status).to be(true)
    end
  end

  describe '#gem_missing?' do

    it 'returns false when present is true' do
      expect(checker.send(:gem_missing?, 'foo', true)).to be(false)
    end

    it 'returns true when present is false' do
      expect(checker.send(:gem_missing?, 'foo', false)).to be(true)
    end

    it 'sets status when present is false' do
      checker.send(:gem_missing?, 'foo', false)
      expect(checker.status).to eql('foo gem is not installed')
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
status_cat-5.2.1 spec/lib/status_cat/checkers/base_spec.rb
status_cat-5.2.0 spec/lib/status_cat/checkers/base_spec.rb
status_cat-5.0.2 spec/lib/status_cat/checkers/base_spec.rb
status_cat-5.0.1 spec/lib/status_cat/checkers/base_spec.rb
status_cat-5.0.0 spec/lib/status_cat/checkers/base_spec.rb