Sha256: c674c316c91e6a561eecc565e55112a16e1d7c4baa6fc2f6306388e347ee6ae5

Contents?: true

Size: 1.86 KB

Versions: 9

Compression:

Stored size: 1.86 KB

Contents

require 'spec_helper'

module Danica
  module Common
    class Dummy
      include Common

      def to_tex
        'tex'
      end

      def to_gnu
        'gnu'
      end
    end

    class Dummy2
      include Common

      def to(format)
        "formatted: #{format}"
      end
    end
  end
end

describe Danica::Common do
  let(:clazz) { described_class::Dummy }
  subject { clazz.new }

  describe '#to_f' do
    it do
      expect do
        subject.to_f
      end.to raise_error(Danica::Exception::NotImplemented)
    end
  end

  describe '#to' do
    context 'when defining to_tex and to_gnu' do
      context 'when requesting :tex' do
        it 'has a string for latex' do
          expect(subject.to(:tex)).to eq('tex')
        end
      end
      context "when requesting 'tex'" do
        it 'has a string for latex' do
          expect(subject.to('tex')).to eq('tex')
        end
      end
      context 'when requesting :gnu' do
        it 'has a string for gnu' do
          expect(subject.to(:gnu)).to eq('gnu')
        end
      end
      context "when requesting 'gnu'" do
        it 'has a string for gnu' do
          expect(subject.to('gnu')).to eq('gnu')
        end
      end
      context "when requesting wrong format" do
        it do
          expect do
            subject.to('format')
          end.to raise_error(Danica::Exception::FormatNotFound)
        end
      end
    end
  end

  describe '#to_tex' do
    context 'when defined the #to method' do
      let(:clazz) { described_class::Dummy2 }
      it 'returns the call of #to(:tex)' do
        expect(subject.to_tex).to eq('formatted: tex')
      end
    end
  end

  describe '#to_gnu' do
    context 'when defined the #to method' do
      let(:clazz) { described_class::Dummy2 }
      it 'returns the call of #to(:gnu)' do
        expect(subject.to_gnu).to eq('formatted: gnu')
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
danica-2.6.4 spec/lib/danica/common_spec.rb
danica-2.6.3 spec/lib/danica/common_spec.rb
danica-2.6.2 spec/lib/danica/common_spec.rb
danica-2.6.1 spec/lib/danica/common_spec.rb
danica-2.6.0 spec/lib/danica/common_spec.rb
danica-2.5.1 spec/lib/danica/common_spec.rb
danica-2.5.0 spec/lib/danica/common_spec.rb
danica-2.4.4 spec/lib/danica/common_spec.rb
danica-2.4.3 spec/lib/danica/common_spec.rb