Sha256: 1ea48fdf31d36802b5441f45872b6f3f25826d329a41811ab0d42adb28f4c19c

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

RSpec.describe Licensee::LicenseRules do
  let(:mit) { Licensee::License.find('mit') }
  subject { mit.rules }

  Licensee::Rule.groups.each do |group|
    context "the #{group} rule group" do
      it 'responds as a hash key string' do
        expect(subject[group]).to be_a(Array)
      end

      it 'responds as a hash key symbol' do
        expect(subject[group.to_sym]).to be_a(Array)
      end

      it 'responds as a method' do
        expect(subject.public_send(group.to_sym)).to be_a(Array)
      end
    end
  end

  context 'created from a license' do
    subject { described_class.from_license(mit) }

    it 'exposes the rules' do
      expect(subject.permissions.first.label).to eql('Commercial use')
    end
  end

  context 'created from a meta' do
    subject { described_class.from_meta(mit.meta) }

    it 'exposes the rules' do
      expect(subject.permissions.first.label).to eql('Commercial use')
    end
  end

  context 'created from a hash' do
    let(:hash) { { 'permissions' => Licensee::Rule.all } }
    subject { described_class.from_hash(hash) }

    it 'exposes the rules' do
      expect(subject.permissions.first.label).to eql('Commercial use')
    end
  end

  context 'to_h' do
    let(:hash) { subject.to_h }
    let(:expected) do
      {
        conditions:  subject.conditions.map(&:to_h),
        permissions: subject.permissions.map(&:to_h),
        limitations: subject.limitations.map(&:to_h)
      }
    end

    it 'Converts to a hash' do
      expect(hash).to eql(expected)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
licensee-9.12.0 spec/licensee/license_rules_spec.rb