Initial import

This commit is contained in:
2008-03-02 16:04:34 -03:00
commit 5e4951fa47
798 changed files with 59730 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
namespace :shoulda do
desc "List the names of the test methods in a specification like format"
task :list do
require 'test/unit'
require 'rubygems'
require 'active_support'
# bug in test unit. Set to true to stop from running.
Test::Unit.run = true
test_files = Dir.glob(File.join('test', '**', '*_test.rb'))
test_files.each do |file|
load file
klass = File.basename(file, '.rb').classify.constantize
puts
puts "#{klass.name.gsub(/Test$/, '')}"
test_methods = klass.instance_methods.grep(/^test/).map {|s| s.gsub(/^test: /, '')}.sort
test_methods.each {|m| puts " - #{m}" }
# puts "#{klass.name.gsub(/Test$/, '')}"
# test_methods = klass.instance_methods.grep(/^test/).sort
#
# method_hash = test_methods.inject({}) do |h, name|
# header = name.gsub(/^test: (.*)should.*$/, '\1')
# test = name.gsub(/^test:.*should (.*)$/, '\1')
# h[header] ||= []
# h[header] << test
# h
# end
#
# method_hash.keys.sort.each do |header|
# puts " #{header.chomp} should"
# method_hash[header].each do |test|
# puts " - #{test}"
# end
# end
end
end
end

View File

@@ -0,0 +1,28 @@
namespace :shoulda do
# From http://blog.internautdesign.com/2007/11/2/a-yaml_to_shoulda-rake-task
# David.Lowenfels@gmail.com
desc "Converts a YAML file (FILE=./path/to/yaml) into a Shoulda skeleton"
task :from_yaml do
require 'yaml'
def yaml_to_context(hash, indent = 0)
indent1 = ' ' * indent
indent2 = ' ' * (indent + 1)
hash.each_pair do |context, shoulds|
puts indent1 + "context \"#{context}\" do"
puts
shoulds.each do |should|
yaml_to_context( should, indent + 1 ) and next if should.is_a?( Hash )
puts indent2 + "should_eventually \"" + should.gsub(/^should +/,'') + "\" do"
puts indent2 + "end"
puts
end
puts indent1 + "end"
end
end
puts("Please pass in a FILE argument.") and exit unless ENV['FILE']
yaml_to_context( YAML.load_file( ENV['FILE'] ) )
end
end