【发布时间】:2012-02-21 15:36:47
【问题描述】:
我是新来的。我正在做一个带有一些测试的项目。我在为课程编写规范时遇到了一些问题。我完成了一些简单的规格,但我不知道如何为这个写。任何帮助将不胜感激。
我的班级
Class Writer
def initialize(filepath)
@filepath = RAILS_ROOT + filepath
@xml_document = Nokogiri::XML::Document.new
end
def open
File.open(@filepath,"w") do |f|
@gz = Zlib::GzipWriter.new(f)
@gz.write(%[<?xml version="1.0" encoding="UTF-8"?>\n])
@gz.write(%[<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n])
yield self
@gz.write(%[</urlset>])
@gz.close
end
end
def write_entry_to_xml(entry)
node = Nokogiri::XML::Node.new( "url" , @xml_document )
node["loc"] = entry.loc
node["changefreq"] = entry.changfreq
node["priority"] = entry.priority
node["lastmod"] = entry.lastmod
@gz.write(node.to_xml)
end
end
目前我写的如下
describe "writer" do
before :each do
@time = Time.now
@filepath = RAILS_ROOT + "/public/sitemap/test/sitemap_test.xml.gz"
File.open(@filepath,"w") do |f|
@gz = Zlib::GzipWriter.new(f)
end
@xml_document = Nokogiri::XML::Document.new
@entry = Sitemap::Entry.new("location", "monthly", "0.8", @time)
end
describe "open" do
it "should create a file and write xml entries to it" do
end
end
describe "write_entry_to_xml" do
it "should format and entry to xml node and write it" do
node = Nokogiri::XML::Node.new( "url" , @xml_document )
node["loc"].should == @entry.loc
node["changefreq"].should == @entry.changfreq
node["priority"].should == @entry.priority
node["lastmod"].shoul == @entry.lastmod
end
结束
谁能帮我写出这门课的完整规范。 提前致谢
【问题讨论】:
-
您没有复制/粘贴代码吗?
Class,shoul? -
复制/粘贴代码是什么意思?你的意思是class code和spec code是一样的吗?
-
测试意味着测试你的实际代码,而不是你真实代码内容的副本。您应该了解测试替身以了解如何测试真实代码的特定语句
-
你能指导我这个具体的课程吗
-
@farnoy 你能帮我解决这个问题吗?
标签: ruby-on-rails ruby rspec rspec2