Sha256: 1bec82be2ce4f8ffd9b0bcac7de5fe43a6d9df1722cf6fe603dbed56f5c1fa8c

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'spec_helper'

module Models
  module Descriptors
    module WalksLikeADuck
    end

    module TalksLikeADuck
    end

    module FloatsLikeADuck
    end

    module IsAWitch
    end
  end
end

class Model < ActiveRecord::Base
  include DescendantsDescribable

  describe_descendants_with(Models::Descriptors) do
    walks_like_a_duck do
      type :badger
      type :hadger do
        is_a_witch
      end

      floats_like_a_duck do
        type :tadger
      end

      is_a_witch do
        type :madger
      end
    end

    talks_like_a_duck do
      type :fadger

      floats_like_a_duck do
        type :ladger do
          is_a_witch
        end
      end
    end
  end
end

describe DescendantsDescribable do

  describe '.type - for subclass generation' do
    it 'creates new subclass of each type' do
      [Badger, Hadger, Fadger, Ladger, Tadger].each do |klass|
        expect(klass < Model).to be_true
      end
    end
  end

  describe 'dynamic module name methods' do
    subject { DescendantsDescribable::DescendantsDescriptor.new(Model, Models::Descriptors) }
    it { should respond_to(:is_a_witch) }

    it 'includes module into new class' do
      expect(Badger < Models::Descriptors::WalksLikeADuck).to be_true
      expect(Hadger < Models::Descriptors::IsAWitch).to be_true
      expect(Fadger < Models::Descriptors::TalksLikeADuck).to be_true
      expect(Ladger < Models::Descriptors::FloatsLikeADuck).to be_true
      expect(Ladger < Models::Descriptors::TalksLikeADuck).to be_true
      expect(Ladger < Models::Descriptors::IsAWitch).to be_true

      expect(Tadger < Models::Descriptors::FloatsLikeADuck).to be_true
      expect(Tadger < Models::Descriptors::WalksLikeADuck).to be_true

      expect(Madger < Models::Descriptors::WalksLikeADuck).to be_true
      expect(Madger < Models::Descriptors::IsAWitch).to be_true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
descendants_describable-0.0.2 spec/descendants_describable_spec.rb