From 4b39f0076ab920d7657452737a2759d4782645e4 Mon Sep 17 00:00:00 2001 From: tsaleh Date: Thu, 8 Nov 2007 21:45:27 +0000 Subject: [PATCH] - moved rake tasks to shoulda namespace - added shoulda:from_yaml task from David.Lowenfels@gmail.com git-svn-id: https://svn.thoughtbot.com/plugins/shoulda/trunk@237 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa --- Rakefile | 7 +++++-- tasks/list_tests.rake | 2 +- tasks/yaml_to_shoulda.rake | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tasks/yaml_to_shoulda.rake diff --git a/Rakefile b/Rakefile index e1bb2b1e..8c7cf29a 100644 --- a/Rakefile +++ b/Rakefile @@ -2,8 +2,6 @@ require 'rake' require 'rake/testtask' require 'rake/rdoctask' -#require 'tasks/list_tests.rake' - # Test::Unit::UI::VERBOSE Rake::TestTask.new do |t| @@ -27,3 +25,8 @@ end desc 'Default: run tests.' task :default => ['test'] + +Dir['tasks/*.rake'].each do |f| + load f +end + diff --git a/tasks/list_tests.rake b/tasks/list_tests.rake index 4b0443fa..cad270f4 100644 --- a/tasks/list_tests.rake +++ b/tasks/list_tests.rake @@ -1,4 +1,4 @@ -namespace :test do +namespace :shoulda do desc "List the names of the test methods in a specification like format" task :list do diff --git a/tasks/yaml_to_shoulda.rake b/tasks/yaml_to_shoulda.rake new file mode 100644 index 00000000..8303011b --- /dev/null +++ b/tasks/yaml_to_shoulda.rake @@ -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 \ No newline at end of file