Skip to content

Instantly share code, notes, and snippets.

@jordandobson
Created April 15, 2010 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordandobson/367505 to your computer and use it in GitHub Desktop.
Save jordandobson/367505 to your computer and use it in GitHub Desktop.
Example of Setup for storing puts and clearing for testing
class TestTaskmaster < Test::Unit::TestCase
def setup
###
# Setup Class
@tm = Taskmaster
###
# Collect Output
def @tm.puts arg
@@output ||= []
@@output << arg if arg
end
###
# Setup Clearing Tasks & Output
@clear = Proc.new{
@tm::TASKS.clear
@@output = []
}
###
# Setup Recipe that clears Output to always make same call
@recipe = Proc.new{
@clear.call
@tm.cookbook do
recipe :sandwich, :meat, :bread do
puts "making a sammich!"
end
recipe :meat, :clean do
puts "preparing the meat"
end
recipe :bread, :clean do
puts "preparing the bread"
end
recipe :clean, :mop, :handwash do
puts "cleaning"
end
recipe :handwash do
puts "washing hands"
end
recipe :mop do
puts "mopping!"
end
end
}
end
# Tests Here...
# Used @recipie.call to load recipies
# Used @clear.call to clear for custom recipies
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment