任何人都可以建议,如何为 XML 值编写测试用例……当它在 Rake Task 中解析时?
在这里,在我的项目中,我从第三方获取 XML 文件并在我的 rake 任务中解析该 XML,并且该 rake 任务将该值存储在定义的数据库和表中。所以现在我想为这个任务写几个测试用例。
请建议一些东西?
对于 Rails 3.0.4,RSpec 作为测试框架
任何人都可以建议,如何为 XML 值编写测试用例……当它在 Rake Task 中解析时?
在这里,在我的项目中,我从第三方获取 XML 文件并在我的 rake 任务中解析该 XML,并且该 rake 任务将该值存储在定义的数据库和表中。所以现在我想为这个任务写几个测试用例。
请建议一些东西?
对于 Rails 3.0.4,RSpec 作为测试框架
假设您在某种类中有解析器,比方说:
class MyApp::XmlImporter
def initialize(file)
@file = file
end
def parse
...
end
end
然后将文件添加到您的规范文件夹 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