# Nathan Hinton 19 Dec 2025 # Defines tests for the buildings require './building' require './player' require './planet' require './space_object' RSpec.describe Building do describe '#initialize' do it 'Initializes to defaults' do building = Building.new(Player.new(), Planet.new()) expect(building.name).to eq 'default name' expect(building.type).to eq 'Central Post' end it 'initializes with custom values' do building = Building.new(Player.new(), Planet.new(), name: 'nathan house', type: 'Solar Farm') expect(building.name).to eq 'nathan house' expect(building.type).to eq 'Solar Farm' end it 'will raise error when invalid building type' do expect{Building.new(Player.new(), Planet.new(), name: 'error', type: 'error')}.to raise_error BuildingError, "Invalid building type" end end describe '#tick' do it 'Adds resources to the player' do player = Player.new() planet = Planet.new() type = 'Central Post' building = Building.new(player, planet, type: type) config = SpaceObject.new().get_config metal = config['buildings'][type]['produces']['metal'] credits = config['buildings'][type]['produces']['credits'] crystals = config['buildings'][type]['produces']['crystals'] expect(player.resources).to eq({'metal' => 0, 'crystals' => 0, 'credits' => 0}) expect{building.tick}.to_not raise_error expect(player.resources).to eq({ 'metal' => metal, 'crystals' => crystals, 'credits' => credits }) expect(planet.resources).to eq({ 'food' => 0, 'energy' => 0, 'people' => 10 }) end it 'Adds resources to the planet' do player = Player.new() planet = Planet.new() type = 'Nuclear Plant' building = Building.new(player, planet, type: type) config = SpaceObject.new().get_config expect(player.resources).to eq({'metal' => 0, 'crystals' => 0, 'credits' => 0}) expect{building.tick}.to_not raise_error expect(player.resources).to eq({ 'metal' => 0, 'crystals' => 0, 'credits' => 0 }) expect(planet.resources).to eq({ 'food' => 0, 'energy' => 1000, 'people' => 10 }) end end end