0

Rake Task で解析されるときに、XML値のテストケースを作成する方法を提案できますか?

ここで、私のプロジェクトでは、サードパーティから XML ファイルを取得し、rake タスクでその XML を解析し、rake タスクはその値を定義済みのデータベースとテーブルに格納します。ですから、このタスクのテスト ケースをいくつか書きたいと思います。

何か提案してください??

Rails 3.0.4 の場合、テスト フレームワークとしての RSpec

4

1 に答える 1

1

ある種のクラス内にパーサーがあるとしましょう。

class MyApp::XmlImporter
  def initialize(file)
    @file = file
  end

  def parse
    ...
  end
end

次に、spec フォルダー spec/lib/my_app/xml_importer_spec.rb にファイルを追加します。

require 'spec_helper' do

describe MyApp::XmlImporter do
  it "should import the test file" do
    described_class.new("#{Rails.root}/spec/fixtures/test_file.xml").parse

    # Now you check for the correct database state given your test_file.xml
  end
end
于 2011-05-28T12:25:01.250 に答える