# encoding=utf-8
require 'spec_helper'
describe 'Polytexnic::Pipeline#to_html' do
subject(:processed_text) { Polytexnic::Pipeline.new(polytex).to_html }
describe "tabular environments" do
context "simple table with centered elements" do
let(:polytex) do <<-'EOS'
\begin{tabular}{cc}
\hline
HTTP request & URL \\
\hline
GET & /users \\
GET & /users/1
\end{tabular}
EOS
end
let(:output) do <<-'EOS'
HTTP request |
URL |
GET |
/users |
GET |
/users/1 |
EOS
end
it { should resemble output }
context "longtable" do
let(:polytex) do <<-'EOS'
\begin{longtable}{cc}
\hline
HTTP request & URL \\
\hline
GET & /users \\
GET & /users/1
\end{longtable}
EOS
end
it { should resemble output }
end
end
context "tabularx environments" do
let(:polytex) do <<-'EOS'
\begin{tabularx}{\textwidth}{ |l|l|l|l| }
\hline
label 1 & label 2 & label 3 & label 4 \\
\hline
item 1 & item 2 & item 3 & item 4 \\
\hline
\end{tabularx}
EOS
end
let(:output) do <<-'EOS'
label 1 |
label 2 |
label 3 |
label 4 |
item 1 |
item 2 |
item 3 |
item 4 |
EOS
end
it { should resemble output }
end
context "more complicated left-aligned cells with lines" do
let(:polytex) do <<-'EOS'
\begin{tabular}{|l|lll|}
\multicolumn{4}{|c|}{Cell spanning four columns} \\
HTTP request & URL & Action & Purpose \\ \hline
GET & /users & index & page to list all users \\
GET & /users/1 & show & page to show user with id 1\\
GET & /users/new & new & page to make a new user \\
POST & /users & create & create a new user \\
GET & /users/1/edit & edit & page to edit user with id 1 \\
PATCH & /users/1 & update & update user with id 1 \\
DELETE & /users/1 & destroy & delete user with id 1
\end{tabular}
EOS
end
it do
should resemble <<-'EOS'
Cell spanning four columns |
HTTP request |
URL |
Action |
Purpose |
GET |
/users |
index |
page to list all users |
GET |
/users/1 |
show |
page to show user with id 1 |
GET |
/users/new |
new |
page to make a new user |
POST |
/users |
create |
create a new user |
GET |
/users/1/edit |
edit |
page to edit user with id 1 |
PATCH |
/users/1 |
update |
update user with id 1 |
DELETE |
/users/1 |
destroy |
delete user with id 1 |
EOS
end
end
context "table whose border used to break for some reason" do
let(:polytex) do <<-'EOS'
\begin{tabular}{l|l|ll}
DELETE & /users/1 & destroy & delete user with id 1
\end{tabular}
\begin{tabular}{|r|l|ll|}
DELETE & /users/1 & destroy & delete user with id 1
\end{tabular}
EOS
end
it do
should resemble <<-'EOS'
DELETE |
/users/1 |
destroy |
delete user with id 1 |
DELETE |
/users/1 |
destroy |
delete user with id 1 |
EOS
end
end
end
describe "table environments" do
context "with a label and a cross-reference" do
let(:polytex) do <<-'EOS'
\begin{table}
\begin{tabular}{cc}
HTTP request & URL \\
GET & /users \\
GET & /users/1
\end{tabular}
\label{table:foo}
\end{table}
Table~\ref{table:foo}
EOS
end
it do
should resemble <<-'EOS'
HTTP request |
URL |
GET |
/users |
GET |
/users/1 |
TableĀ 1
EOS
end
end
context "with a caption" do
let(:polytex) do <<-'EOS'
\begin{table}
\begin{tabular}{cc}
HTTP request & URL \\
GET & /users \\
GET & /users/1
\end{tabular}
\caption{HTTP requests.}
\end{table}
EOS
end
it do
should resemble <<-'EOS'
HTTP request |
URL |
GET |
/users |
GET |
/users/1 |
HTTP requests.
EOS
end
context "with a caption and a label" do
let(:polytex) do <<-'EOS'
\begin{table}
\begin{tabular}{cc}
HTTP request & URL \\
GET & /users \\
GET & /users/1
\end{tabular}
\caption{HTTP requests.\label{table:foo}}
\end{table}
Table~\ref{table:foo}
EOS
end
it do
should resemble <<-'EOS'
HTTP request |
URL |
GET |
/users |
GET |
/users/1 |
HTTP requests.
TableĀ 1
EOS
end
end
context "with a table containing a centering environment" do
let(:polytex) do <<-'EOS'
\begin{table}
\footnotesize
\begin{center}
\begin{tabular}{lll}
\textbf{HTTP request} & \textbf{URL} & \textbf{Action} \\ \hline
\texttt{DELETE} & /users/1 & \kode{destroy}
\end{tabular}
\end{center}
\caption{RESTful routes provided by the Users resource.\label{table:RESTful_users}}
\end{table}
EOS
end
it { should resemble 'id="table-RESTful_users"' }
end
end
context "numbering with two chapters" do
let(:polytex) do <<-'EOS'
\chapter{A chapter}
lorem
\begin{table}
\begin{tabular}{cc}
HTTP request & URL \\
GET & /users \\
GET & /users/1
\end{tabular}
\label{table:foo}
\end{table}
\chapter{Another}
ipsum
Table~\ref{table:foo}
\begin{table}
\begin{tabular}{cc}
HTTP request & URL \\
GET & /users \\
GET & /users/1
\end{tabular}
\label{table:bar}
\end{table}
EOS
end
it { should include 'Table 1.1' }
it { should include 'Table 2.1' }
end
end
end