Last active
December 20, 2015 14:19
-
-
Save monkstone/6145906 to your computer and use it in GitHub Desktop.
Alternative test setup for ruby-processing uses capture_io from minitest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(300, 300) | |
frame_rate(10) | |
end | |
def draw | |
if frame_count == 3 | |
puts "ok" | |
exit | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(300, 300) | |
end | |
def draw | |
begin | |
unknown_method() | |
rescue NoMethodError => e | |
puts e | |
exit | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(100, 100, P3D) | |
puts Java::Processing::opengl::PGraphicsOpenGL.OPENGL_VERSION | |
exit | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(300, 300, P2D) | |
frame_rate(10) | |
end | |
def draw | |
if frame_count == 3 | |
puts "ok" | |
exit | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(300, 300, P3D) | |
frame_rate(10) | |
end | |
def draw | |
if frame_count == 3 | |
puts "ok" | |
exit | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "minitest" # don't use bundled minitest | |
require "minitest/autorun" | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
Dir.chdir(File.dirname(__FILE__)) | |
class Rp5Test < Minitest::Test | |
def test_normal | |
out, err = capture_io do | |
open("|../bin/rp5 run basic.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert_match %r%ok%, out, "Failed Basic Sketch" | |
end | |
def test_p2d | |
out, err = capture_io do | |
open("|../bin/rp5 run p2d.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert_match %r%ok%, out, "Failed P2D sketch" | |
end | |
def test_p3d | |
out, err = capture_io do | |
open("|../bin/rp5 run p3d.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert_match %r%ok%, out, "Failed P3D sketch" | |
end | |
def test_graphics | |
out, err = capture_io do | |
open("|../bin/rp5 run graphics.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert out[0].to_i >= 3, "Graphics capability #{out} may be sub-optimal" | |
end | |
def test_setup_exception | |
out, err = capture_io do | |
open("|../bin/rp5 run setup.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert out.index("undefined method `unknown_method'"), "Failed to raise exception?" | |
end | |
def test_draw_exception | |
out, err = capture_io do | |
open("|../bin/rp5 run draw.rb", "r") do |io| | |
while l = io.gets | |
puts(l.chop) | |
end | |
end | |
end | |
assert out.index("undefined method `unknown_method'"), "Failed to raise exception?" | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def setup | |
size(300, 300) | |
begin | |
unknown_method() | |
rescue NoMethodError => e | |
puts e | |
exit | |
end | |
end | |
def draw | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment