Sha256: ebb2438b99416e0d52d9fdac08bfb3ede39ee54252805733f5c3c06dcec77387

Contents?: true

Size: 1.57 KB

Versions: 4

Compression:

Stored size: 1.57 KB

Contents

require 'test_helper'

class CallbackTestException < RuntimeError; end

describe 'An exception in a callback' do
  describe 'for signals' do
    let(:object) { Gtk::Window.new :toplevel }

    before do
      object.signal_connect 'destroy' do
        raise CallbackTestException, 'Boom'
      end
    end

    describe 'when the signal is emitted synchronously' do
      it 'raises an error' do
        -> { GObject.signal_emit object, 'destroy' }.must_raise CallbackTestException
      end
    end

    describe 'when the signal is emitted during an event loop' do
      it 'causes loop run to be terminated with an exception' do
        GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
          GObject.signal_emit object, 'destroy'
          false
        end
        # Guard against runaway loop
        @guard = GLib.timeout_add(GLib::PRIORITY_DEFAULT, 1000) { Gtk.main_quit }
        proc do
          Gtk.main
        end.must_raise CallbackTestException
      end

      after do
        GLib.source_remove @guard
      end
    end
  end

  describe 'for other callbacks' do
    describe 'when the callback occurs during an event loop' do
      it 'causes loop run to be terminated with an exception' do
        GLib.timeout_add GLib::PRIORITY_DEFAULT, 1 do
          raise CallbackTestException, 'Boom'
        end
        # Guard against runaway loop
        @guard = GLib.timeout_add(GLib::PRIORITY_DEFAULT, 1000) { Gtk.main_quit }
        proc do
          Gtk.main
        end.must_raise CallbackTestException
      end

      after do
        GLib.source_remove @guard
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gir_ffi-gtk-0.14.1 test/callback_exceptions_test.rb
gir_ffi-gtk-0.14.0 test/callback_exceptions_test.rb
gir_ffi-gtk-0.13.1 test/callback_exceptions_test.rb
gir_ffi-gtk-0.13.0 test/callback_exceptions_test.rb