Fixed tests. Need to check for damage from AI code

This commit is contained in:
2026-06-11 16:39:58 -06:00
parent df68358a2e
commit 6d2c2162f0
9 changed files with 149 additions and 78 deletions
+14 -4
View File
@@ -36,8 +36,12 @@ require 'json'
HOSTNAME = 'localhost'
PORT = 2000
server_pid = spawn('rake serve', out: File::NULL, err: File::NULL)
sleep(0.5)
RSpec.describe "app.rb" do
let(:client) {TCPSocket.open(HOSTNAME, PORT)}
it 'responds with an error when a non JSON request is sent' do
client.puts 'this is non json test data'
expect(JSON.parse(client.gets)).to eq({'type' => 'error', 'domain' => 'error', 'payload' => 'Server unable to decode JSON'})
@@ -46,10 +50,6 @@ RSpec.describe "app.rb" do
describe 'type: hello' do
describe 'domain: player' do
describe 'payload: player_id, faction' do
it 'Connects the player:' do
client.puts({'type' => 'hello', 'domain' => 'player', 'payload' => {'player_id' => 'test_player', 'faction' => 'good'}}.to_json)
expect(JSON.parse(client.gets)).to eq('')
end
end
end
end
@@ -73,5 +73,15 @@ RSpec.describe "app.rb" do
end
describe 'type: error' do
it 'returns an error when a player does not exist' do
client.puts({'type' => 'hello', 'domain' => 'player', 'payload' => {'player_id' => 'test_esfe_player', 'faction' => 'good'}}.to_json)
expect(JSON.parse(client.gets)).to eq({"payload" => "Player not registered!",
"request_id" => -1,
"type" => "error",}
)
end
end
end
Process.kill('TERM', server_pid)
Process.wait(server_pid)
+9 -19
View File
@@ -1,6 +1,7 @@
# Nathan Hinton 24 Dec 2025
# Test file for the player
# spec/player_spec.rb
require 'rspec'
require 'json'
require 'game/player' # adjust the path if needed
@@ -46,16 +47,16 @@ RSpec.describe Player do
end
# ------------------------------------------------------------------
# create_new
# set_resources
# ------------------------------------------------------------------
describe '#create_new' do
describe '#set_resources' do
let(:credits) { 1000 }
let(:metal) { 500 }
let(:crystals) { 200 }
let(:fuel) { 300 }
it 'stores the resources hash correctly' do
subject.create_new(credits, metal, crystals, fuel)
subject.set_resources(credits, metal, crystals, fuel)
expect(subject.player_resources).to eq(
'credits' => credits,
'metal' => metal,
@@ -165,7 +166,7 @@ RSpec.describe Player do
let(:request_id) { 42 }
before do
subject.create_new(credits, metal, crystals, fuel)
subject.set_resources(credits, metal, crystals, fuel)
subject.player_planets << double('planet', info_update: 'test_data')
subject.player_ships << double('ship')
end
@@ -231,7 +232,7 @@ RSpec.describe Player do
let(:fuel) { 300 }
before do
subject.create_new(credits, metal, crystals, fuel)
subject.set_resources(credits, metal, crystals, fuel)
end
it 'writes a marshaled file and can read it back' do
@@ -245,7 +246,7 @@ RSpec.describe Player do
'credits' => credits,
'metal' => metal,
'crystals' => crystals,
'fuel' => fuel
'fuel' => fuel,
)
end
end
@@ -260,7 +261,7 @@ RSpec.describe Player do
let(:fuel) { 300 }
before do
subject.create_new(credits, metal, crystals, fuel)
subject.set_resources(credits, metal, crystals, fuel)
end
it 'returns a hash with the expected keys' do
@@ -281,15 +282,4 @@ RSpec.describe Player do
expect(new_player.player_resources).to eq(subject.player_resources)
end
end
end# Nathan Hinton 24 Dec 2025
# Test file for the player
require 'game/player'
RSpec.describe Player do
describe '#initialize' do
it 'initializes with a player id' do
end
end
end