I'm a bit lost here as to why my rake
task will not create the desired XML file, however it works fine when I have the method build_xml
in an .rb
file.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
namespace :xml do
desc "xml build test"
task :xml_build => :environment do
build_xml
end
end
def build_xml
# bui开发者_如何学运维ld xml docoument
builder = Nokogiri::XML::Builder.new do |xml|
xml.root {
xml.location {
xml.value "test"
}
}
end
File.open("test.xml", 'w') {|f| f.write(builder.to_xml) }
end
When I execute your rakefile with rake xml:xml_build
, I get an error that the task environment
is not defined. If I remove environment
as a dependency of xml_build
and then run it again it works fine and creates the xml file.
So my guess is that your environment task causes an error and xml_build never runs (or the task doesn't exist in your real rakefile either, so just remove it as a dependency).
精彩评论