2011-03-02 130 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