Created
May 10, 2010 01:20
-
-
Save tomas-stefano/395559 to your computer and use it in GitHub Desktop.
Just a Example of Future Test::Unit DSL for Morpheus
This file contains 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
# 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