Sha256: ba151fe5e8fafdb7234572e4dbc73d368a593256272f1457b1e9decf020e65b3

Contents?: true

Size: 1.09 KB

Versions: 11

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Axiom::Types::Type, '.includes' do
  subject { object.includes(*members) }

  let(:object) { Class.new(described_class) }

  context 'with a non-empty list' do
    let(:member)  { Object.new       }
    let(:members) { [member, member] }

    it_should_behave_like 'a command method'

    it 'adds a constraint that returns true for a valid member' do
      should include(member)
    end

    it 'adds a constraint that returns false for an invalid member' do
      should_not include(nil)
    end

    it 'freezes the members' do
      expect { subject }.to change(member, :frozen?).from(false).to(true)
    end

    it 'removes duplicate members' do
      expect(member).to receive(:freeze).and_return(member)
      expect(member).to receive(:hash).exactly(3).times.and_return(1)
      subject
      expect(object).to include(member)
    end
  end

  context 'with an empty set' do
    let(:members) { [] }

    it_should_behave_like 'a command method'

    it 'adds a constraint that returns false' do
      should_not include(Object.new)
    end
  end
end

Version data entries

11 entries across 9 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/axiom-types-0.1.1/spec/unit/axiom/types/type/class_methods/includes_spec.rb
axiom-types-0.1.1 spec/unit/axiom/types/type/class_methods/includes_spec.rb
axiom-types-0.1.0 spec/unit/axiom/types/type/class_methods/includes_spec.rb