2011-03-02 128 views
3

我在軌道上使用紅寶石自動測試。跑步時我已經通過了2次測試。 rspec spec/;然而,當我嘗試使用自動測試時,這是輸出:自定義紅寶石與rspec軌道

[email protected]:~/sample_app$ autotest 
loading autotest/rails_rspec2 
style: RailsRspec2 
[email protected]:~/sample_app$ 

我得不到關於測試結果的輸出。同樣的事情適用於bundle exec autotest。我看到一條帖子推薦autospec,但該命令已棄用rspec2。我的Gemfile是

source 'http://rubygems.org' 

gem 'rails', '3.0.5' 
gem 'sqlite3-ruby', '1.3.2', :require => 'sqlite3' 

group :development do 
    gem 'rspec-rails', '2.5.0' 
    gem 'autotest','4.4.4' 
end 

group :test do 
    gem 'rspec', '2.5.0' 
    gem 'webrat', '0.7.1' 
    gem 'autotest', '4.4.4' 
    gem 'redgreen', '1.2.2' 
end 

我試圖把.autotest配置文件在我的項目的根目錄,以及主目錄,並沒有使對輸出的差異。我的.autotest文件看起來像這樣

#!/bin/ruby 
require 'autotest/timestamp' 

module Autotest::GnomeNotify 
    def self.notify title, msg, img 
    system "notify-send '#{title}' '#{msg}' -i #{img} -t 3000" 
    end 

    Autotest.add_hook :ran_command do |at| 
    image_root = "~/.autotest_images" 
    results = [at.results].flatten.join("\n") 
    results.gsub!(/\\e\[\d+m/,'') 
    output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(,\s(\d+)\spending?|)/) 
    full_sentence, green, failures, garbage, pending = $~.to_a.map(&:to_i) 
    if output 
    if failures > 0 
     notify "FAIL", "#{output}", "#{image_root}/fail.png" 
    elsif pending > 0 
     notify "Pending", "#{output}", "#{image_root}/pending.png" 
    else 
     notify "Pass", "#{output}", "#{image_root}/pass.png" 
    end 
    end 
end 
end 

我也檢查過libnotify-bin已安裝並正在運行。

回答

1

從rspec的得到詳細的結果,在您的項目根文件夾中創建一個.rspec文件,並寫入:

--format documentation 

如果可以的話,請允許我建議watchr而不是自動測試(用叉勺以及)。非常容易設置和非常有效。

看看

http://www.rubyinside.com/how-to-rails-3-and-rspec-2-4336.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+RubyInside+%28Ruby+Inside%29

如果你喜歡。

+0

謝謝!看守寶石使它的工作就像那樣! – 2011-03-02 08:26:04

+0

不客氣,我很高興幫助你:) – Spyros 2011-03-02 08:27:56

0

我和Autotest有很多相同的問題。我不確定,但我相信它可能對依賴版本非常挑剔。我有點像Rails noob,但是因爲我最近分享了你的麻煩,讓我告訴你我做了什麼來解決這個問題:

我能夠通過擺脫所有代碼.autotest文件並將其替換爲:

require 'autotest/growl' 
require 'autotest/fsevent' 

要清楚的是,該第二行僅適用於使用OSX的情況。我認爲你可以安全地擺脫.autotest文件中的所有「代碼」,因爲它涉及到手動的「紅/綠」咆哮通知,一旦你安裝了「redgreen」gem,這將不再需要。總之,你最終會得到一兩行.autotest文件。

這裏是我通過gem安裝的一些文件(有些像rspec-expectations,應該自動安裝爲依賴項)。以下文件是我認爲應該與您的自動測試設置相關的文件,版本是撰寫此回覆之前10分鐘的最新版本。

  • 自動測試(4.4.6,4.3.2)
  • 自動測試-fsevent(0.2.5,0.2.2)
  • 自動測試-咆哮(0.2.9,0.2.4)
  • 自動測試-rails純(4.1.2,4.1.0)
  • redgreen(1.2.2)
  • rspec的核(2.5.1,2.0.0.beta.18)
  • rspec的-預期(2.5。 0,2.0.0.beta.18)
  • rspec-mocks (2.5.0,2.0.0β18)
  • rspec的護欄(2.5.0,2.0.0.beta.18)
  • 叉勺(0.8.4)
  • webrat(0.7.3)
  • ZenTest(4.5.0)

執行gem list命令查看您已安裝哪些。這可能是更新您的版本和簡化.autotest文件(如果您關心位置,我的主目錄中有我的),這是一個簡單的問題。另外,不要忘記autotest-fsevent文件只適用於OSX。

P.S.你可能仍結有不明原因的自動檢測錯誤,除非你把一些額外的代碼在你的投機/控制器/ spec_helper.rb文件的末尾:

# Webrat configuration 
Webrat.configure do |config| 
config.mode = :rails 
end