Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment