Sha256: 458c4fa1ffb4374894a34b804acc272e2d2b56fca5272cb6d59c461c836108ed

Contents?: true

Size: 1.5 KB

Versions: 10

Compression:

Stored size: 1.5 KB

Contents

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

10 entries across 10 versions & 1 rubygems

Version Path
licensee-9.11.0 spec/licensee/license_rules_spec.rb
licensee-9.10.1 spec/licensee/license_rules_spec.rb
licensee-9.10.0 spec/licensee/license_rules_spec.rb
licensee-9.9.4 spec/licensee/license_rules_spec.rb
licensee-9.9.3 spec/licensee/license_rules_spec.rb
licensee-9.9.2 spec/licensee/license_rules_spec.rb
licensee-9.9.1 spec/licensee/license_rules_spec.rb
licensee-9.9.0 spec/licensee/license_rules_spec.rb
licensee-9.9.0.beta.3 spec/licensee/license_rules_spec.rb
licensee-9.9.0.beta.2 spec/licensee/license_rules_spec.rb