Files
space_game_server/game/spec/planet_spec.rb
T
2025-12-19 09:16:48 -07:00

53 lines
1.5 KiB
Ruby

# Nathan Hinton 2 Oct 2025
require './planet'
require './player'
RSpec.describe Planet do
let(:seed) { 12345 }
let(:random) { Random.new(seed) }
let(:planet) { Planet.new(random) }
let(:player_1) { Player.new('tester 01') }
let(:player_2) { Player.new('tester 02') }
describe '#initialize' do
it 'stores the random off' do
expect(planet.instance_variable_get(:@random)).to eq random
end
it 'creates a production rate' do
expect(planet.instance_variable_get(:@prod_rate)).to eq Random.new(seed).rand
end
it 'sets a resource' do
expect(planet.instance_variable_get(:@resource)).to eq PLANET_PRODUCTION_RESOURCES[(Random.new(seed).rand * PLANET_PRODUCTION_RESOURCES.length).floor]
end
it 'has a nil owner' do
expect(planet.instance_variable_get(:@owner)).to eq nil
end
end # describe #initialize
describe '#change_owner' do
it 'allows an ownership change when the current owner is nil' do
expect(planet.change_owner(player_1)).to eq true
expect(planet.instance_variable_get(:@owner)).to eq player_1
end
it 'does not change when already owned' do
planet.change_owner(player_2)
expect(planet.change_owner(player_1)).to eq false
expect(planet.instance_variable_get(:@owner)).to eq player_2
end
end
describe '#tick' do
it 'adds resources to the Players storage' do
planet.change_owner(player_1)
planet.tick
expect(player_1.resources).to eq('')
end
end
end