On 1/15/06, Daniel Hackney <chrono325 / gmail.com> wrote:
> Hello everyone!
>
> My problem today is a strange one indeed. I have set up a number of
> unit tests with Test::Unit for various parts of my program, but it
> appears that signals are simply not sent while using Test::Unit. I
> thought I had made some error (since I am relatively new to Ruby and
> Gtk) so I tried it in irb, and it worked perfectly!
>
> Here is what I typed into irb:
>
> irb(main):001:0> require 'gtk2'
> => true
> irb(main):002:0> buf = Gtk::TextBuffer.new
> => #<Gtk::TextBuffer:0xb769d9b0 ptr=0x826c280>
> irb(main):003:0> buf.signal_connect('insert_text') {|*args| puts "text
> inserted..." }
> => 1
> irb(main):004:0> buf.insert buf.start_iter, "Hello World!"
> text inserted...
> => #<Gtk::TextBuffer:0xb769d9b0 ptr=0x826c280>
> irb(main):005:0>
>
>
> And in my 'arg_test.rb'...
>
> require 'test/unit'
> require 'gtk2'
>
> class NeatTest < Test::Unit::TestCase
>   def test_setting_stuff
>     buf = Gtk::TextBuffer.new
>     buf.signal_connect('insert_text') {|*args| flunk }
>     buf.insert buf.start_iter, "Hello World!"
>     assert "Hello World!", buf.text
>   end
> end
>
> When I run 'ruby arg_test.rb' I get:
>
> $ ruby arg_test.rb
> Loaded suite arg_test
> Started
> .
> Finished in 0.034443 seconds.
>
> 1 tests, 1 assertions, 0 failures, 0 errors
>
> Notice the definite lack of the test failing. If I throw a 'puts
> buf.text' in there, it properly displays "Hello World!" on the
> console. I am using Ruby 1.8.3 on Ubuntu Breezy with Ruby-GNOME2
> 0.14.1.

Don't ask me why, but switch the order of the require statments. 
(load gtk2 before test/unit)

Anyone know why that's a problem?