Sha256: 21056cc243e27fb6cc05d29553da4b0c85784a17e611ab54cf65fd64085a612c

Contents?: true

Size: 1.89 KB

Versions: 57

Compression:

Stored size: 1.89 KB

Contents

# encoding: utf-8
require 'spec_helper'
require 'fedux_org_stdlib/roles/typable'

RSpec.describe FeduxOrgStdlib::Roles::Typable do
  let(:klass) do
    Class.new do
      include FeduxOrgStdlib::Roles::Typable

      attr_reader :source_path

      def initialize(source_path:)
        @source_path = Pathname.new(source_path)
      end
    end
  end

  context 'use' do
    let(:klass) do
      Class.new do
        include FeduxOrgStdlib::Roles::Typable

        def initialize(source_path:)
          @source_path = Pathname.new(source_path)
        end
      end
    end

    it 'fails if source_path-method is missing' do
      object = klass.new(source_path: 'blub/image.png')
      expect do
        object.type
      end.to raise_error NoMethodError
    end
  end

  context '#type' do
    it 'returns type' do
      object = klass.new(source_path: 'blub/image.png')
      expect(object.type).to eq :image
    end
  end

  context '#type?' do
    it 'checks type' do
      object = klass.new(source_path: 'blub/image.png')
      expect(object).not_to be_type :script
      expect(object).to be_type :image
    end
  end

  context 'extname' do
    it 'returns file extension' do
      object = klass.new(source_path: 'blub/image.png')
      expect(object.extnames).to eq %w(.png)
    end

    it 'returns all file extensions' do
      object = klass.new(source_path: 'blub/image.png.gz')
      expect(object.extnames).to eq %w(.png .gz)
    end
  end

  context '#extnames?' do
    it 'checks if object has extnames' do
      object = klass.new(source_path: 'blub/image.png.gz')
      expect(object).to be_extnames %w(.png .gz)
      expect(object).to be_extnames %w(.png )
    end
  end

  context '#valid?' do
    it 'succeeds if file exist' do
      touch_file 'blub/image.png'

      object = klass.new(source_path: 'blub/image.png')

      in_current_dir do
        expect(object).to be_valid
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.8.6 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.5 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.4 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.3 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.0 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.33 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.31 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.30 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.29 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.28 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.27 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.26 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.25 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.24 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.23 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.22 spec/roles/typable_spec.rb
fedux_org-stdlib-0.7.21 spec/roles/typable_spec.rb