spec/writer/file_spec.rb in massive_sitemap-2.0.0.rc4 vs spec/writer/file_spec.rb in massive_sitemap-2.0.0.rc5

- old
+ new

@@ -10,15 +10,21 @@ after do FileUtils.rm(filename) rescue nil FileUtils.rm(filename2) rescue nil end + describe "set" do + it "updates filename" do + writer.set(:filename => "test").send(:filename).should == "./test" + end + end + describe "root" do let(:root) { "test/test2" } after do - FileUtils.rm_rf(root) rescue nil + FileUtils.rm_rf(File.dirname(root)) rescue nil end it 'mkdir_p folder' do expect do MassiveSitemap::Writer::File.new(:root => root).tap do |w| @@ -67,14 +73,15 @@ writer.print 'test' writer.close! `cat '#{filename}'`.should == "test" end - it 'inits new file closes current' do - writer.print 'test' - writer.init!(:filename => filename2) - `cat '#{filename}'`.should == "test" + it 'inits new file does not closes current' do + expect do + writer.print 'test' + writer.init!(:filename => filename2) + end.to_not change { File.exists?(filename) } end it 'writes into second file' do writer.print 'test' writer.init!(:filename => filename2) @@ -99,8 +106,66 @@ writer = MassiveSitemap::Writer::File.new(:force_overwrite => true) expect do writer.init! writer.close! end.to_not raise_error(MassiveSitemap::Writer::File::FileExistsException) + end + end + + describe "#with_rotation" do + let(:writer) { MassiveSitemap::Writer::File.new } + + context "keeps filename" do + it "rotation is zero" do + writer.send(:with_rotation, "sitemap.xml").should == "sitemap-1.xml" + end + + it "rotation is zero" do + writer.send(:with_rotation, "sitemap2.xml").should == "sitemap2-1.xml" + end + + it "rotation is zero" do + writer.send(:with_rotation, "sitemap-1.xml").should == "sitemap-2.xml" + end + + it "rotation is zero" do + writer.send(:with_rotation, "sitemap-1-1.xml").should == "sitemap-1-2.xml" + end + + it "rotation is nil" do + writer.send(:with_rotation, "sitemap-user.xml").should == "sitemap-user-1.xml" + end + end + end + + describe "#split_filename" do + let(:writer) { MassiveSitemap::Writer::File.new } + + FILENAMES = { + nil => ["", nil, nil], + ".xml" => ["", nil, ".xml"], + ".xml.gz" => ["", nil, ".xml.gz"], + "sitemap" => ["sitemap", nil, nil], + "sitemap.xml" => ["sitemap", nil, ".xml"], + "sitemap.xml.gz" => ["sitemap", nil, ".xml.gz"], + "-1.xml" => ["", "1", ".xml"], + "-1.xml.gz" => ["", "1", ".xml.gz"], + "sitemap-1" => ["sitemap", "1", nil], + "sitemap-1.xml" => ["sitemap", "1", ".xml"], + "sitemap-1.xml.gz" => ["sitemap", "1", ".xml.gz"], + "-user-1.xml" => ["-user", "1", ".xml"], + "-user-1.xml.gz" => ["-user", "1", ".xml.gz"], + "sitemap-user-1" => ["sitemap-user", "1", nil], + "sitemap-user-1.xml" => ["sitemap-user", "1", ".xml"], + "sitemap-user-1.xml.gz" => ["sitemap-user", "1", ".xml.gz"], + "sitemap1" => ["sitemap1", nil, nil], + "sitemap1.xml" => ["sitemap1", nil, ".xml"], + "sitemap1.xml.gz" => ["sitemap1", nil, ".xml.gz"], + } + + FILENAMES.each do |filename, expected| + it "splits filename #{filename} into #{expected.join(' ')}" do + writer.send(:split_filename, filename).should == expected + end end end end