Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

worded test assertions in a clearer fashion

added test for non-404 pages
  • Loading branch information...
commit 208c0941036d79126ac93dfa529937b811241c8e 1 parent b64447b
Gernot authored
Showing with 18 additions and 15 deletions.
  1. +3 −3 test/helper.rb
  2. +15 −12 test/test_rack_piwik.rb
View
6 test/helper.rb
@@ -14,9 +14,9 @@ def mock_app(options)
main_app = lambda { |env|
request = Rack::Request.new(env)
case request.path
- when '/' then [200,{ 'Content-Type' => 'application/html' },['<head>Hello world</head>']]
- when '/test.xml' then [200,{'Content-Type' => 'application/xml'}, ['Xml here']]
- when '/bob' then [200,{'Content-Type' => 'application/html'} ,['<body>bob here</body>']]
+ when '/head_only' then [200,{ 'Content-Type' => 'application/html' },['<head>head only</head>']]
+ when '/arbitrary.xml' then [200,{'Content-Type' => 'application/xml'}, ['xml only']]
+ when '/body_only' then [200,{'Content-Type' => 'application/html'} ,['<body>body only</body>']]
else [404,'Nothing here']
end
}
View
27 test/test_rack_piwik.rb
@@ -5,26 +5,29 @@ class TestRackPiwik < Test::Unit::TestCase
context "Asynchronous" do
context "default" do
setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
- should "show asynchronous tracker" do
- get "/"
+ should "add tracker if body element is present" do
+ get "/body_only"
assert_match %r{https://piwik.example.org/}, last_response.body
assert_match %r{123\);}, last_response.body
- assert_match %r{</script>\n<!-- End Piwik Code --></head>}, last_response.body
- assert_equal "538", last_response.headers['Content-Length']
+ assert_match %r{</noscript>\n<!-- End Piwik Code --></body>}, last_response.body
+ assert_equal "650", last_response.headers['Content-Length']
end
- setup { mock_app :async => true, :multiple => true, :tracker => 'gonna', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
- should "not add tracker to none html content-type" do
- get "/test.xml"
+ should "omit 404 tracking for other responses with other status" do
+ get "/body_only"
+ assert_no_match %r{.setDocumentTitle\('404/URL}, last_response.body
+ end
+
+ should "omit addition of tracking code for non-html content" do
+ get "/arbitrary.xml"
assert_no_match %r{Piwik}, last_response.body
- assert_match %r{Xml here}, last_response.body
+ assert_match %r{xml only}, last_response.body
end
- setup { mock_app :async => true, :multiple => true, :tracker => 'gonna', :piwik_url => 'piwik.example.org', :piwik_id => '123' }
- should "not add without </head>" do
- get "/bob"
+ should "omit addition of tracking code if </body> tag is missing" do
+ get "/head_only"
assert_no_match %r{Piwik}, last_response.body
- assert_match %r{bob here}, last_response.body
+ assert_match %r{head only}, last_response.body
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.