require 'rails_helper' module Tables RSpec.describe Shift do describe '#each' do let(:shifts) do acc = [] described_class.new(initial_solution).each do |solution| acc << solution.tables.map(&:dup) end acc end context 'when there are two tables with two people each' do let(:initial_solution) do Distribution.new(min_per_table: 2, max_per_table: 2).tap do |distribution| distribution.tables << %i[a b].to_table distribution.tables << %i[c d].to_table end end it 'yields all possible shifts between the tables' do expect(shifts).to contain_exactly( [[:b], %i[c d a]], [[:a], %i[c d b]], [%i[b a d], [:c]], [%i[b a c], [:d]] ) end end end end end