# encoding=utf-8 require 'spec_helper' describe Polytexnic::Pipeline do before(:all) do FileUtils.rm('.highlight_cache') if File.exist?('.highlight_cache') end subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html } describe "code blocks" do context "without syntax highlighting" do let(:polytex) do <<-'EOS' \begin{code} def foo "bar" end \end{code} EOS end it { should resemble 'def foo' } it { should resemble '
def foo
"bar"
end
' }
end
end
context "with a space after 'lang'" do
let(:polytex) do <<-'EOS'
%= lang: ruby
\begin{code}
def foo
"bar"
end
\end{code}
EOS
end
it do
should resemble <<-'EOS'
def foo
"bar"
end
EOS
end
end
context "with highlight and line numbering options" do
let(:polytex) do <<-'EOS'
%= lang:ruby, options: "hl_lines": [1, 2], "linenos": true
\begin{code}
def foo
"bar"
end
\end{code}
EOS
end
it do
should resemble <<-'EOS'
1
def foo
2
"bar"
3
end
EOS
end
end
describe "code inclusion" do
context "for an existing file" do
context "with no extension" do
let(:polytex) do <<-'EOS'
%= <<(Rakefile)
EOS
end
let(:output) do <<-'EOS'
require
EOS
end
it { should resemble output }
end
context "with an extension" do
let(:polytex) do <<-'EOS'
%= <<(spec/to_html/literal_environments/code_spec.rb)
EOS
end
let(:output) do <<-'EOS'
# encoding=utf-8
EOS
end
it { should resemble output }
it { should_not include '' }
end
context "with a custom language override" do
let(:polytex) do <<-'EOS'
%= <<(polytexnic_commands.sty, lang: tex)
EOS
end
let(:output) do <<-'EOS'
% Add some custom commands needed by PolyTeXnic.
EOS
end
it { should resemble output }
it { should_not include '' }
end
context "with custom options" do
let(:polytex) do <<-'EOS'
%= <<(polytexnic_commands.sty, lang: tex, options: "hl_lines": [5])
EOS
end
let(:output) do <<-'EOS'
EOS
end
it { should resemble output }
end
end
context "for a nonexistent file" do
let(:polytex) do <<-'EOS'
%= <<(foobar.rb)
EOS
end
it { should include "ERROR: File 'foobar.rb' does not exist" }
end
end
end