File: helper.rb

package info (click to toggle)
ruby-rack-piwik 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 116 kB
  • ctags: 22
  • sloc: ruby: 108; makefile: 7
file content (29 lines) | stat: -rwxr-xr-x 806 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'rack'
require 'rack/test'
require 'rack/piwik'

class Test::Unit::TestCase
  include Rack::Test::Methods
  
  def app; Rack::Lint.new(@app); end
  
  def mock_app(options)
    main_app = lambda { |env|
      request = Rack::Request.new(env)
      case request.path
      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
    }

    builder = Rack::Builder.new
    builder.use Rack::Piwik, options
    builder.run main_app
    @app = builder.to_app
  end
end