# 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 "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
end
end
end