Sha256: d63b9aa49a18a728dbf655b04e325089f6b6ce487c71f6ee9b4179df8dc5cfdd

Contents?: true

Size: 1.58 KB

Versions: 5

Compression:

Stored size: 1.58 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
        lambda { 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

5 entries across 5 versions & 1 rubygems

Version Path
gir_ffi-gtk-0.12.1 test/callback_exceptions_test.rb
gir_ffi-gtk-0.12.0 test/callback_exceptions_test.rb
gir_ffi-gtk-0.11.0 test/callback_exceptions_test.rb
gir_ffi-gtk-0.10.0 test/callback_exceptions_test.rb
gir_ffi-gtk-0.9.0 test/callback_exceptions_test.rb