Sha256: 9bf6f4998d506f52fe4baa28ee3df0d0165dc32343662e84c671b276e101f081

Contents?: true

Size: 904 Bytes

Versions: 13

Compression:

Stored size: 904 Bytes

Contents

require 'minitest_helper'

describe Rasti::Web::Router do

  let(:router) { Rasti::Web::Router.new }

  def get(path)
    Rack::MockRequest.env_for path, method: :get
  end

  def post(path)
    Rack::MockRequest.env_for path, method: :post
  end
  
  it 'Verbs' do
    %w(delete get head options patch post put).each do |verb|
      router.must_respond_to verb
    end
  end

  it 'Route matching' do
    router.get '/resources', ->(env) { :index }
    router.post '/resources/:id', ->(env) { :update }
    router.not_found ->(env) { :not_found }

    router.call(get('/resources')).must_equal :index
    router.call(post('/resources/123')).must_equal :update
    router.call(post('/resources')).must_equal :not_found
  end

  it 'Not found' do
    status, headers, response = router.call get('/not_found')

    status.must_equal 404
    response.body.must_equal ['Not found: GET /not_found']
  end

end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rasti-web-0.2.3 spec/router_spec.rb
rasti-web-0.2.2 spec/router_spec.rb
rasti-web-0.2.1 spec/router_spec.rb
rasti-web-0.2.0 spec/router_spec.rb
rasti-web-0.1.1 spec/router_spec.rb
rasti-web-0.1.0 spec/router_spec.rb
rasti-web-0.0.7 spec/router_spec.rb
rasti-web-0.0.6 spec/router_spec.rb
rasti-web-0.0.5 spec/router_spec.rb
rasti-web-0.0.4 spec/router_spec.rb
rasti-web-0.0.3 spec/router_spec.rb
rasti-web-0.0.2 spec/router_spec.rb
rasti-web-0.0.1 spec/router_spec.rb