Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
refactor specs, add specs for pipe and toc
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Scott committed Mar 23, 2013
1 parent e27f013 commit ad2f02a
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
1 change: 1 addition & 0 deletions spec/glorify/helper_with_pipe.erb
@@ -0,0 +1 @@
<%= glorify(@some_code, :pipe => true) %>
1 change: 1 addition & 0 deletions spec/glorify/helper_with_toc.erb
@@ -0,0 +1 @@
<%= glorify(@some_code, :toc => true) %>
2 changes: 1 addition & 1 deletion spec/glorify/with_helper.erb
@@ -1 +1 @@
<%= glorify(@some_code) %> <%= glorify(@some_code, :pipe => true) %>
55 changes: 50 additions & 5 deletions spec/glorify_spec.rb
Expand Up @@ -4,21 +4,19 @@


it "should parse a header" do it "should parse a header" do
mock_app do mock_app do
Tilt.prefer Sinatra::Glorify::Template
get('/') { markdown :header } get('/') { markdown :header }
end end
expected = "<h1 id=\"label-a+sip+of+glory\">a sip of glory<span><a href=\"#label-a+sip+of+glory\">&para;</a> <a href=\"#documentation\">&uarr;</a></span></h1>" expected = '<h1 id="label-a+sip+of+glory">a sip of glory<span><a href="#label-a+sip+of+glory">&para;</a> <a href="#documentation">&uarr;</a></span></h1>'
get('/') get('/')
assert ok? assert ok?
assert_equal expected, body assert_equal expected, body
end end


it "should parse code blocks" do it "should parse code blocks" do
mock_app do mock_app do
Tilt.prefer Sinatra::Glorify::Template
get('/') { markdown :blocks } get('/') { markdown :blocks }
end end
expected = "<pre class=\"highlight text\">&quot;Hello, world!&quot;</pre>" expected = '<pre class="highlight text">&quot;Hello, world!&quot;</pre>'
get('/') get('/')
assert ok? assert ok?
assert_equal expected, body assert_equal expected, body
Expand All @@ -27,7 +25,6 @@
it "should parse ruby blocks" do it "should parse ruby blocks" do
mock_app do mock_app do
get('/') do get('/') do
Tilt.prefer Sinatra::Glorify::Template
markdown :ruby_blocks markdown :ruby_blocks
end end
end end
Expand All @@ -51,6 +48,36 @@
refute_empty Nokogiri::HTML(body).search("pre.highlight") refute_empty Nokogiri::HTML(body).search("pre.highlight")
end end


it "should use helper with pipe" do
mock_app do
get('/') do
@some_code = File.open(
File.expand_path('../glorify/header.md', __FILE__),
"rb"
).read
erb :helper_with_pipe
end
end
get('/')
assert ok?
assert_equal '<h1 id="label-a+sip+of+glory">a sip of glory</h1>', body
end

it "should use helper with toc" do
mock_app do
get('/') do
@some_code = File.open(
File.expand_path('../glorify/header.md', __FILE__),
"rb"
).read
erb :helper_with_toc
end
end
get('/')
assert ok?
assert_equal "<li><a href='#label-a+sip+of+glory'>a sip of glory</a></li>", body
end

it "should include a valid css helper for pygments" do it "should include a valid css helper for pygments" do
mock_app mock_app
get('/pygments.css') get('/pygments.css')
Expand All @@ -59,4 +86,22 @@
assert_match /text\/css/, content_type assert_match /text\/css/, content_type
assert_empty validate_css(body).errors assert_empty validate_css(body).errors
end end

it "should render template with pipe" do
mock_app do
get('/') { markdown :header, :pipe => true }
end
get('/')
assert ok?
assert_equal '<h1 id="label-a+sip+of+glory">a sip of glory</h1>', body
end

it "should render template with toc" do
mock_app do
get('/') { markdown :header, :toc => true }
end
get('/')
assert ok?
assert_equal "<li><a href='#label-a+sip+of+glory'>a sip of glory</a></li>", body
end
end end
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -19,7 +19,10 @@ class MiniTest::Spec
include W3CValidators include W3CValidators


def mock_app(base=Sinatra::Base, &block) def mock_app(base=Sinatra::Base, &block)
@app = Sinatra.new(base, &block) @app = Sinatra.new(base) do
Tilt.prefer Sinatra::Glorify::Template
class_eval &block if block_given?
end
end end


def app def app
Expand Down

0 comments on commit ad2f02a

Please sign in to comment.