repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/remote_token.rb | rack-protection/lib/rack/protection/remote_token.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery
#
# Only accepts unsafe HTTP requests if a given access token matches... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/authenticity_token.rb | rack-protection/lib/rack/protection/authenticity_token.rb | # frozen_string_literal: true
require 'rack/protection'
require 'securerandom'
require 'openssl'
require 'base64'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery
#
# This mi... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/version.rb | rack-protection/lib/rack/protection/version.rb | # frozen_string_literal: true
module Rack
module Protection
VERSION = '4.2.1'
end
end
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/form_token.rb | rack-protection/lib/rack/protection/form_token.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery
#
# Only accepts submitted forms if a given access token matches the ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/path_traversal.rb | rack-protection/lib/rack/protection/path_traversal.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Directory traversal
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Directory_traversal
#
# Unescapes '/' and '.', expands +path_info+.
# Thus <t... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/json_csrf.rb | rack-protection/lib/rack/protection/json_csrf.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: all
# More infos:: http://flask.pocoo.org/docs/0.10/security/#json-security
# http://haacked.com/archive/2008/11/20/anatomy-of-... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/escaped_params.rb | rack-protection/lib/rack/protection/escaped_params.rb | # frozen_string_literal: true
require 'rack/protection'
require 'rack/utils'
require 'tempfile'
begin
require 'escape_utils'
rescue LoadError
end
module Rack
module Protection
##
# Prevented attack:: XSS
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Cross-site_s... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/base.rb | rack-protection/lib/rack/protection/base.rb | # frozen_string_literal: true
require 'rack/protection'
require 'rack/utils'
require 'digest'
require 'logger'
require 'uri'
module Rack
module Protection
class Base
DEFAULT_OPTIONS = {
reaction: :default_reaction, logging: true,
message: 'Forbidden', encryptor: Digest::SHA1,
sessi... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/strict_transport.rb | rack-protection/lib/rack/protection/strict_transport.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Protects against against protocol downgrade attacks and cookie hijacking.
# Supported browsers:: all
# More infos:: https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/http_origin.rb | rack-protection/lib/rack/protection/http_origin.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: Google Chrome 2, Safari 4 and later
# More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery
# http://tools.ietf.... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/remote_referrer.rb | rack-protection/lib/rack/protection/remote_referrer.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: CSRF
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Cross-site_request_forgery
#
# Does not accept unsafe HTTP requests if the Referer [sic] header ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/session_hijacking.rb | rack-protection/lib/rack/protection/session_hijacking.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Session Hijacking
# Supported browsers:: all
# More infos:: http://en.wikipedia.org/wiki/Session_hijacking
#
# Tracks request properties like the user agent in the session ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/xss_header.rb | rack-protection/lib/rack/protection/xss_header.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Non-permanent XSS
# Supported browsers:: Internet Explorer 8+ and Chrome
# More infos:: http://blogs.msdn.com/b/ie/archive/2008/07/01/ie8-security-part-iv-the-xss-filter.aspx
#... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/ip_spoofing.rb | rack-protection/lib/rack/protection/ip_spoofing.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: IP spoofing
# Supported browsers:: all
# More infos:: http://blog.c22.cc/2011/04/22/surveymonkey-ip-spoofing/
#
# Detect (some) IP spoofing attacks.
class IPSpoofing < ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/frame_options.rb | rack-protection/lib/rack/protection/frame_options.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Clickjacking
# Supported browsers:: Internet Explorer 8, Firefox 3.6.9, Opera 10.50,
# Safari 4.0, Chrome 4.1.249.1042 and later
# More infos:: https://dev... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/referrer_policy.rb | rack-protection/lib/rack/protection/referrer_policy.rb | # frozen_string_literal: true
require 'rack/protection'
module Rack
module Protection
##
# Prevented attack:: Secret leakage, third party tracking
# Supported browsers:: mixed support
# More infos:: https://www.w3.org/TR/referrer-policy/
# https://caniuse.com/#sear... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/rack-protection/lib/rack/protection/host_authorization.rb | rack-protection/lib/rack/protection/host_authorization.rb | # frozen_string_literal: true
require 'rack/protection'
require 'ipaddr'
module Rack
module Protection
##
# Prevented attack:: DNS rebinding and other Host header attacks
# Supported browsers:: all
# More infos:: https://en.wikipedia.org/wiki/DNS_rebinding
# https:... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_test.rb | test/integration_test.rb | require_relative 'test_helper'
require File.expand_path('integration_helper', __dir__)
# These tests start a real server and talk to it over TCP.
# Every test runs with every detected server.
#
# See test/integration/app.rb for the code of the app we test against.
class IntegrationTest < Minitest::Test
extend Integr... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/asciidoctor_test.rb | test/asciidoctor_test.rb | require_relative 'test_helper'
begin
require 'asciidoctor'
class AsciidoctorTest < Minitest::Test
def asciidoc_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline AsciiDoc strings' do
asciidoc_app { asciido... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/sinatra_test.rb | test/sinatra_test.rb | require_relative 'test_helper'
class SinatraTest < Minitest::Test
it 'creates a new Sinatra::Base subclass on new' do
app = Sinatra.new { get('/') { 'Hello World' } }
assert_same Sinatra::Base, app.superclass
end
it "responds to #template_cache" do
assert_kind_of Sinatra::TemplateCache, Sinatra::Bas... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/rack_test.rb | test/rack_test.rb | require_relative 'test_helper'
require 'rack'
class RackTest < Minitest::Test
setup do
@foo = Sinatra.new { get('/foo') { 'foo' }}
@bar = Sinatra.new { get('/bar') { 'bar' }}
end
def build(*middleware)
endpoint = middleware.pop
@app = Rack::Builder.app do
middleware.each { |m| use m }
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/indifferent_hash_test.rb | test/indifferent_hash_test.rb | # frozen_string_literal: true
#
# We don't need the full test helper for this standalone class.
#
require 'minitest/autorun' unless defined?(Minitest)
require_relative '../lib/sinatra/indifferent_hash'
class TestIndifferentHashBasics < Minitest::Test
def test_flattened_constructor
hash = Sinatra::IndifferentHas... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/rabl_test.rb | test/rabl_test.rb | require_relative 'test_helper'
begin
require 'rabl'
require 'ostruct'
require 'json'
require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/hash/conversions'
class RablTest < Minitest::Test
def rabl_app(&block)
mock_app {
set :views, __dir__ + '/views'
get '/', &blo... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_async_test.rb | test/integration_async_test.rb | require_relative 'test_helper'
require File.expand_path('integration_async_helper', __dir__)
# These tests are like integration_test, but they test asynchronous streaming.
class IntegrationAsyncTest < Minitest::Test
extend IntegrationAsyncHelper
attr_accessor :server
it 'streams async' do
Timeout.timeout(3)... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/route_added_hook_test.rb | test/route_added_hook_test.rb | require_relative 'test_helper'
module RouteAddedTest
@routes, @procs = [], []
def self.routes ; @routes ; end
def self.procs ; @procs ; end
def self.route_added(verb, path, proc)
@routes << [verb, path]
@procs << proc
end
end
class RouteAddedHookTest < Minitest::Test
setup do
RouteAddedTest.ro... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/nokogiri_test.rb | test/nokogiri_test.rb | require_relative 'test_helper'
begin
require 'nokogiri'
class NokogiriTest < Minitest::Test
def nokogiri_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline Nokogiri strings' do
nokogiri_app { nokogiri '' }
assert ok?
as... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_helper.rb | test/integration_helper.rb | require 'sinatra/base'
require 'rbconfig'
require 'open-uri'
require 'sinatra/runner'
module IntegrationHelper
class BaseServer < Sinatra::Runner
extend Enumerable
attr_accessor :server, :port
alias name server
def self.all
@all ||= []
end
def self.all_async
@all_async ||= []
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/middleware_test.rb | test/middleware_test.rb | require_relative 'test_helper'
class MiddlewareTest < Minitest::Test
setup do
@app = mock_app(Sinatra::Application) do
get('/*')do
response.headers['X-Tests'] = env['test.ran'].
map { |n| n.split('::').last }.
join(', ')
env['PATH_INFO']
end
end
end
class ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/encoding_test.rb | test/encoding_test.rb | require_relative 'test_helper'
require 'erb'
class BaseTest < Minitest::Test
setup do
@base = Sinatra.new(Sinatra::Base)
@base.set :views, __dir__ + "/views"
end
it 'allows unicode strings in ascii templates per default (1.9)' do
next unless defined? Encoding
@base.new!.erb(File.read(@base.views... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/contest.rb | test/contest.rb | # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use,... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/templates_test.rb | test/templates_test.rb | require_relative 'test_helper'
File.delete(__dir__ + '/views/layout.test') rescue nil
class TestTemplate < Tilt::Template
def prepare
end
def evaluate(scope, locals={}, &block)
inner = block ? block.call : ''
data + inner
end
Tilt.register 'test', self
end
class TemplatesTest < Minitest::Test
de... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/server_test.rb | test/server_test.rb | require_relative 'test_helper'
require 'stringio'
module Rackup::Handler
class Mock
extend Minitest::Assertions
# Allow assertions in request context
def self.assertions
@assertions ||= 0
end
def self.assertions= assertions
@assertions = assertions
end
def self.run(app, opti... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/filter_test.rb | test/filter_test.rb | require_relative 'test_helper'
class BeforeFilterTest < Minitest::Test
it "executes filters in the order defined" do
count = 0
mock_app do
get('/') { 'Hello World' }
before do
assert_equal 0, count
count = 1
end
before do
assert_equal 1, count
count = 2... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/streaming_test.rb | test/streaming_test.rb | require_relative 'test_helper'
class StreamingTest < Minitest::Test
Stream = Sinatra::Helpers::Stream
it 'returns the concatenated body' do
mock_app do
get('/') do
stream do |out|
out << "Hello" << " "
out << "World!"
end
end
end
get('/')
assert_bod... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/routing_test.rb | test/routing_test.rb | require_relative 'test_helper'
# Helper method for easy route pattern matching testing
def route_def(pattern)
mock_app { get(pattern) { } }
end
class PatternLookAlike
def to_pattern(*)
self
end
def params(input)
{ "one" => +"this", "two" => +"is", "three" => +"a", "four" => +"test" }
end
end
class... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | true |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/static_test.rb | test/static_test.rb | require_relative 'test_helper'
class StaticTest < Minitest::Test
setup do
mock_app do
set :static, true
set :public_folder, __dir__
end
end
it 'serves GET requests for files in the public directory' do
get "/#{File.basename(__FILE__)}"
assert ok?
assert_equal File.read(__FILE__),... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/response_test.rb | test/response_test.rb | require_relative 'test_helper'
class ResponseTest < Minitest::Test
setup { @response = Sinatra::Response.new([], 200, { 'Content-Type' => 'text/html' }) }
def assert_same_body(a, b)
assert_equal a.to_enum(:each).to_a, b.to_enum(:each).to_a
end
it "initializes with 200, text/html, and empty body" do
a... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_async_helper.rb | test/integration_async_helper.rb | require File.expand_path('integration_helper', __dir__)
module IntegrationAsyncHelper
Server = IntegrationHelper::BaseServer
def it(message, &block)
Server.all_async.each do |server|
next unless server.installed?
super("with #{server.name}: #{message}") { server.run_test(self, &block) }
end
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/extensions_test.rb | test/extensions_test.rb | require_relative 'test_helper'
class ExtensionsTest < Minitest::Test
module FooExtensions
def foo
end
private
def im_hiding_in_ur_foos
end
end
module BarExtensions
def bar
end
end
module BazExtensions
def baz
end
end
module QuuxExtensions
def quux
end
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/test_helper.rb | test/test_helper.rb | if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
add_filter '/test/'
add_group 'sinatra-contrib', 'sinatra-contrib'
add_group 'rack-protection', 'rack-protection'
end
end
ENV['APP_ENV'] = 'test'
require 'rack'
testdir = __dir__
$LOAD_PATH.unshift testdir unless $LOAD_PATH.include?(testdir)... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/request_test.rb | test/request_test.rb | require_relative 'test_helper'
require 'stringio'
class RequestTest < Minitest::Test
it 'responds to #user_agent' do
request = Sinatra::Request.new({'HTTP_USER_AGENT' => 'Test'})
assert request.respond_to?(:user_agent)
assert_equal 'Test', request.user_agent
end
it 'parses POST params when Content-T... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_start_test.rb | test/integration_start_test.rb | require_relative "integration_start_helper"
class IntegrationStartTest < Minitest::Test
include IntegrationStartHelper
# what we test here: that the correct help text is printed when the required gems aren't installed
def test_app_start_without_rackup
# Why we skip head versions: The Gemfile used here would... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/delegator_test.rb | test/delegator_test.rb | require_relative 'test_helper'
class DelegatorTest < Minitest::Test
class Mirror
attr_reader :last_call
def method_missing(*a, &b)
@last_call = [*a.map(&:to_s)]
@last_call << b if b
end
end
def self.delegates(name)
it "delegates #{name}" do
m = mirror { send name }
assert... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/builder_test.rb | test/builder_test.rb | require_relative 'test_helper'
begin
require 'builder'
class BuilderTest < Minitest::Test
def builder_app(options = {}, &block)
mock_app do
set :views, __dir__ + '/views'
set options
get('/', &block)
end
get '/'
end
it 'renders inline Builder strings' do
builder_app { builder ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/haml_test.rb | test/haml_test.rb | require_relative 'test_helper'
begin
require 'haml'
class HAMLTest < Minitest::Test
def haml_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline HAML strings' do
haml_app { haml '%h1 Hiya' }
assert ok?
assert_equal "<h1>... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/readme_test.rb | test/readme_test.rb | require_relative 'test_helper'
# Tests to check if all the README examples work.
class ReadmeTest < Minitest::Test
example do
mock_app { get('/') { 'Hello world!' } }
get '/'
assert_body 'Hello world!'
end
section "Routes" do
example do
mock_app do
get('/') { ".. show something .."... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/compile_test.rb | test/compile_test.rb | require_relative 'test_helper'
class CompileTest < Minitest::Test
def self.parses pattern, example, expected_params, mtype = :sinatra, mopts = {}
it "parses #{example} with #{pattern} into params #{expected_params}" do
compiled = mock_app { set :mustermann_opts, :type => mtype }.send(:compile, pattern, mop... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/helpers_test.rb | test/helpers_test.rb | require_relative 'test_helper'
require 'date'
require 'json'
class HelpersTest < Minitest::Test
def test_default
assert true
end
def status_app(code, &block)
code += 2 if [204, 304].include? code
block ||= proc { }
mock_app do
get('/') do
status code
instance_eval(&block).i... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | true |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/liquid_test.rb | test/liquid_test.rb | require_relative 'test_helper'
begin
require 'liquid'
class LiquidTest < Minitest::Test
def liquid_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline liquid strings' do
liquid_app { liquid '<h1>Hiya</h1>' }
assert ok?
a... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/sass_test.rb | test/sass_test.rb | require_relative 'test_helper'
begin
require 'sass-embedded'
class SassTest < Minitest::Test
def sass_app(options = {}, &block)
mock_app do
set :views, __dir__ + '/views'
set options
get('/', &block)
end
get '/'
end
it 'renders inline Sass strings' do
sass_app { sass "#sass\n ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/yajl_test.rb | test/yajl_test.rb | require_relative 'test_helper'
begin
require 'yajl'
class YajlTest < Minitest::Test
def yajl_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline Yajl strings' do
yajl_app { yajl('json = { :foo => "bar" }') }
assert ok?
a... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/markdown_test.rb | test/markdown_test.rb | require_relative 'test_helper'
MarkdownTest = proc do
def markdown_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
def setup
Tilt.prefer engine, 'markdown', 'mkd', 'md'
super
end
# commonmarker is not installed on all platforms (e.g. j... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration_start_helper.rb | test/integration_start_helper.rb | require "childprocess"
require "expect"
require "minitest/autorun"
module IntegrationStartHelper
def command_for(app_file)
[
"ruby",
app_file,
"-p",
"0", # any free port
"-s",
"puma",
]
end
def with_process(command:, env: {}, debug: false)
process = ChildProcess.b... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/result_test.rb | test/result_test.rb | require_relative 'test_helper'
class ThirdPartyError < RuntimeError
def http_status; 400 end
end
class ResultTest < Minitest::Test
it "sets response.body when result is a String" do
mock_app { get('/') { 'Hello World' } }
get '/'
assert ok?
assert_equal 'Hello World', body
end
it "sets respo... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/mapped_error_test.rb | test/mapped_error_test.rb | require_relative 'test_helper'
class FooError < RuntimeError
end
class FooNotFound < Sinatra::NotFound
end
class FooSpecialError < Sinatra::Error
def http_status; 501 end
end
class FooStatusOutOfRangeError < Sinatra::Error
def code; 4000 end
end
class FooWithCode < Sinatra::Error
def code; 419 end
end
class... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/slim_test.rb | test/slim_test.rb | require_relative 'test_helper'
begin
require 'slim'
class SlimTest < Minitest::Test
def slim_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline slim strings' do
slim_app { slim "h1 Hiya\n" }
assert ok?
assert_equal "<h1... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/erb_test.rb | test/erb_test.rb | require_relative 'test_helper'
class ERBTest < Minitest::Test
def engine
Tilt::ERBTemplate
end
def setup
Tilt.prefer engine, :erb
super
end
def erb_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'uses the correct engine' d... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/rdoc_test.rb | test/rdoc_test.rb | require_relative 'test_helper'
begin
require 'rdoc'
require 'rdoc/markup/to_html'
class RdocTest < Minitest::Test
def rdoc_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline rdoc strings' do
rdoc_app { rdoc '= Hiya' }
asser... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/host_authorization_test.rb | test/host_authorization_test.rb | # frozen_string_literal: true
require_relative "test_helper"
class HostAuthorization < Minitest::Test
describe "in development environment" do
setup do
Sinatra::Base.set :environment, :development
end
%w[
127.0.0.1
127.0.0.1:3000
[::1]
[::1]:3000
localhost
loca... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/markaby_test.rb | test/markaby_test.rb | require_relative 'test_helper'
begin
require 'markaby'
class MarkabyTest < Minitest::Test
def markaby_app(&block)
mock_app do
set :views, __dir__ + '/views'
get('/', &block)
end
get '/'
end
it 'renders inline markaby strings' do
markaby_app { markaby 'h1 "Hiya"' }
assert ok?
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/settings_test.rb | test/settings_test.rb | require_relative 'test_helper'
class SettingsTest < Minitest::Test
setup do
@base = Sinatra.new(Sinatra::Base)
@base.set :environment => :foo, :app_file => nil
@application = Sinatra.new(Sinatra::Application)
@application.set :environment => :foo, :app_file => nil
end
it 'sets settings to liter... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/base_test.rb | test/base_test.rb | require_relative 'test_helper'
class BaseTest < Minitest::Test
describe 'Sinatra::Base subclasses' do
class TestApp < Sinatra::Base
get('/') { 'Hello World' }
end
class TestKeywordArgumentInitializerApp < Sinatra::Base
def initialize(argument:)
@argument = argument
end
g... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/scss_test.rb | test/scss_test.rb | require_relative 'test_helper'
begin
require 'sass-embedded'
class ScssTest < Minitest::Test
def scss_app(options = {}, &block)
mock_app do
set :views, __dir__ + '/views'
set options
get('/', &block)
end
get '/'
end
it 'renders inline Scss strings' do
scss_app { scss "#scss {\... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration/gemfile_without_rackup.rb | test/integration/gemfile_without_rackup.rb | # frozen_string_literal: true
source 'https://rubygems.org'
gemspec path: File.join('..', '..')
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration/zeitwerk_app.rb | test/integration/zeitwerk_app.rb | require "bundler/setup"
# This needs to come first so that sinatra require goes through zeitwerk loader
require "zeitwerk"
require "sinatra"
get "/" do
"OK"
end
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration/app.rb | test/integration/app.rb | $stderr.puts "loading"
require 'sinatra'
configure do
set :foo, :bar
end
get '/app_file' do
content_type :txt
settings.app_file
end
get '/ping' do
'pong'
end
get '/stream' do
stream do |out|
sleep 0.1
out << "a"
sleep 1.25
out << "b"
end
end
get '/mainonly' do
object = Object.new
be... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/test/integration/simple_app.rb | test/integration/simple_app.rb | require "bundler/setup"
require "sinatra"
get "/" do
"OK"
end
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/examples/chat.rb | examples/chat.rb | #!/usr/bin/env ruby -I ../lib -I lib
# frozen_string_literal: true
# This example does *not* work properly with WEBrick or other
# servers that buffer output. To shut down the server, close any
# open browser tabs that are connected to the chat server.
require 'sinatra'
set :server, :puma
connections = Set.new
get '... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/examples/lifecycle_events.rb | examples/lifecycle_events.rb | #!/usr/bin/env ruby -I ../lib -I lib
# frozen_string_literal: true
require 'sinatra'
get('/') do
'This shows how lifecycle events work'
end
on_start do
puts "=============="
puts " Booting up"
puts "=============="
end
on_stop do
puts "================="
puts " Shutting down"
puts "=================... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/examples/simple.rb | examples/simple.rb | #!/usr/bin/env ruby -I ../lib -I lib
# frozen_string_literal: true
require 'sinatra'
get('/') { 'this is a simple app' }
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra.rb | lib/sinatra.rb | # frozen_string_literal: true
require 'sinatra/main'
enable :inline_templates
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/main.rb | lib/sinatra/main.rb | # frozen_string_literal: true
module Sinatra
PARAMS_CONFIG = {}
if ARGV.any?
require 'optparse'
parser = OptionParser.new do |op|
op.on('-p port', 'set the port (default is 4567)') { |val| PARAMS_CONFIG[:port] = Integer(val) }
op.on('-s server', 'specify rack server/handler') ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/version.rb | lib/sinatra/version.rb | # frozen_string_literal: true
module Sinatra
VERSION = '4.2.1'
end
| ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/base.rb | lib/sinatra/base.rb | # frozen_string_literal: true
# external dependencies
require 'rack'
begin
require 'rackup'
rescue LoadError
end
require 'tilt'
require 'rack/protection'
require 'rack/session'
require 'mustermann'
require 'mustermann/sinatra'
require 'mustermann/regular'
# stdlib dependencies
require 'ipaddr'
require 'time'
requir... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | true |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/indifferent_hash.rb | lib/sinatra/indifferent_hash.rb | # frozen_string_literal: true
module Sinatra
# A poor man's ActiveSupport::HashWithIndifferentAccess, with all the Rails-y
# stuff removed.
#
# Implements a hash where keys <tt>:foo</tt> and <tt>"foo"</tt> are
# considered to be the same.
#
# rgb = Sinatra::IndifferentHash.new
#
# rgb[:black] ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/show_exceptions.rb | lib/sinatra/show_exceptions.rb | # frozen_string_literal: true
require 'rack/show_exceptions'
module Sinatra
# Sinatra::ShowExceptions catches all exceptions raised from the app it
# wraps. It shows a useful backtrace with the sourcefile and clickable
# context, the whole Rack environment and the request data.
#
# Be careful when you use t... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/lib/sinatra/middleware/logger.rb | lib/sinatra/middleware/logger.rb | # frozen_string_literal: true
require 'logger'
module Sinatra
module Middleware
class Logger
def initialize(app, level = ::Logger::INFO)
@app, @level = app, level
end
def call(env)
logger = ::Logger.new(env[Rack::RACK_ERRORS])
logger.level = @level
env[Rack::R... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/custom_logger_spec.rb | sinatra-contrib/spec/custom_logger_spec.rb | require 'spec_helper'
require 'sinatra/custom_logger'
RSpec.describe Sinatra::CustomLogger do
before do
rack_logger = @rack_logger = double
mock_app do
helpers Sinatra::CustomLogger
before do
env['rack.logger'] = rack_logger
end
get '/' do
logger.info 'Logged message... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/content_for_spec.rb | sinatra-contrib/spec/content_for_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::ContentFor do
subject do
Sinatra.new do
helpers Sinatra::ContentFor
set :views, File.expand_path("content_for", __dir__)
end.new!
end
Tilt.prefer Tilt::ERBTemplate
require 'hamlit'
Tilt.register Tilt::HamlTemplate, :haml
extend Forwardable... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/config_file_spec.rb | sinatra-contrib/spec/config_file_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::ConfigFile do
def config_file(*args, &block)
mock_app do
register Sinatra::ConfigFile
set :root, File.expand_path('config_file', __dir__)
instance_eval(&block) if block
config_file(*args)
end
end
it 'should set options from a simple c... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/cookies_spec.rb | sinatra-contrib/spec/cookies_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::Cookies do
def cookie_route(*cookies, headers: {}, &block)
result = nil
set_cookie(cookies)
@cookie_app.get('/') do
result = instance_eval(&block)
"ok"
end
get '/', {}, headers || {}
expect(last_response).to be_ok
expect(body).to e... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/multi_route_spec.rb | sinatra-contrib/spec/multi_route_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::MultiRoute do
it 'does not break normal routing' do
mock_app do
register Sinatra::MultiRoute
get('/') { 'normal' }
end
expect(get('/')).to be_ok
expect(body).to eq('normal')
end
it 'supports multiple routes' do
mock_app do
reg... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/haml_helpers_spec.rb | sinatra-contrib/spec/haml_helpers_spec.rb | require 'haml'
require 'spec_helper'
require 'sinatra/haml_helpers'
RSpec.describe Sinatra::HamlHelpers do
let(:quote_char) { Haml::VERSION >= "7.0.0" ? "\"" : "'" }
describe "#surround" do
it "renders correctly" do
mock_app do
helpers Sinatra::HamlHelpers
get "/" do
haml_code ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/extension_spec.rb | sinatra-contrib/spec/extension_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::Extension do
module ExampleExtension
extend Sinatra::Extension
set :foo, :bar
settings.set :bar, :blah
configure :test, :production do
set :reload_stuff, false
end
configure :development do
set :reload_stuff, true
end
get '... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/reloader_spec.rb | sinatra-contrib/spec/reloader_spec.rb | require 'spec_helper'
require 'fileutils'
RSpec.describe Sinatra::Reloader do
# Returns the temporary directory.
def tmp_dir
File.expand_path('../tmp', __dir__)
end
# Returns the path of the Sinatra application file created by
# +setup_example_app+.
def app_file_path
File.join(tmp_dir, "example_ap... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/respond_with_spec.rb | sinatra-contrib/spec/respond_with_spec.rb | require 'multi_json'
require 'spec_helper'
require 'okjson'
RSpec.describe Sinatra::RespondWith do
def respond_app(&block)
mock_app do
set :app_file, __FILE__
set :views, root + '/respond_with'
register Sinatra::RespondWith
class_eval(&block)
end
end
def respond_to(*args, &block... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/quiet_logger_spec.rb | sinatra-contrib/spec/quiet_logger_spec.rb | require 'spec_helper'
require 'sinatra/quiet_logger'
require 'logger'
RSpec.describe Sinatra::QuietLogger do
it 'logs just paths not excluded' do
log = StringIO.new
logger = Logger.new(log)
mock_app do
use Rack::CommonLogger, logger
set :quiet_logger_prefixes, %w(quiet asset)
register ... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/capture_spec.rb | sinatra-contrib/spec/capture_spec.rb | # -*- coding: utf-8 -*-
require 'slim'
require 'spec_helper'
RSpec.describe Sinatra::Capture do
subject do
Sinatra.new do
enable :inline_templates
helpers Sinatra::Capture
end.new!
end
Tilt.prefer Tilt::ERBTemplate
extend Forwardable
def_delegators :subject, :capture, :capture_later
d... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/namespace_spec.rb | sinatra-contrib/spec/namespace_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::Namespace do
verbs = [:get, :head, :post, :put, :delete, :options, :patch]
def mock_app(&block)
super do
register Sinatra::Namespace
class_eval(&block)
end
end
def namespace(*args, &block)
mock_app { namespace(*args, &block) }
end
ver... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/json_spec.rb | sinatra-contrib/spec/json_spec.rb | require 'multi_json'
require 'spec_helper'
require 'okjson'
RSpec.shared_examples_for "a json encoder" do |lib, const|
before do
begin
require lib if lib
@encoder = eval(const)
rescue LoadError
skip "unable to load #{lib}"
end
end
it "allows setting :encoder to #{const}" do
en... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/link_header_spec.rb | sinatra-contrib/spec/link_header_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::LinkHeader do
before do
mock_app do
helpers Sinatra::LinkHeader
before('/') { link 'something', :rel => 'from-filter', :foo => :bar }
get '/' do
link :something, 'booyah'
end
get '/style' do
stylesheet '/style.css'
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/streaming_spec.rb | sinatra-contrib/spec/streaming_spec.rb | require 'spec_helper'
RSpec.describe Sinatra::Streaming do
def stream(&block)
rack_middleware = @use
out = nil
mock_app do
rack_middleware.each { |args| use(*args) }
helpers Sinatra::Streaming
get('/') { out = stream(&block) }
end
get('/')
out
end
def use(*args)
@us... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/okjson.rb | sinatra-contrib/spec/okjson.rb | # Copyright 2011 Keith Rarick
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/spec_helper.rb | sinatra-contrib/spec/spec_helper.rb | ENV['RACK_ENV'] = 'test'
require 'sinatra/contrib'
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# The generated `.rspec` file contains `--require spec_helper` which will cause this
# file to always be loaded, w... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/spec/required_params_spec.rb | sinatra-contrib/spec/required_params_spec.rb | require_relative 'spec_helper'
RSpec.describe Sinatra::RequiredParams do
context "#required_params" do
context "simple keys" do
before do
mock_app do
helpers Sinatra::RequiredParams
get('/') { required_params(:p1, :p2) }
end
end
it 'return 400 if required par... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/lib/sinatra/webdav.rb | sinatra-contrib/lib/sinatra/webdav.rb | # frozen_string_literal: true
require 'sinatra/base'
module Sinatra
# = Sinatra::WebDAV
#
# This extensions provides WebDAV verbs, as defined by RFC 4918
# (https://tools.ietf.org/html/rfc4918). To use this in your app,
# just +register+ it:
#
# require 'sinatra/base'
# require 'sinatra/webdav'
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/lib/sinatra/cookies.rb | sinatra-contrib/lib/sinatra/cookies.rb | # frozen_string_literal: true
require 'sinatra/base'
module Sinatra
# = Sinatra::Cookies
#
# Easy way to deal with cookies
#
# == Usage
#
# Allows you to read cookies:
#
# get '/' do
# "value: #{cookies[:something]}"
# end
#
# And of course to write cookies:
#
# get '/set' do
... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/lib/sinatra/respond_with.rb | sinatra-contrib/lib/sinatra/respond_with.rb | # frozen_string_literal: true
require 'sinatra/json'
require 'sinatra/base'
module Sinatra
#
# = Sinatra::RespondWith
#
# These extensions let Sinatra automatically choose what template to render or
# action to perform depending on the request's Accept header.
#
# Example:
#
# # Without Sinatra::R... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/lib/sinatra/required_params.rb | sinatra-contrib/lib/sinatra/required_params.rb | # frozen_string_literal: true
require 'sinatra/base'
module Sinatra
# = Sinatra::RequiredParams
#
# Ensure required query parameters
#
# == Usage
#
# Set required query parameter keys in the argument.
# It'll halt with 400 if required keys don't exist.
#
# get '/simple_keys' do
# required_... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
sinatra/sinatra | https://github.com/sinatra/sinatra/blob/074d876e0c54ffbe605bb733cefc5a71bb22dbc1/sinatra-contrib/lib/sinatra/engine_tracking.rb | sinatra-contrib/lib/sinatra/engine_tracking.rb | # frozen_string_literal: true
require 'sinatra/base'
module Sinatra
# Adds methods like `haml?` that allow helper methods to check whether they
# are called from within a template.
module EngineTracking
attr_reader :current_engine
# @return [Boolean] Returns true if current engine is `:erb`.
def er... | ruby | MIT | 074d876e0c54ffbe605bb733cefc5a71bb22dbc1 | 2026-01-04T15:37:42.068011Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.