@@ -881,6 +881,40 @@ def client_cap_hash(client_cap_string, dynamic_reg)
881881 )
882882 end
883883
884+ describe 'PuppetLanguageServer::MessageHandler' do
885+ let ( :server_options ) { { puppet_version : '5.5.1' } }
886+ let ( :server ) { double ( 'PuppetEditorServices::Server' ) }
887+ let ( :connection ) { double ( 'PuppetEditorServices::Protocol::Connection' , id : 'some_id' ) }
888+ let ( :protocol ) { double ( 'PuppetEditorServices::Protocol::JsonRPC' ) }
889+ let ( :handler_object ) { PuppetLanguageServer ::MessageHandler . new ( protocol ) }
890+
891+ before do
892+ allow ( server ) . to receive ( :server_options ) . and_return ( server_options )
893+ allow ( connection ) . to receive ( :server ) . and_return ( server )
894+ allow ( protocol ) . to receive ( :connection ) . and_return ( connection )
895+ end
896+
897+ context 'When receiving a notification' do
898+ context '.notification_initialized' do
899+ it 'sends a warning message when Puppet versions are mismatched' do
900+ allow ( Puppet ) . to receive ( :version ) . and_return ( '6.0.0' )
901+
902+ expected_message = {
903+ 'type' => LSP ::MessageType ::WARNING ,
904+ 'message' => "Unable to use Puppet version '#{ server_options [ :puppet_version ] } ' as it is not available. Using version '#{ Puppet . version } ' instead."
905+ }
906+
907+ expect ( protocol ) . to receive ( :encode_and_send ) do |arg |
908+ expect ( arg ) . to be_a ( PuppetEditorServices ::Protocol ::JsonRPCMessages ::NotificationMessage )
909+ expect ( arg . params ) . to eq ( expected_message )
910+ end
911+
912+ handler_object . notification_initialized ( nil , nil )
913+ end
914+ end
915+ end
916+ end
917+
884918 # initialized - https://github.com/Microsoft/language-server-protocol/blob/master/protocol.md#initialized
885919 describe '.notification_initialized' do
886920 let ( :notification_method ) { 'initialized' }
0 commit comments