# encoding=utf-8
require 'spec_helper'
describe 'Polytexnic::Pipeline#to_html' do
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
describe "code listings" do
let(:polytex) do <<-'EOS'
\chapter{Foo bar}
\begin{codelisting}
\codecaption{Creating a \texttt{gem} configuration file. \\ \filepath{path/to/file}}
\label{code:create_gemrc}
%= lang:console
\begin{code}
$ subl .gemrc
\end{code}
\end{codelisting}
Listing~\ref{code:create_gemrc}
EOS
end
it do
should resemble <<-'EOS'
Listing 1.1:
Creating a gem configuration file.
path/to/file
ListingĀ 1.1
EOS
end
context "with an empty caption" do
let(:polytex) do <<-'EOS'
\chapter{Foo bar}
\begin{codelisting}
\codecaption{}
\label{code:create_gemrc}
%= lang:console
\begin{code}
$ subl .gemrc
\end{code}
\end{codelisting}
Listing~\ref{code:create_gemrc}
EOS
end
it { should include 'Listing 1.1' }
it { should_not include 'Listing 1.1:' }
end
end
describe "metacode listings" do
let(:polytex) do <<-'EOS'
\begin{codelisting}
\label{code:listing}
\codecaption{The heading.}
%= lang:latex
\begin{metacode}
%= lang:ruby
\begin{code}
def foo
"bar"
end
\end{code}
\end{metacode}
\end{codelisting}
EOS
end
it "should not raise an error" do
expect { processed_text }.not_to raise_error
end
end
describe "containing code inclusion with a hyphen" do
before do
File.write(File.join('spec', 'fixtures', 'name-with-hyphens.txt'), '')
end
after do
FileUtils.rm(File.join('spec', 'fixtures', 'name-with-hyphens.txt'))
end
let(:polytex) do <<-'EOS'
\begin{codelisting}
\codecaption{Foo}
\label{code:foo}
%= <<(spec/fixtures/name-with-hyphens.txt, lang: text)
\end{codelisting}
EOS
end
it "should not raise an error" do
expect { processed_text }.not_to raise_error
end
end
end