Permalink
Browse files

add tests for existing library

  • Loading branch information...
1 parent 3e241b9 commit 41216de3a0c9429911edf3be397be576ccb75629 @phlipper phlipper committed Mar 30, 2012
Showing with 54 additions and 0 deletions.
  1. +10 −0 spec/fixtures/test.html
  2. +44 −0 spec/rack_typekit_spec.rb
View
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Rack::Typekit Test</title>
+</head>
+<body>
+ <h1>Rack::Typekit</h1>
+ <p>Test file.</p>
+</body>
+</html>
View
@@ -0,0 +1,44 @@
+require "minitest/autorun"
+require "minitest/pride"
+require "rack"
+require "rack/lint"
+require "rack/mock"
+require "rack/typekit"
+
+describe Rack::Typekit do
+ let(:html_file) do
+ File.read(File.expand_path("../fixtures/test.html", __FILE__))
+ end
+ let(:html_app) { proc{[200,{"Content-Type"=>"text/html"},[html_file]]} }
+ let(:text_app) { proc{[200,{"Content-Type"=>"text/plain"},["FOO"]]} }
+ let(:typekit_html) { Rack::Typekit.new(html_app, :kit => "123") }
+ let(:typekit_text) { Rack::Typekit.new(text_app, :kit => "123") }
+
+ it { proc{ Rack::Typekit.new(nil) }.must_raise(ArgumentError) }
+
+ it { typekit_html.must_be_kind_of(Rack::Typekit) }
+ it { typekit_text.must_be_kind_of(Rack::Typekit) }
+
+ describe "script injection" do
+ describe "html" do
+ let(:request) { Rack::MockRequest.new(Rack::Lint.new(typekit_html)) }
+ let(:response) { request.get("/") }
+
+ it { response.status.must_equal 200 }
+ it { response.body.must_match %(src="http://use.typekit.com/123.js") }
+ it { response.body.must_match "try{Typekit.load();}catch(e){}" }
+ it { response.body.must_match "<title>Rack::Typekit Test</title>" }
+ it { response.body.must_match "<p>Test file.</p>" }
+ end
+
+ describe "text" do
+ let(:request) { Rack::MockRequest.new(Rack::Lint.new(typekit_text)) }
+ let(:response) { request.get("/") }
+
+ it { response.status.must_equal 200 }
+ it { response.body.wont_match %(src="http://use.typekit.com/123.js") }
+ it { response.body.wont_match "try{Typekit.load();}catch(e){}" }
+ it { response.body.must_match "FOO" }
+ end
+ end
+end

0 comments on commit 41216de

Please sign in to comment.