0

私はコンバーターを開発しており、rspec を使用して、変換された値が正しいことを確認しています。値を確認するには、変換されたファイル (JSON で記述) をロードする必要があります。そこで、変換したファイルを に読み込む方法を用意しましたspec_helper.rb:beforeフックを使用して各スペック ファイルでこのメソッドを呼び出します(ただし、この質問の本質ではありません)。

次に、複数の変換結果に対して同じ rspec テストを実行したいと考えています。これはただのイメージです。

file_names = [ 'file1', 'file2', 'file3' ] # OR use Dir.glob to get some file paths
file_names.each do |file|
  all_rspec_tests( file )
end

いくつかのファイル名を反復するベスト プラクティスを教えてください。いくつかのパターンを試しました。

1) Rakefile では、RakeTask で変数を渡すことができません。次に、次のように ENV (環境変数) を使用しました:コマンドライン パラメーターを Rspec スクリプトに渡すには? 期待どおりに機能しませんでした。特に、RakeTast はシーケンシャルに実行されない (別のスレッドで実行されているように見える) ため、各テストは正しく実行されませんでした。

2) モジュールを作成し、次のように RSpec を拡張します: Run the same spec multiple times with different filters . しかし、これは JavaScript を使用するためのパターンです。そして、この方法が成功するかどうかはわかりません。

4

1 に答える 1

0

私は通常使用します:

system "rspec \"%s\" --format CustomFormatter --require environment" % file

ただし、custom_formatter.rb と environment.rb の 2 つのファイルを含む「spec」フォルダーが必要です。

custom_formatter.rb:

require "rspec/core/formatters/base_text_formatter"
require 'yaml'
class CustomFormatter < RSpec::Core::Formatters::BaseTextFormatter
  def initialize(output)
    super(output)
  end
  def example_started proxy
  end
  def example_passed proxy
    p "\tPassed: " + proxy.description
  end
  def example_failed proxy
  end
  def example_group_started group
  end
  def example_group_finished group
  end
end

環境.rb:

require "rubygems"
require "watir-webdriver"
require "watir-webdriver/wait"
require "test/unit"
require 'system/report_html_template'
require "system/logger"
require "system/report"
require "rspec"

include Selenium
include Watir

RSpec.configure do |config|
    config.fail_fast = true
    config.before(:all) do
    end
    config.after(:all) do
    end
end
于 2013-01-25T20:21:08.160 に答える