Skip to content

Instantly share code, notes, and snippets.

@guiceolin
Created October 19, 2012 12:41
Show Gist options
  • Save guiceolin/3918053 to your computer and use it in GitHub Desktop.
Save guiceolin/3918053 to your computer and use it in GitHub Desktop.
class Case1 < TestCase
test id:1 do
description "bla"
end
end
class TestCase
class << self
@@depth = 0
@@out = ""
def test(*args, &block)
method_missing(:test, args, block)
end
def method_missing(sym, *args, &block)
@@depth += 1
@@out += "<#{sym}"
if args.size > 1
data = args[0]
options = args[1]
else
if args[0].is_a? Hash
options = args[0]
data = nil
else
data = args[0]
options = {}
end
end
options.each_pair do |key,value|
@@out += " #{key}=#{value}"
end
@@out += ">"
if data
@@out += data
elsif block_given?
yield(block)
end
@@out += "</#{sym}>"
@@depth -= 1
puts @@out if @@depth == 0
end
end
def old
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment