Files
codeocean/spec/lib/runner/strategy/poseidon/connection_spec.rb
dependabot[bot] bcb6409126 Bump rubocop from 1.57.2 to 1.58.0 and fix offenses
Bumps [rubocop](https://github.com/rubocop/rubocop) from 1.57.2 to 1.58.0.
- [Release notes](https://github.com/rubocop/rubocop/releases)
- [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rubocop/rubocop/compare/v1.57.2...v1.58.0)

---
updated-dependencies:
- dependency-name: rubocop
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-12-07 11:02:00 +01:00

71 lines
2.1 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Runner::Strategy::Poseidon::Connection do
let(:runner_id) { attributes_for(:runner)[:runner_id] }
let(:execution_environment) { create(:ruby) }
let(:strategy) { Runner::Strategy::Poseidon.new(runner_id, execution_environment) }
let(:connection_url) { 'wss://runners.example.org/websocket' }
let(:connection) { described_class.new(connection_url, strategy, nil) }
let(:websocket_client) { instance_double(Faye::WebSocket::Client) }
before do
allow(Faye::WebSocket::Client).to receive(:new).and_return(websocket_client)
allow(websocket_client).to receive(:on)
allow(websocket_client).to receive(:url).and_return(connection_url)
end
describe '#on_message' do
subject(:process_message) { connection.send(:on_message, websocket_event, nil) }
let(:websocket_event) { Faye::WebSocket::API::Event.create('message', data: message.to_json) }
before { allow(connection).to receive(:on_message).and_call_original }
shared_examples 'calls a message handler' do
it 'calls the corresponding handler' do
handler = :"handle_#{message[:type]}"
expect(connection).to receive(handler)
process_message
end
end
context "when type is 'start'" do
let(:message) { {type: 'start'} }
it_behaves_like 'calls a message handler'
end
context "when type is 'stdout'" do
let(:message) { {type: 'stdout', data: 'Standard Output'} }
it_behaves_like 'calls a message handler'
end
context "when type is 'stderr'" do
let(:message) { {type: 'stderr', data: 'Standard Error'} }
it_behaves_like 'calls a message handler'
end
context "when type is 'error'" do
let(:message) { {type: 'error', data: 'Error'} }
it_behaves_like 'calls a message handler'
end
context "when type is 'exit'" do
let(:message) { {type: 'exit', data: 0} }
it_behaves_like 'calls a message handler'
end
context "when type is 'timeout'" do
let(:message) { {type: 'timeout'} }
it_behaves_like 'calls a message handler'
end
end
end