Reputation: 6542
Can any one suggest, How to write test case for XML value.. when it is parsed in Rake Task ?
Here, In my project I took XML file from third party and parse that XML in my rake task and that rake task store that value in defined database and table. So now I wanna write few test case for this task.
Please suggest some thing??
For Rails 3.0.4, RSpec as Testing Framework
Upvotes: 0
Views: 674
Reputation: 25757
Let's suppose you have the parser within some kind of class, let's say:
class MyApp::XmlImporter
def initialize(file)
@file = file
end
def parse
...
end
end
Then add a file to your spec folder 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
Upvotes: 1