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

      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
      • thomthomT Offline
        thomthom
        last edited by

        @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

          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
          • thomthomT Offline
            thomthom
            last edited by

            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
            • tbdT Offline
              tbd
              last edited by

              @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

                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

                  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

                    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

                      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

                        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
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement