diff options
| author | Szymon Szukalski <szymon@skas.io> | 2024-10-24 21:10:57 +1100 |
|---|---|---|
| committer | Szymon Szukalski <szymon@skas.io> | 2024-10-24 21:10:57 +1100 |
| commit | 9bc26146397acb5a216e20d5eb55bb2a582fdd3e (patch) | |
| tree | 4c02f13ca30e673417870114050f7a3d653ad47d /spec/family_spec.rb | |
| parent | 55475178a8c0e610103e37027cc0a7a387d72f91 (diff) | |
Implement key data model
- Added classes for Person, Gender, Family, FamilyTree
- Replaced FamilyTreeManager with FamilyTree
- Add FamilyFactory for seeding the initial FamilyTree for King Arthur and Queen Margaret
- Added a RelationshipManager for linking spouses correctly
- Refactored ActionFileExecutor for readability
- More test coverage
Diffstat (limited to 'spec/family_spec.rb')
| -rw-r--r-- | spec/family_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/family_spec.rb b/spec/family_spec.rb new file mode 100644 index 0000000..7247648 --- /dev/null +++ b/spec/family_spec.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require_relative '../lib/family' +require_relative '../lib/person' +require_relative '../lib/gender' + +RSpec.describe Family do + describe '#initialize' do + it 'creates a new family with a mother, father, and children' do + family = Family.new + expect(family.mother).to be_a(NilPerson) + expect(family.father).to be_a(NilPerson) + expect(family.children).to eq([]) + end + + it 'raises an error if the mother is not a female' do + jack = Person.new('Jack', Gender::MALE) + + expect { Family.new(jack) }.to raise_error(ArgumentError).with_message('Mother must be female') + end + + it 'raises an error if the father is not a male' do + jill = Person.new('Jill', Gender::FEMALE) + + expect { Family.new(NilPerson.new, jill) }.to raise_error(ArgumentError).with_message('Father must be male') + end + end + + describe 'assign_mother' do + it 'raises an error if the mother is not a female' do + family = Family.new + jack = Person.new('Jack', Gender::MALE) + + expect { family.assign_mother(jack) }.to raise_error(ArgumentError).with_message('Mother must be female') + end + end + + describe 'assign_father' do + it 'raises an error if the mother is not a female' do + family = Family.new + jill = Person.new('Jill', Gender::FEMALE) + + expect { family.assign_father(jill) }.to raise_error(ArgumentError).with_message('Father must be male') + end + end + + describe '#add_child' do + it 'adds a child to the family' do + family = Family.new + child = Person + + family.add_child(child) + expect(family.children).to eq([child]) + end + end + + describe '#get_siblings' do + it 'returns all siblings of a person' do + family = Family.new + child1 = Person.new('Jack', Gender::MALE) + child2 = Person.new('Jill', Gender::FEMALE) + child3 = Person.new('Phil', Gender::MALE) + + family.add_child(child1) + family.add_child(child2) + family.add_child(child3) + + expect(family.get_siblings(child1)).to eq([child2, child3]) + end + end +end |
