Browse files

Merge branch 'spec'

  • Loading branch information...
2 parents 0b17c8b + 33a3ddd commit 15360772f8bf493310bcf7d953efe90bcdddcc07 @zzak committed May 22, 2012
View
9 Rakefile
@@ -1 +1,10 @@
require "bundler/gem_tasks"
+
+require 'rake/testtask'
+
+Rake::TestTask.new do |t|
+ t.pattern = "spec/*_spec.rb"
+end
+
+task(:spec => :test)
+task(:default => :test)
View
4 glorify.gemspec
@@ -18,4 +18,8 @@ Gem::Specification.new do |s|
s.add_runtime_dependency "redcarpet", "~> 2.0"
s.add_runtime_dependency "pygments.rb"
s.add_runtime_dependency "nokogiri"
+
+ s.add_development_dependency "minitest"
+ s.add_development_dependency "rack-test"
+ s.add_development_dependency "rake"
end
View
1 spec/glorify/blocks.erb
@@ -0,0 +1 @@
+<%= glorify('```puts "Hello, world!"```') %>
View
1 spec/glorify/header.erb
@@ -0,0 +1 @@
+<%= glorify("#a sip of glory") %>
View
1 spec/glorify/layout.erb
@@ -0,0 +1 @@
+<%= yield %>
View
1 spec/glorify/ruby_blocks.erb
@@ -0,0 +1 @@
+<%= glorify(@some_code) %>
View
5 spec/glorify/some_code.md
@@ -0,0 +1,5 @@
+```ruby
+def in_ruby?
+ return apples.all? { |a| a.to_s == 'ruby' }
+end
+```
View
43 spec/glorify_spec.rb
@@ -0,0 +1,43 @@
+begin
+ require_relative 'spec_helper'
+rescue NameError
+ require File.expand_path('../spec_helper', __FILE__)
+end
+
+describe Sinatra::Glorify do
+
+ it "should parse a header" do
+ mock_app do
+ get('/') { erb :header }
+ end
+ expected = "<h1>a sip of glory</h1>"
+ get('/')
+ assert ok?
+ assert_equal expected, body
+ end
+
+ it "should parse code blocks" do
+ mock_app do
+ get('/') { erb :blocks }
+ end
+ expected = "<p><code>puts &quot;Hello, world!&quot;</code></p>"
+ get('/')
+ assert ok?
+ assert_equal expected, body
+ end
+
+ it "should parse ruby blocks" do
+ mock_app do
+ get('/') do
+ @some_code = File.open(
+ File.expand_path('../glorify/some_code.md', __FILE__),
+ "rb"
+ ).read
+ erb :ruby_blocks
+ end
+ end
+ get('/')
+ assert ok?
+ refute_empty Nokogiri::HTML(body).search("//div[@class = 'highlight']/pre")
+ end
+end
View
34 spec/spec_helper.rb
@@ -0,0 +1,34 @@
+ENV['RACK_ENV'] = 'test'
+require 'minitest/spec'
+require 'minitest/autorun'
+require 'rack'
+
+require 'glorify'
+require 'nokogiri'
+require 'rack/test'
+require 'sinatra/base'
+require 'erb'
+
+Sinatra::Base.set :environment, :test
+Sinatra::Base.set :views, File.expand_path('../glorify', __FILE__)
+Sinatra::Base.register Sinatra::Glorify
+
+class MiniTest::Spec
+ include Rack::Test::Methods
+
+ def mock_app(base=Sinatra::Base, &block)
+ @app = Sinatra.new(base, &block)
+ end
+
+ def app
+ Rack::Lint.new(@app)
+ end
+
+ def body
+ last_response.body.gsub(/\n/,'')
+ end
+
+ def ok?
+ last_response.ok?
+ end
+end

0 comments on commit 1536077

Please sign in to comment.