3

Ruby on Railsで自動テストを使用しています。実行時に2つの合格テストに合格しています。rspec spec/; ただし、自動テストを使用しようとすると、次の出力が表示されます。

matt@matt-laptop:~/sample_app$ autotest
loading autotest/rails_rspec2
style: RailsRspec2
matt@matt-laptop:~/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 がインストールされ、機能していることも確認しました。

4

2 に答える 2

1

rspec から詳細な結果を取得するには、ルート プロジェクト フォルダーに .rspec ファイルを作成し、次のように記述します。

--format documentation

よろしければ、autotest の代わりに watchr を提案させてください (spork でも)。セットアップが非常に簡単で、非常に効果的です。

を見てみましょう

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

もし良かったら。

于 2011-03-02T07:56:12.797 に答える
0

私はオートテストで同じ問題を抱えていました。確かではありませんが、依存関係のバージョンについては非常に気難しいかもしれません。私は少し Rails 初心者ですが、最近あなたの問題を共有したので、問題を解決するために私が何をしたかをお見せしましょう。

.autotest ファイル内のすべてのコードを削除し、次のように置き換えることで、動作させることができました。

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

明確にするために、2 行目は OSX を使用している場合にのみ適用する必要があります。.autotest ファイル内のすべての「コード」を安全に削除できると思います。これは、「redgreen」gem をインストールすると不要になる、手動の「red/green」うなり通知に関連するためです。つまり、1 行または 2 行の .autotest ファイルになります。

ここに、gem を介してインストールしたファイルをいくつか示します (rspec-expectations のように、依存関係として自動的にインストールされるはずのファイルもあります)。次のファイルは、オートテストのセットアップに関連すると思われるファイルです。バージョンは、この応答を書く 10 分前の時点で最新のものです。

  • 自動テスト (4.4.6、4.3.2)
  • autotest-fsevent (0.2.5、0.2.2)
  • autotest-grow (0.2.9、0.2.4)
  • autotest-rails-pure (4.1.2、4.1.0)
  • 赤緑 (1.2.2)
  • rspec コア (2.5.1、2.0.0.beta.18)
  • rspec-expectations (2.5.0, 2.0.0.beta.18)
  • rspec モック (2.5.0、2.0.0.beta.18)
  • rspec レール (2.5.0、2.0.0.beta.18)
  • スポーク (0.8.4)
  • ウェブラット (0.7.3)
  • ゼンテスト (4.5.0)

gem listコマンドを実行して、インストールされているものを確認します。バージョンを更新して .autotest ファイルを簡素化するのは簡単なことかもしれません (場所が気になる場合は、ホーム ディレクトリに私のファイルがあります)。また、autotest-fsevent ファイルは OSX にのみ適用されることを忘れないでください。

PS spec/controllers/spec_helper.rb ファイルの最後に追加のコードを追加しない限り、説明のつかない自動テスト エラーが発生する可能性があります。

# Webrat configuration
Webrat.configure do |config|
config.mode = :rails
end
于 2011-04-06T05:05:39.120 に答える