require_relative 'test_helper.rb' class Thok < Qt::Widget signal :whatever end class TestWidget < Test::Unit::TestCase def setup @thok = Thok.new end should 'have a whatever_signal method' do assert_equal 1, @thok.methods.grep( /^whatever_signal$/ ).size assert_raise ArgumentError do @thok.whatever_signal( 'hello' ) end assert_nothing_raised do @thok.whatever_signal( 'hello'.to_variant ) end end should 'have a whatever emitter' do assert_equal 1, @thok.methods.grep( /^whatever$/ ).size assert_nothing_raised { @thok.whatever } assert_nothing_raised { @thok.whatever 1 } assert_nothing_raised { @thok.whatever 1,2,3 } assert_nothing_raised { @thok.whatever [4,5,6] } end should 'have an on_whatever handler' do assert_equal 1, @thok.methods.grep( /^on_whatever$/ ).size end context 'on_whatever handler' do should 'handle nil args' do @thok.on_whatever do |arg| assert_nil arg end @thok.whatever @thok.whatever( nil ) end should 'handle single args' do @thok.on_whatever do |arg| assert_not_nil arg assert_not_equal Array, arg.class end @thok.whatever 1 @thok.whatever 'hello' end should_eventually 'handle objects' do NVP = Struct.new :name, :value nvp = NVP.new nvp.name = 'how' nvp.value = 'that' @thok.on_whatever do |arg| assert_not_nil arg assert_equal NVP, arg.class end @thok.whatever nvp end should 'handle arg lists' do @thok.on_whatever do |arg1,arg2| assert_not_nil arg1 assert_not_nil arg2 assert_not_equal Array, arg1.class assert_not_equal Array, arg2.class end @thok.whatever 1,2 @thok.whatever 'hello','there' end should 'handle a single array' do @thok.on_whatever do |ary| assert_not_nil ary assert_equal Array, ary.class assert_equal 3, ary.size assert_equal [4,5,6], ary end @thok.whatever [4,5,6] end should_eventually 'handle multiple arrays' do @thok.on_whatever do |ary1,ary2| assert_not_nil ary1 assert_not_nil ary2 assert_equal Array, ary1.class assert_equal Array, ary2.class assert_equal 3, ary1.size assert_equal 3, ary2.size # fails here because ary1 is an array of variants puts "ary1: #{ary1.inspect}" assert_equal [4,5,6], ary1 assert_equal [7,8,9], ary2 end @thok.whatever( [4,5,6], [7,8,9] ) end end end