Twitter GitHub Facebook Instagram dirv.me

Daniel Irvine on building software

Walkthrough: Test-driven development of a Qt app in Ruby, part 5

19 June 2014

Here’s what we’ve covered in this series:

  • In part 1 we used RSpec matchers that assert on objects that are found using object_name. Using expectations in this way is a great way to build fluid tests that are not dependent on the visual structure of your application.
  • We also used SimpleCov from the very beginning to ensure we were always at 100% coverage.
  • In part 2 we used an RSpec shared context that houses all of our Qt helper methods and initialization code.
  • In part 3 we used RSpec stubs to enable us to test the messages sent to Qt without actually starting any ‘real’ GUI widgets.
  • In part 4 we used emit to ensure that signals and slots were connected correctly.

To reiterate a few points:

  • The children property on widget only returns immediate children. To recursively search a widget tree, use the find_children method. This takes a widget type parameter and optionally an object name:
    all_labels = window.find_children(Qt::Label)
    

    Lately I’ve found this more useful than the children property itself.

  • About the author

    Daniel Irvine is a software craftsman at 8th Light, based in London. These days he prefers to code in Clojure and Ruby, despite having been a C++ and C# developer for the majority of his career.

    For a longer bio please see danielirvine.com. To contact Daniel, send a tweet to @d_ir or use the comments section below.

    Twitter GitHub Facebook Instagram dirv.me