spec/wortsammler_spec.rb in wortsammler-1.0.3 vs spec/wortsammler_spec.rb in wortsammler-2.0.0.dev1

- old
+ new

@@ -1,14 +1,15 @@ require 'rake' require 'tmpdir' require 'pry' +require 'wortsammler.rb' wortsammlerbin = "'#{File.expand_path("bin")}'" -wortsammler = "'#{File.expand_path(File.join("bin", "wortsammler"))}'" +wortsammler = "'#{File.expand_path(File.join("bin", "wortsammler"))}'" testprojectdir = "testproject/30_Sources" -specdir = File.dirname(__FILE__) -testoutput = "#{specdir}/../testoutput" +specdir = File.dirname(__FILE__) +testoutput = "#{specdir}/../testoutput" describe "Wortsammler generic issues" do it "provides a help", :exp => false do @@ -66,11 +67,11 @@ describe "Wortsammler beautifier features" do it "beautifies all markdown files in a folder" do tempdir=Dir.mktmpdir - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" cycles=10 cycles.times { |i| File.open("#{tempdir}/#{i}.md", "w") { |f| f.puts mdtext } } @@ -83,14 +84,14 @@ beautified_result.should include("# this is headline") } end - it "beautifies a single file" do + it "beautifies a single file", exp: false do tempdir=Dir.mktmpdir - mdfile="#{tempdir}/single.md" - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdfile ="#{tempdir}/single.md" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" File.open(mdfile, "w") { |f| f.puts mdtext } system "#{wortsammler} -bi #{mdfile}" $?.success?.should==true @@ -99,20 +100,20 @@ end it "recognizes if the specified manifest file is a directory", exp: false do FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") { |d| manifest="../ZSUPP_Manifests" - cmd= "#{wortsammler} -bm #{manifest} 2>&1" - r=`#{cmd}` + cmd = "#{wortsammler} -bm #{manifest} 2>&1" + r =`#{cmd}` r.include?("directory").should==true } $?.success?.should==false end it "beautifies input files in a manifest" do FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") { |d| manifest = "../ZSUPP_Manifests/sample_the-sample-document.yaml" - cmd = "#{wortsammler} -bm #{manifest}" + cmd = "#{wortsammler} -bm #{manifest}" system cmd } $?.success?.should==true end @@ -126,32 +127,32 @@ system "#{wortsammler} -bi this-path-does-not-exist" $?.success?.should == false end it "creates a semantically unchanged markdown file", exp: false do - testname = 'test_beautify' - inputfile = %Q{#{specdir}/#{testname}.md} - outputfile = %Q{#{testoutput}/#{testname}.md} + testname = 'test_beautify' + inputfile = %Q{#{specdir}/#{testname}.md} + outputfile = %Q{#{testoutput}/#{testname}.md} referencefile = %Q{#{specdir}/#{testname}_reference.md} FileUtils.cp(inputfile, outputfile) cmd = "#{wortsammler} -bi '#{outputfile}'" system cmd reference = File.open(referencefile).read - result = File.open(outputfile).read + result = File.open(outputfile).read result.should == reference end end describe "Wortsammler conversion" do it "converts a single file to output format" do tempdir=Dir.mktmpdir - mdfile="#{tempdir}/single.md" - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdfile ="#{tempdir}/single.md" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" File.open(mdfile, "w") { |f| f.puts mdtext } system "#{wortsammler} -pi #{mdfile} -o #{tempdir} -f latex:pdf:html:docx" $?.success?.should==true @@ -164,12 +165,12 @@ ] end it "converts a single file to default output format" do tempdir=Dir.mktmpdir - mdfile="#{tempdir}/single.md" - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdfile ="#{tempdir}/single.md" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" File.open(mdfile, "w") { |f| f.puts mdtext } system "#{wortsammler} -pi #{mdfile} -o #{tempdir}" $?.success?.should==true @@ -180,12 +181,12 @@ end it "handles chapters up to 6 levels", exp: false do tempdir="#{specdir}/../testoutput" - mdfile="#{tempdir}/chapternesting.md" - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdfile ="#{tempdir}/chapternesting.md" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" def lorem(j) (1.upto 100).map { |i| "text_#{j} lorem ipsum #{i} dolor " }.join(" ") end @@ -214,12 +215,12 @@ ].sort end it "handles lists up to 9 levels", exp: false do tempdir="#{specdir}/../testoutput" - mdfile="#{tempdir}/listnesting.md" - mdtext="#this is headline\n\n lorem ipsum\n\nbla fasel" + mdfile ="#{tempdir}/listnesting.md" + mdtext ="#this is headline\n\n lorem ipsum\n\nbla fasel" def lorem(j) (1.upto 100).map { |i| "text_#{j} lorem ipsum #{i} dolor " }.join(" ") end @@ -250,14 +251,14 @@ "listnesting.md.bak" ].sort end it "converts all files within a folder to output format" do - tempdir=Dir.mktmpdir - mdtext="# Header\n\n lorem ipsum\n" + tempdir =Dir.mktmpdir + mdtext ="# Header\n\n lorem ipsum\n" basefiles = ["f1", "f2", "f3"] - outfiles = basefiles.map { |f| ["#{f}.md", "#{f}.latex"] }.flatten.sort + outfiles = basefiles.map { |f| ["#{f}.md", "#{f}.latex"] }.flatten.sort basefiles.each { |f| File.open("#{tempdir}/#{f}.md", "w") { |fo| fo.puts mdtext } } system "#{wortsammler} -pi #{tempdir} -o #{tempdir} -f latex" @@ -268,11 +269,11 @@ end it "processes a manifest" do FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") { |d| manifest="../ZSUPP_Manifests/sample_the-sample-document.yaml" - cmd= "#{wortsammler} -pm #{manifest}" + cmd = "#{wortsammler} -pm #{manifest}" system cmd } $?.success?.should==true end @@ -319,39 +320,64 @@ it "handles undefined snippets" do pending "Test not yet implemented" end - it "runs the rake file in the sample document" do + it "runs the rake file in the sample document", exp: false do FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") { |d| - path=ENV['PATH'] - ENV['PATH']="#{wortsammlerbin}:#{path}" + path = ENV['PATH'] + ENV['PATH'] = "#{wortsammlerbin}:#{path}" puts ENV['PATH'] #system 'wortsammler -h' - cmd= "rake sample" + cmd = "rake sample" system cmd } + Dir["testproject/30_Sources/ZGEN_Documents/*.*"].count.should==15 $?.success?.should==true end - it "compiles all documents" do + it "compiles all documents", exp: false do FileUtils.cd("testproject/30_Sources/ZSUPP_Tools") { |d| - path=ENV['PATH'] + path =ENV['PATH'] ENV['PATH']="#{wortsammlerbin}:#{path}" puts ENV['PATH'] #system 'wortsammler -h' cmd= "rake all" #system cmd } end end +describe "Wortsammler output formats" do + + it "generates dzslides", exp: false do + mdfile = %Q{'#{specdir}/test_slides.md'} + FileUtils.cd("spec") do + system %Q{#{wortsammler} -pi #{mdfile} -o '#{testoutput}' -f slidy} + end + end + + + it "generates beamer files", exp: false do + mdfile = %Q{'#{specdir}/test_slides.md'} + FileUtils.cd("spec") do + system %Q{#{wortsammler} -pi #{mdfile} -o '#{testoutput}' -f beamer} + end + end + + + it "generates markdown", exp: true do + + end +end + + describe "Wortsammler syntax extensions", :exp => false do it "[RS_Comp_012] supports embedded images" do - tempdir ="#{specdir}/../testoutput" + tempdir ="#{specdir}/../testoutput" imagefile ="floating-image.pdf" FileUtils.cd(tempdir) { |c| FileUtils.cp("#{specdir}/#{imagefile}", ".") @@ -380,35 +406,35 @@ $?.success?.should==true end it "TC_EXP_001 expands expected results from testcases", exp: false do - proc=ReferenceTweaker.new("pdf") - outfile="#{specdir}/../testoutput/TC_EXP_001.output.md" + proc = ReferenceTweaker.new("pdf") + outfile = "#{specdir}/../testoutput/TC_EXP_001.output.md" File.unlink(outfile) if File.exists?(outfile) proc.prepareFile("#{specdir}/TC_EXP_001.md", outfile) a=File.open(outfile, "r").readlines.join a.should include("TC-DES-003-01") end it "TC_EXP_002 removes plantuml sources", exp: false do - proc=ReferenceTweaker.new("pdf") - outfile="#{specdir}/../testoutput/TC_EXP_002.output.md" + proc = ReferenceTweaker.new("pdf") + outfile = "#{specdir}/../testoutput/TC_EXP_002.output.md" File.unlink(outfile) if File.exists?(outfile) proc.prepareFile("#{specdir}/TC_EXP_002.md", outfile) - a=File.open(outfile, "r").readlines.join + a = File.open(outfile, "r").readlines.join a.include?(".plantuml").should==false end - it "TC_EXP_003 handles Markdown inlays", exp: false do - tempdir ="#{specdir}/../testoutput" - mdinlayfile ="TC_EXP_003_1.md" + it "TC_EXP_003 handles Markdown inlays", exp: true do + tempdir ="#{specdir}/../testoutput" + mdinlayfile ="TC_EXP_003_1.md" mdinlayfile_1 ="TC_EXP_003_2.md" - mdfile="tc_exp_003" + mdfile ="tc_exp_003" FileUtils.cd(tempdir) { |c| FileUtils.cp("#{specdir}/#{mdinlayfile}", ".") FileUtils.cp("#{specdir}/#{mdinlayfile_1}", ".") @@ -432,26 +458,30 @@ system "#{wortsammler} -pi '#{mdfile}.md' -o '.' -f txt" FileUtils.rm mdinlayfile FileUtils.rm mdinlayfile_1 } - ref = File.open("#{specdir}/tc_exp_003_reference.txt").read + ref = File.open("#{specdir}/tc_exp_003_reference.txt").read result = File.open("#{tempdir}/#{mdfile}.txt").read - ref.should==result + + expect(result).to eq ref end it "generates an index", exp: false do system "wortsammler -pi \"#{specdir}/test_mkindex.md\" -f pdf:latex -o \"#{testoutput}\"" system "pdftotext \"#{testoutput}/test_mkindex.pdf\"" - ref = File.open("#{specdir}/test_mkindex_reference.txt").read - result = File.open("#{testoutput}/test_mkindex.txt").read - ref.should==result + the_time = Time.now.strftime("%B %-d, %Y") + ref = File.open("#{specdir}/test_mkindex_reference.txt", encoding: "ISO-8859-1").read + result = File.open("#{testoutput}/test_mkindex.txt", encoding: "ISO-8859-1").read + result = result.gsub(the_time, "January 5, 2019") # adapt this if you update the reference + expect(result).to eq ref end it "reports TeX messages", exp: false do - system "wortsammler -pi \"#{specdir}/test_mkindex.md\" -f pdf:latex >> \"#{specdir}/test_mkindex.lst\"" - system "pdftotext \"#{specdir}/test_mkindex.pdf\"" - result = File.open("#{specdir}/test_mkindex.lst").read + system %Q{wortsammler -pi '#{specdir}/test_mkindex.md' -f pdf:latex -o '#{testoutput}' >> '#{testoutput}/test_mkindex.lst'} + system "pdftotext \"#{testoutput}/test_mkindex.pdf\"" + result = File.open("#{testoutput }/test_mkindex.lst").read result.include?("[WARN]").should==true end + end \ No newline at end of file