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.
Posts
-
RE: Use Ruby's Unit-testing functionality in Sketchup
-
RE: Use Ruby's Unit-testing functionality in Sketchup
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 -
RE: Use Ruby's Unit-testing functionality in Sketchup
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
endclass 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
endclass ModelDumpTest < Test::Unit::TestCase
def test_dumpexistingmodel
assert_equal true, Sketchup.active_model.dumpr
end
enddef runTests
runner = Test::Unit::UI::Console::TestRunner.new(ModelDumpTest, Test::Unit::UI::NORMAL, SketchupConsoleOutput.new)
runner.start
endUI.menu("PlugIns").add_item("TestRunner") { runTests }
-
RE: Use Ruby's Unit-testing functionality in Sketchup
I don't know why on Mac SU comes with the full Ruby set while on PC only the "core" Ruby components are deployed.
-
RE: Use Ruby's Unit-testing functionality in Sketchup
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.
-
RE: Use Ruby's Unit-testing functionality in Sketchup
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
-
Use Ruby's Unit-testing functionality in Sketchup
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.