• Login
sketchucation logo sketchucation
  • Login
ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

Use Ruby's Unit-testing functionality in Sketchup

Scheduled Pinned Locked Moved Developers' Forum
15 Posts 5 Posters 2.0k Views 5 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    lbaeyens
    last edited by 6 Jun 2010, 10:29

    I've been playing around with ruby scripts in Sketchup for some time now but want to start test harness my code. Ruby has the build in unit testing framework, so I was wondering whether anyone has hands on experience with applying this within the boundaries of Sketchup. the presentation http://www.playuptools.com/csroby/media/GDC_Sketchup_09.pdf mentions it should work (slide 31 & 32), but so far, I've been unsuccessful to get it up and running.

    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 6 Jun 2010, 12:14

      I've not used TestUnits with SU Ruby. But that's a nice presentation you linked to.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by 6 Jun 2010, 13:18

        Does the framework rely on compiled libraries? If so, you may end up having to compile it just for use in SketchUp since SU is still using version 1.8.0. Still, several plug-ins are using the Ruby win32API.so and win32ole.so libraries copied from the Ruby 1.8.6 distribution, but other libraries don't play as nicely for whatever reason.

        If the framework is pure Ruby, you should be able to use it as-is. What do you mean by unsuccessful? What have you done so far?

        Hi

        1 Reply Last reply Reply Quote 0
        • D Offline
          Dan Rathbun
          last edited by 6 Jun 2010, 14:48

          Another thought....

          Ruby ver 1.9.1 comes with a MiniTest library. Maybe it may work better than the fullblown edition.

          I don't see it with ver 1.8.6, don't knowif it's in 1.8.7 __ anyone?
          EDIT: (Just unzipped v1.8.7-p72, and it's not there. Looks like it's a v1.9.x addition. So the question is will it work in the v1.8.x branch?)

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • L Offline
            lbaeyens
            last edited by 9 Jun 2010, 09:32

            Guys,

            I got in contact with the author of the slide deck I mentioned. He told me that the unit testing functionality of Ruby is not part of the SketchUp installation (on PC, it is on Mac), so that I need to copy the unit testing folders from ruby into the plugin folder of sketchup.

            this is also mentioned on the FAQ pages of SketchUp (http://code.google.com/apis/sketchup/docs/faq.html )

            What parts of Ruby comes with SketchUp?
            Only the minimal "core" Ruby modules come with SketchUp on the PC. On the Mac, the full standard Ruby install is included with the OS.

            I need a Ruby module (such as CGI) that doesn't come with SketchUp. What do I do?
            You could either require that your plugin users install the latest version of Ruby on their computer (it comes standard on the Mac, by the way) or you could distribute the needed .rb files in a subdirectory that you add to the /Plugins directory when they install your script.

            I will try this out later on today and keep you tuned on how it went.

            Lieven

            1 Reply Last reply Reply Quote 0
            • L Offline
              lbaeyens
              last edited by 9 Jun 2010, 13:01

              So I copied the test and underlying folders from my Ruby 1.8 installation to the Plugins folder of Sketchup.
              I bumped into another load error, so I also copied the optparse.rb file to the Plugins folder. Now my code snippet is loading fine. I'll come back with more news, once I've done some real testing.

              L.

              1 Reply Last reply Reply Quote 0
              • T Offline
                thomthom
                last edited by 9 Jun 2010, 13:05

                @lbaeyens said:

                You could either require that your plugin users install the latest version of Ruby on their computer

                hmm.. I don't think that sounds like a good solution. As a user I'd rather not have to install a full separate Ruby installation.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • L Offline
                  lbaeyens
                  last edited by 9 Jun 2010, 18:55

                  I don't know why on Mac SU comes with the full Ruby set while on PC only the "core" Ruby components are deployed.

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    thomthom
                    last edited by 9 Jun 2010, 18:56

                    Yea, there are many questionmarks regarding the SU Ruby implementation...

                    Thomas Thomassen — SketchUp Monkey & Coding addict
                    List of my plugins and link to the CookieWare fund

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tbd
                      last edited by 9 Jun 2010, 19:42

                      @lbaeyens said:

                      I don't know why on Mac SU comes with the full Ruby set while on PC only the "core" Ruby components are deployed.

                      because OSX, not SU, has Ruby preinstalled by default (among other nice things).

                      SketchUp Ruby Consultant | Podium 1.x developer
                      http://plugins.ro

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by 11 Jun 2010, 16:35

                        I'm interested in learning how unit testing can improve the development process for plugins. I've never felt I needed it, but I can't really justify that feeling because I really don't know what unit testing is all about.

                        My plugins are simple and straight-forward. I am making an assumption that testing is designed more for software that is too large to understand as a whole, and so it is divided into smaller pieces (units.) Then the tests make sure you're smaller units don't break as you work on the other parts.

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • L Offline
                          lbaeyens
                          last edited by 16 Jun 2010, 19:00

                          I got it working! thanks to Scott (the author of the slide deck remember)
                          the issue was that the stdout which is the standard output stream used by the TestRunner is not supported in SU, so you need to implement a SU specific output stream SketchupConsoleOutput in this case
                          a second issue that had to be resolved was the reference to Test::Unit::UI::NORMAL.
                          but now it's up and running. copy the code into a .rb file and give it a try.

                          Test driven SU, here we come!

                          require 'test/unit/ui/console/testrunner'
                          require 'test/unit'
                          require 'sketchup'
                          Sketchup.send_action "showRubyPanel:"

                          module Sketchup
                          class Model
                          def dumpr
                          return true
                          end
                          end
                          end

                          class SketchupConsoleOutput
                          def puts s
                          print s.to_s + "\n"
                          end
                          def write s
                          print s
                          end
                          def flush
                          #nop
                          # The testrunner expects to be able to call this method on the supplied io object.
                          end
                          end

                          class ModelDumpTest < Test::Unit::TestCase
                          def test_dumpexistingmodel
                          assert_equal true, Sketchup.active_model.dumpr
                          end
                          end

                          def runTests
                          runner = Test::Unit::UI::Console::TestRunner.new(ModelDumpTest, Test::Unit::UI::NORMAL, SketchupConsoleOutput.new)
                          runner.start
                          end

                          UI.menu("PlugIns").add_item("TestRunner") { runTests }

                          1 Reply Last reply Reply Quote 0
                          • L Offline
                            lbaeyens
                            last edited by 16 Jun 2010, 19:35

                            test driven development for sketchup plugins
                            well, I come out of the classic software development space and apply TDD for the last 10 years. when I started experimenting with SU plugin development, I started without TDD, but after a while I felt like developing "naked". once you're used to the TDD way, you won't go back to the non TDD way. and Ruby has embedded TDD capability, so no excuse!
                            I'm glad I got it up and running, I'll keep you tuned on my TDD adventures in SU Ruby

                            1 Reply Last reply Reply Quote 0
                            • J Offline
                              Jim
                              last edited by 17 Jun 2010, 02:42

                              You can also start sketchup from the command line as follows:

                              $ sketchup.exe > log.txt

                              And then output goes to the file as long as you do not open the Ruby Console. The Ruby Console slows SU down and is less convenient when there is a lot of output.

                              So is the example code you posted an actual test you would write, or is it for testing the setup?

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • L Offline
                                lbaeyens
                                last edited by 17 Jun 2010, 21:16

                                the code snippet is not an actual test, but just to prove it works. now the real work starts. thanks for the hint on directing the SU output.

                                1 Reply Last reply Reply Quote 0
                                • 1 / 1
                                1 / 1
                                • First post
                                  1/15
                                  Last post
                                Buy SketchPlus
                                Buy SUbD
                                Buy WrapR
                                Buy eBook
                                Buy Modelur
                                Buy Vertex Tools
                                Buy SketchCuisine
                                Buy FormFonts

                                Advertisement