require 'rails_helper' module Tables RSpec.describe Distribution do describe '#local_discomfort' do let(:service) { described_class.new(min_per_table: 5, max_per_table: 5) } before { service.tables = [table] } context 'when there is just one group in the table' do let(:table) do create_list(:guest, 3).each do |guest| guest.affinity_group_list.add('family') guest.save! end end it { expect(service.send(:local_discomfort, table)).to eq(0) } end context 'when the table contains two groups' do let(:table) do guests = create_list(:guest, 3) guests[0].affinity_group_list.add('family') guests[1].affinity_group_list.add('friends') guests[2].affinity_group_list.add('family') guests.each(&:save!) end it { expect(service.send(:local_discomfort, table)).to eq(10) } end context 'when the table contains three groups' do let(:table) do guests = create_list(:guest, 3) guests[0].affinity_group_list.add('family') guests[1].affinity_group_list.add('friends') guests[2].affinity_group_list.add('work') guests.each(&:save!) end it { expect(service.send(:local_discomfort, table)).to eq(20) } end end end end