Sha256: a19b617e5e673b88df99967c5c372ae1a21e4abc528accb3dfaf4acb2f8fc7b4

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

require 'helper'
require 'rack/test'

class App

  include Newark

  before do
    headers['X-Newark-Version'] = Newark::VERSION
  end

  after do
    headers['X-Newark-Done'] = 'true'
  end

  get '/', params: { user: 'frank' } do
    'hello frank'
  end

  get '/' do
    'hello'
  end

  get(/\/regexp/) do
    'regexp'
  end

  get '/create' do
    'whoops'
  end

  post '/create' do
    'created'
  end

  get '/request_and_response' do
    request && response
    headers && params
    'ok'
  end

  get '/variables/:a/:b' do
    "#{params[:a]}:#{params[:b]}"
  end

end

class TestRouter < Minitest::Unit::TestCase

  include Rack::Test::Methods

  def app
    App.new
  end

  def test_gets_root
    get '/'
    assert last_response.ok?
    assert_equal 'hello', last_response.body
  end

  def test_gets_root_with_param_constraint
    get '/', user: 'frank'
    assert last_response.ok?
    assert_equal 'hello frank', last_response.body
  end

  def test_gets_404
    get '/not_found'
    refute last_response.ok?
    assert last_response.not_found?
  end

  def test_gets_by_regexp
    get '/regexp'
    assert last_response.ok?
    assert_equal 'regexp', last_response.body
  end

  def test_post
    post '/create'
    assert last_response.ok?
    assert_equal 'created', last_response.body
  end

  def test_has_access_to_request_and_response
    get '/request_and_response'
    assert last_response.ok?
    assert_equal 'ok', last_response.body
  end

  def test_before_hook
    get '/'
    assert_equal Newark::VERSION, last_response.header['X-Newark-Version']
  end

  def test_after_hook
    get '/'
    assert_equal 'true', last_response.header['X-Newark-Done']
  end

  def test_variable_globbing
    get '/variables/fu/bar'
    assert last_response.ok?
    assert_equal 'fu:bar', last_response.body
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newark-0.0.1 test/test_router.rb