Guest User

Untitled

a guest
Feb 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. require 'yaml'
  2.  
  3. def spit_context context, level=0
  4. spaces = " " * level
  5.  
  6. puts "#{spaces}context '#{context[0]}' do"
  7. puts "#{spaces} setup do\n#{spaces} end\n\n"
  8. spit_specs(context[1], level)
  9. puts "#{spaces}end\n\n"
  10. end
  11.  
  12. def spit_specs speclist, level
  13. spaces = " " * (level + 1)
  14. while spec = speclist.shift
  15. if spec.is_a?(Array)
  16. spit_context(spec, level+1)
  17. else
  18. puts "#{spaces}it '#{spec}' do"
  19. puts "#{spaces}end\n\n"
  20. end
  21. end
  22. end
  23.  
  24. fname = ARGV[0] || 'spec.yml'
  25. YAML.load(File.read(fname)).each do |context|
  26. spit_context(context)
  27. end
  28.  
  29. __END__
  30.  
  31. An example file might look like
  32.  
  33. ---
  34. - - My Controller
  35. - - should perform some action
  36. - should perform some other action
  37. - - When used by an admin
  38. - - should perform another action
  39. - should perform yet another action
Add Comment
Please, Sign In to add comment