Skip to content

Instantly share code, notes, and snippets.

@tomas-stefano
Created May 10, 2010 01:20
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 tomas-stefano/395559 to your computer and use it in GitHub Desktop.
Save tomas-stefano/395559 to your computer and use it in GitHub Desktop.
Just a Example of Future Test::Unit DSL for Morpheus
# encoding: utf-8
class TestUnit
attr_accessor :name
def initialize(name)
@name = name
@pattern = "test/*_test.rb"
@verbose = false
end
def pattern(name)
name = name || @pattern
puts name
end
def verbose(name)
name = name || @verbose
puts name
end
end
def test_unit(name=:test, &block)
test = TestUnit.new(name)
register_task(:name => test.name, :object => test, &block)
end
def method_not_exist_test_unit_class
puts 'Call Method not exist in TestUnit class'
end
def register_task(options={}, &block)
puts "Nome da tarefa é #{options[:name]}"
eval <<-METHOD
def #{options[:name]}
puts "#{options[:object]}"
"#{options[:object].instance_eval(&block)}"
end
METHOD
end
def call_task(options={})
send(options[:name])
end
# Domain Specific Language Example
#
test_unit do
pattern 'test/test*.rb'
verbose true
method_not_exist_test_unit_class
end
# Domain Specific Language Example with name of task
#
test_unit(:other_test_task) do
pattern '*_test.rb'
verbose true
end
call_task(:name => :test)
call_task(:name => :other_test_task)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment