Report abuse

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
29
30
31
32
33
34
35
36
#!/usr/bin/env ruby
#
# Yaml to Rspec
# Created by Gregg Pollack (RailsEnvy.com)
#
# Installation notes
# -----------------
# 1. From textmate select bundles -> bundle commands -> edit commands
# 2. Select Rails 
# 3. Click the ++ button at the bottom and add a new command.
# 4. Name the command "Yaml to Rspec"
# 5. Paste in this snippet to the big field
# 6. Give the command the following properties
# 
# Save: Nothing
# Input: Entire Document
# Output: Replace Document
# 
# Key Equivalent: ctrl + opt + command + y
#  (that's what I use anyways)
#
# 7. Close the bundle editor, and try it out on a yaml file (but make sure Rails is selected at the bottom of your page)

require "yaml"

contexts = YAML::load(STDIN.read)
puts "require File.dirname(__FILE__) + '/../spec_helper'"
contexts.each do |context,specifications|
  puts '', "describe \"#{context.gsub('\"', '\\\"')}\" do", ''
  specifications.each do |specification|
    puts "  it \"#{specification.gsub('\"', '\\\"').chomp}\" do"
    puts "    pending \"Not done yet\""
    puts "  end", ''
  end
  puts "end"
end