Skip to content

Commit

Permalink
refactor spec
Browse files Browse the repository at this point in the history
Creating sample document files within file tasks in Rake, not in a shared
context. This is more efficient and match with philosophy of RSpec.
  • Loading branch information
wtsnjp committed Apr 6, 2019
1 parent 48bb7b1 commit bf343ed
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
17 changes: 16 additions & 1 deletion Rakefile
Expand Up @@ -58,11 +58,25 @@ file PS_TEXDOC_CNF_LINK => PS_TEXMF_TEXDOC_DIR do
ln_s TEXDOC_CNF, PS_TEXDOC_CNF_LINK
end

# link to texlive.tlpdb
PS_TEXLIVE_TLPDB = TMP_DIR + "texlive.tlpdb"
file PS_TEXLIVE_TLPDB do
ln_s TEXMFROOT + "tlpkg/texlive.tlpdb", PS_TEXLIVE_TLPDB
end

# sample files
SAMPLE_DOC_DIR = PS_TEXMF + "doc/sample"
directory SAMPLE_DOC_DIR

SAMPLE_FILES = []
["html", "htm", "dvi", "md", "txt", "pdf", "ps", "tex"].each do |ext|
sample_file = SAMPLE_DOC_DIR + "sample.#{ext}"
file sample_file => SAMPLE_DOC_DIR do
touch sample_file
end
SAMPLE_FILES << sample_file
end

# options for ronn
OPT_MAN = "--manual=\"Texdoc manual\""
OPT_ORG = "--organization=\"Texdoc #{TEXDOC_VERSION}\""
Expand Down Expand Up @@ -102,7 +116,8 @@ task :uninstall do
end

desc "Run tests [options available]"
task :test => [PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK, PS_TEXLIVE_TLPDB] do
task :test =>
[PS_TEXDOC_LINK, PS_TEXDOC_CNF_LINK, PS_TEXLIVE_TLPDB] + SAMPLE_FILES do
# parse options
options = {}
if ARGV.delete("--")
Expand Down
5 changes: 1 addition & 4 deletions spec/config/items_spec.rb
@@ -1,16 +1,13 @@
require 'os'
require 'spec_helper'
require 'pathname'
require 'fileutils'

RSpec.describe "Configuration item", :type => :aruba do
include_context "messages"
include_context "texmf"

context "texlive_tlpdb" do
context "to set custom path" do
let(:tlpdb) { Pathname.pwd + "tmp/texlive.tlpdb" }
let(:texmf_var) { Pathname.pwd + "tmp/texmf-var" }

before(:each) { set_environment_variable "TEXMFVAR", texmf_var.to_s }
before(:each) {
run_texdoc "-dtlpdb", "-c texlive_tlpdb=#{tlpdb.to_s}", "texlive-en"
Expand Down
13 changes: 0 additions & 13 deletions spec/support/shared_contexts/sample_files_context.rb

This file was deleted.

17 changes: 17 additions & 0 deletions spec/support/shared_contexts/texmf_context.rb
@@ -0,0 +1,17 @@
require 'pathname'

shared_context "texmf" do
# pseudo TEXMF trees
let(:texmf_home) { Pathname.pwd + "tmp/texmf" }
let(:texmf_var) { Pathname.pwd + "tmp/texmf-var" }

# link to texlive.tlpdb
let(:tlpdb) { Pathname.pwd + "tmp/texlive.tlpdb" }

# sample files
["html", "htm", "dvi", "md", "txt", "pdf", "ps", "tex"].each do |ext|
let("sample_#{ext}".to_sym) {
Pathname.pwd + "tmp/texmf/doc/sample/sample.#{ext}"
}
end
end
10 changes: 1 addition & 9 deletions spec/view/file_detection_spec.rb
Expand Up @@ -2,11 +2,10 @@

RSpec.describe "File detection for viewing", :type => :aruba do
include_context "messages"
include_context "sample_files"
include_context "texmf"

context "File *.html" do
before(:each) do
sample_html = cleate_sample_file "html"
run_texdoc "-dview --just-view", sample_html
end

Expand All @@ -19,7 +18,6 @@

context "File *.htm" do
before(:each) do
sample_htm = cleate_sample_file "htm"
run_texdoc "-dview --just-view", sample_htm
end

Expand All @@ -32,7 +30,6 @@

context "File *.dvi" do
before(:each) do
sample_dvi = cleate_sample_file "dvi"
run_texdoc "-dview --just-view", sample_dvi
end

Expand All @@ -45,7 +42,6 @@

context "File *.md" do
before(:each) do
sample_md = cleate_sample_file "md"
run_texdoc "-dview --just-view", sample_md
end

Expand All @@ -58,7 +54,6 @@

context "File *.txt" do
before(:each) do
sample_txt = cleate_sample_file "txt"
run_texdoc "-dview --just-view", sample_txt
end

Expand All @@ -71,7 +66,6 @@

context "File *.pdf" do
before(:each) do
sample_pdf = cleate_sample_file "pdf"
run_texdoc "-dview --just-view", sample_pdf
end

Expand All @@ -84,7 +78,6 @@

context "File *.ps" do
before(:each) do
sample_ps = cleate_sample_file "ps"
run_texdoc "-dview --just-view", sample_ps
end

Expand All @@ -97,7 +90,6 @@

context "File *.tex" do
before(:each) do
sample_tex = cleate_sample_file "tex"
run_texdoc "-dview --just-view", sample_tex
end

Expand Down

0 comments on commit bf343ed

Please sign in to comment.