2011-05-27 136 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