public
Rubygem
Description: Makes tests easy on the fingers and the eyes
Homepage: http://www.thoughtbot.com/projects/shoulda
Clone URL: git://github.com/thoughtbot/shoulda.git
tsaleh (author)
Thu Nov 08 13:45:27 -0800 2007
commit  4b39f0076ab920d7657452737a2759d4782645e4
tree    866f02368eb45331269647587dbfaf296d8cf2fe
parent  2aba771ceed5d054d1fd15a8b4dba6194ea9018e
shoulda / tasks / yaml_to_shoulda.rake
100644 28 lines (25 sloc) 0.93 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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