2011-05-27 133 views
0

任何人可以建議,如何編寫測試用例的XML值..當它在Rake任務分析時?XML解析+任何方式來編寫TestCase的XML解析

在這裏,在我的項目中,我從第三方獲取XML文件,並在我的rake任務中解析該XML,並且rake任務將該值存儲在已定義的數據庫和表中。所以現在我想爲這個任務寫幾個測試用例。

請建議一些事情?

對於Rails的3.0.4,RSpec的作爲測試框架

回答

1

讓我們假設你有某種類的中解釋,讓我們說:

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

    def parse 
    ... 
    end 
end 

然後將文件添加到您的規範文件夾投機/ 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