Posted By

Catfish on 06/30/06


Tagged

textmate rails rspec


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

daniel
alvaroisorna
jonbaer
jpb
vali29
tkmr
sergeizen
webstic


Running RSpec for Rails from TextMate


 / Published in: Ruby
 

  1. #######
  2. #Command :
  3.  
  4. RUBYLIB="$TM_BUNDLE_SUPPORT/lib:$RUBYLIB" 
  5. "${TM_RUBY:=ruby}" -- "${TM_BUNDLE_SUPPORT}/bin/spec_helper.rb"
  6.  
  7.  
  8. #######
  9. #Your.bundle/Support/bin/spec_helper.rb :   require 'cgi'
  10.  
  11. #try and remove unnecessary '..'s from paths.
  12. #Eg collapse 'config/../app/controllers/../../public' to 'public'.  Hopefully.
  13. def rationalize_path(path)        
  14.   components = path.split("/")
  15.   real_components = []
  16.   components.each do |c|
  17.     if (c == "..") && (real_components.size > 0) && (real_components.last != "..")
  18.       real_components.pop
  19.     else
  20.       real_components.push c
  21.     end
  22.   end
  23.   
  24.   File.join(real_components)
  25. end
  26.   
  27.  
  28.  
  29. Dir.chdir(ENV['TM_PROJECT_DIRECTORY'])
  30.  
  31. output = `rake spec 2>&1`
  32. output = CGI.escapeHTML(output)
  33.  
  34. #rationalize paths (strip out unnecessary '..'s etc)
  35. output.gsub! /(\.\/|\/)[^:\n&]+\.[^:\n]+/ do |m|
  36.  rationalize_path(m)
  37. end
  38.  
  39. #Find local file names and make them into proper links
  40. #It ignores any paths that don't start with './'.
  41. # (This is a feature, IMO - too many links otherwise)
  42. output.gsub! /\.(\/[^:&]+):([\d]+)/ do |m|
  43.   path = Dir.pwd + $1
  44.   "<a href=\"txmt://open?url=file://#{path}&line=#{$2}\">#{m}</a>"
  45. end
  46.  
  47.  
  48. #Remove unnecessary repitition of the project path.
  49. #Need to keep it in if it's preceeded by '/' - this would indicate it's part of a link url.
  50. output.gsub! /([^\/])#{Dir.pwd}\// do |m|
  51.   $1+'./'
  52. end
  53.  
  54.  
  55. #Find the result lines (x specification(s), y failure(s)) and color them
  56. output.gsub! /^[\d]+ specifications?, [\d]+ failures?/ do |m|
  57.   "<span class='result'>#{m}</span>"
  58. end
  59.  
  60.  
  61.  
  62. output.gsub!("\n", "<br/>")
  63.  
  64. puts <<END
  65. <html>
  66. <head>
  67.   <title>rspec results</title>
  68.   <style type='text/css'>
  69. body {font-size:0.8em}
  70. .result {font-weight:bold;}
  71.   </style>
  72. </head>
  73. <body>
  74. <h1>rspec</h1>
  75. #{output}
  76. </body>
  77. </html>
  78. END

Report this snippet  

You need to login to post a comment.