从TextMate运行Rails的RSpec

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从TextMate运行Rails的RSpec相关的知识,希望对你有一定的参考价值。

  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! /(./|/)[^: &]+.[^: ]+/ 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!(" ", "<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

以上是关于从TextMate运行Rails的RSpec的主要内容,如果未能解决你的问题,请参考以下文章

从e/TextMate发布到Twitter

Rails:重命名控制器和相应的模型

从GIT刷新并添加textmate包

TextMate命令-运行DocTest

从剪贴板生成新的textmate文档

打开Apachehttpd.conf文件使用TextMate从终端