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.10.6 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.5 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.4 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.3 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.2 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.1 spec/roles/typable_spec.rb
fedux_org-stdlib-0.10.0 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.8 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.7 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.6 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.5 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.4 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.2 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.1 spec/roles/typable_spec.rb
fedux_org-stdlib-0.9.0 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.11 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.10 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.9 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.8 spec/roles/typable_spec.rb
fedux_org-stdlib-0.8.7 spec/roles/typable_spec.rb