require ‘minitest/autorun’
require ‘gtk2’
class TestWindow < MiniTest::Unit::TestCase
def test_window_fires_event
closing = false
window = Gtk::Window.new
window.signal_connect(‘delete_event’) { puts ‘closing’; closing =
true; false }
window.signal_emit(‘delete_event’,
Gdk::EventAny.new(Gdk::Event::DELETE))
puts “HAS BEEN CLICKED: #{closing}”
assert_equal true, closing
end
end
#TestWindow.new.test_window_fires_event
I have a problem when trying to test that I’ve correctly connected a
signal by ensuring the block is fired when emitting it. I’ve simplified
the test a great deal. This is a functional test and as such I really
want the block to be executed.
If I run the code directly (uncomment the last line and comment out
MiniTest::Unit::TestCase and the assert then it runs fine. It fails,
however, when running it as a test. I guess it’s got something to do
with the context it’s run in as a test and how signal_connect stores the
block but I’m stretching my knowledge of blocks and GTK signals here.
I’d be grateful for any suggestions.
Thanks,
Phil