# wxRuby and Test::Unit (or Rspec or whatever)

**URL:** <https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103>\
**Category:** wxRuby\
**Created:** [January 31, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103 "2009-01-31T14:51:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [January 31, 2009, 2:51pm UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/1 "2009-01-31T14:51:36Z")

</div>

This is my first post to the mailing list, so “Hello All”.

I have a question about wxRuby and having automated tests of my GUI.  
Is anyone doing this? I have plenty of experience testing Rails apps  
with Test::Unit and Rspec, but I couldn’t find any examples for wxRuby.

At the moment I start my app by calling MyApp.new.mainloop, but this  
method blocks until I quit it. Should I start another thread to run  
my tests, sending messages to my running application?

If anyone has a simple example to show me, that would be fantastic.

Thanks,

Clinton.

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [January 31, 2009, 3:44pm UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/2 "2009-01-31T15:44:40Z")

</div>

Clinton,

I’ve been looking for the same thing. I came across wx-nobbie in  
rubyforge which looks like Webrat for wx apps but it is quite old and  
doesn’t work with the latest wx.

I’ve started looking at updating wx-nobbie but the tests are failing on  
find\_window\_by\_name.

wx-nobbie does use a separate thread as you suggested.

If you’re interested, I could put wx-nobbie up on github and we could  
take it from there.

Bryan

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 1, 2009, 4:26am UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/3 "2009-02-01T04:26:41Z")

</div>

Bryan A. wrote:

> take it from there.  
> It’d be good to see nobbie updated. I’d be happy to help get it working  
> with latest wxRuby.

alex

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 1, 2009, 4:30am UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/4 "2009-02-01T04:30:12Z")

</div>

Hi Clinton

Clinton Forbes wrote:

> I have a question about wxRuby and having automated tests of my GUI.  
> Is anyone doing this? I have plenty of experience testing Rails apps  
> with Test::Unit and Rspec, but I couldn’t find any examples for wxRuby.

There are some in the wxRuby repository and tarball which use test/unit

[http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test\_item\_data.rb](http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test_item_data.rb)  
(Ruby 1.8)  
[http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test\_clipboard.rb](http://wxruby.rubyforge.org/svn/trunk/wxruby2/tests/test_clipboard.rb)  
(Ruby 1.9)

> At the moment I start my app by calling MyApp.new.mainloop, but this  
> method blocks until I quit it. Should I start another thread to run  
> my tests, sending messages to my running application?

For simple tests, you don’t need to run threads. Just call the test  
library’s method to run whatever tests you want within your app’s  
on\_init method, or Wx::App.run { … } block. The way to do this with  
Ruby’s standard test/unit varies between ruby versions 1.8 and 1.9. I  
haven’t used rspec but i expect there’s something similar.

If you return false or nil from the application start-up, then the  
program should exit cleanly.

alex

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 10, 2009, 4:03am UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/5 "2009-02-10T04:03:18Z")

</div>

Turns Nobbie works just fine with current wxRuby, the problem was with  
the Gem’s dependence on an old wxSugar. When I just updated wxSugar  
most of the issues disappeared.

I’ve uploaded it to [GitHub](http://github.com/bryan-ash/wx-nobbie/tree) with a  
gemspec, so it can be installed:

gem sources -a [http://gems.github.com](http://gems.github.com)  
gem install bryan-ash-wx-nobbie

All the tests pass, but they do give a number of warnings like:

listen is deprecated, use evt\_xxx directly  
(C:/ruby/lib/ruby/gems/1.8/gems/bryan-ash-wx-nobbie-0.0.3.2/test/suite/app.rb:19:in  
`initialize’)

Bryan

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 10, 2009, 4:05am UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/6 "2009-02-10T04:05:40Z")

</div>

Bryan A. wrote:

> I’ve uploaded it to [GitHub](http://github.com/bryan-ash/wx-nobbie/tree) with a

I guess posting links is easier than I thought, all I needed was:  
[http://github.com/bryan-ash/wx-nobbie/tree](http://github.com/bryan-ash/wx-nobbie/tree)

Bryan

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 11, 2009, 7:07pm UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/7 "2009-02-11T19:07:49Z")

</div>

Alex F. wrote:

> The test runs well for a while for me, but then segfaults after a while.  
> This is with Ruby 1.8.6 on OS X, using the latest wxRuby. Strangely, the  
> backtrace of the segfault is not in wxRuby code anywhere.

The original author, Paul, had mentioned that in the KNOWN\_ISSUES. I’m  
still waiting for someone to donate a MacBook Pro to me so I can  
investigate these 😉

Bryan

---

<div class="post-metadata">

**Author:** ![Clinton\_Forbes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e79b87/32.png) [@Clinton\_Forbes](https://www.ruby-forum.com/u/Clinton_Forbes)\
**Post date:** [February 11, 2009, 6:34pm UTC](https://www.ruby-forum.com/t/wxruby-and-test-unit-or-rspec-or-whatever/159103/8 "2009-02-11T18:34:55Z")

</div>

Bryan A. wrote:

> Turns Nobbie works just fine with current wxRuby, the problem was with  
> the Gem’s dependence on an old wxSugar. When I just updated wxSugar  
> most of the issues disappeared.
> 
> I’ve uploaded it to [http://github.com/bryan-ash/wx-nobbie/tree](http://github.com/bryan-ash/wx-nobbie/tree) with a  
> gemspec, so it can be installed:

Thanks for doing this. It looks good. I never got it working before.

> All the tests pass,

The test runs well for a while for me, but then segfaults after a while.  
This is with Ruby 1.8.6 on OS X, using the latest wxRuby. Strangely, the  
backtrace of the segfault is not in wxRuby code anywhere.

> but they do give a number of warnings like:
> 
> listen is deprecated, use evt\_xxx directly

‘listen’ was in wxSugar for a while as an experiment in better event  
handling syntax. In the end most of what ‘listen’ did was rolled into  
core wxRuby, but there didn’t seem to be any advantage to writing

listen :text

rather than just

evt\_text

So I deprecated it.

alex
