RSpec.describe 'struct builder', '#call' do subject(:builder) { ROM::Repository::StructBuilder.new } let(:input) { [:users, [:header, [[:attribute, :id], [:attribute, :name]]]] } before { builder[*input] } it 'generates a struct for a given relation name and columns' do struct = builder.class.cache[input.hash] user = struct.new(id: 1, name: 'Jane') expect(user.id).to be(1) expect(user.name).to eql('Jane') expect(user[:id]).to be(1) expect(user[:name]).to eql('Jane') expect(Hash[user]).to eql(id: 1, name: 'Jane') expect(user.inspect).to eql('#') expect(user.to_s).to match(/\A#\z/) end it 'stores struct in the cache' do expect(builder.class.cache[input.hash]).to be(builder[*input]) end end