Created
September 3, 2008 20:42
-
-
Save xtoddx/8660 to your computer and use it in GitHub Desktop.
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
require 'yaml' | |
def spit_context context, level=0 | |
spaces = " " * level | |
puts "#{spaces}context '#{context[0]}' do" | |
puts "#{spaces} setup do\n#{spaces} end\n\n" | |
spit_specs(context[1], level) | |
puts "#{spaces}end\n\n" | |
end | |
def spit_specs speclist, level | |
spaces = " " * (level + 1) | |
while spec = speclist.shift | |
if spec.is_a?(Array) | |
spit_context(spec, level+1) | |
else | |
puts "#{spaces}it '#{spec}' do" | |
puts "#{spaces}end\n\n" | |
end | |
end | |
end | |
fname = ARGV[0] || 'spec.yml' | |
YAML.load(File.read(fname)).each do |context| | |
spit_context(context) | |
end | |
__END__ | |
An example file might look like | |
--- | |
- - My Controller | |
- - should perform some action | |
- should perform some other action | |
- - When used by an admin | |
- - should perform another action | |
- should perform yet another action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment