Sha256: e176f5bd69061e110f939cb50291b7c1368dad10772697ea2668887449034c3e

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 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
      member.should_receive(:frozen?).and_return(true)
      member.should_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

3 entries across 3 versions & 1 rubygems

Version Path
axiom-types-0.0.5 spec/unit/axiom/types/type/class_methods/includes_spec.rb
axiom-types-0.0.4 spec/unit/axiom/types/type/class_methods/includes_spec.rb
axiom-types-0.0.3 spec/unit/axiom/types/type/class_methods/includes_spec.rb