# 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