source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/test_helper.rb
Ruby
mit
12,419
main
3,601
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)...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/streaming_test.rb
Ruby
mit
12,419
main
3,604
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/extensions_test.rb
Ruby
mit
12,419
main
2,737
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/request_test.rb
Ruby
mit
12,419
main
5,718
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/sass_test.rb
Ruby
mit
12,419
main
2,272
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/compile_test.rb
Ruby
mit
12,419
main
6,281
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/server_test.rb
Ruby
mit
12,419
main
2,604
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_async_helper.rb
Ruby
mit
12,419
main
551
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/haml_test.rb
Ruby
mit
12,419
main
2,950
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>...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/indifferent_hash_test.rb
Ruby
mit
12,419
main
8,919
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/templates_test.rb
Ruby
mit
12,419
main
11,076
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/builder_test.rb
Ruby
mit
12,419
main
2,208
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/rabl_test.rb
Ruby
mit
12,419
main
2,010
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/settings_test.rb
Ruby
mit
12,419
main
17,064
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/response_test.rb
Ruby
mit
12,419
main
2,334
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/yajl_test.rb
Ruby
mit
12,419
main
1,818
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/slim_test.rb
Ruby
mit
12,419
main
2,630
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_start_test.rb
Ruby
mit
12,419
main
2,411
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/route_added_hook_test.rb
Ruby
mit
12,419
main
1,339
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_async_test.rb
Ruby
mit
12,419
main
1,066
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)...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/rdoc_test.rb
Ruby
mit
12,419
main
1,504
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/mapped_error_test.rb
Ruby
mit
12,419
main
7,269
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_test.rb
Ruby
mit
12,419
main
2,233
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/readme_test.rb
Ruby
mit
12,419
main
2,724
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 .."...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/result_test.rb
Ruby
mit
12,419
main
2,085
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/nokogiri_test.rb
Ruby
mit
12,419
main
1,626
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/markaby_test.rb
Ruby
mit
12,419
main
1,970
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? ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/delegator_test.rb
Ruby
mit
12,419
main
4,053
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/asciidoctor_test.rb
Ruby
mit
12,419
main
1,912
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/erb_test.rb
Ruby
mit
12,419
main
2,571
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/rack_test.rb
Ruby
mit
12,419
main
1,040
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 } ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/encoding_test.rb
Ruby
mit
12,419
main
569
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/sinatra_test.rb
Ruby
mit
12,419
main
352
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/markdown_test.rb
Ruby
mit
12,419
main
2,788
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/filter_test.rb
Ruby
mit
12,419
main
11,766
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/host_authorization_test.rb
Ruby
mit
12,419
main
3,944
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_start_helper.rb
Ruby
mit
12,419
main
1,574
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/base_test.rb
Ruby
mit
12,419
main
5,706
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/contest.rb
Ruby
mit
12,419
main
3,237
# 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,...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/liquid_test.rb
Ruby
mit
12,419
main
1,922
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration_helper.rb
Ruby
mit
12,419
main
3,330
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 ||= [] ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/routing_test.rb
Ruby
mit
12,419
main
39,828
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/helpers_test.rb
Ruby
mit
12,419
main
52,431
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/static_test.rb
Ruby
mit
12,419
main
9,667
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__),...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
test/integration/app.rb
Ruby
mit
12,419
main
1,265
$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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
examples/chat.rb
Ruby
mit
12,419
main
1,633
#!/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 '...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
examples/lifecycle_events.rb
Ruby
mit
12,419
main
326
#!/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 "=================...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
examples/stream.ru
Ruby
mit
12,419
main
498
# frozen_string_literal: true # this example does *not* work properly with WEBrick # # run *one* of these: # # unicorn stream.ru # gem install unicorn # puma stream.ru # gem install puma require 'sinatra/base' class Stream < Sinatra::Base get '/' do content_type :txt ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
lib/sinatra/main.rb
Ruby
mit
12,419
main
1,825
# 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') ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
lib/sinatra/show_exceptions.rb
Ruby
mit
12,419
main
12,169
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
lib/sinatra/indifferent_hash.rb
Ruby
mit
12,419
main
4,537
# 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] ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
lib/sinatra/base.rb
Ruby
mit
12,419
main
68,361
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
lib/sinatra/middleware/logger.rb
Ruby
mit
12,419
main
392
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/sinatra-contrib.gemspec
Ruby
mit
12,419
main
1,434
# frozen_string_literal: true require_relative 'lib/sinatra/contrib/version' version = Sinatra::Contrib::VERSION Gem::Specification.new do |s| s.name = 'sinatra-contrib' s.version = version s.description = 'Collection of useful Sinatra extensions' s.homepage = 'http://sinatrarb.com/contrib/' ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/Gemfile
Ruby
mit
12,419
main
703
# frozen_string_literal: true source 'https://rubygems.org' gemspec rack_version = ENV['rack'].to_s rack_version = nil if rack_version.empty? || (rack_version == 'stable') rack_version = { github: 'rack/rack' } if rack_version == 'head' tilt_version = ENV['tilt'].to_s tilt_version = nil if tilt_version.empty? || (t...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/Rakefile
Ruby
mit
12,419
main
2,181
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('lib', __dir__) require 'open-uri' require 'yaml' require 'sinatra/contrib/version' desc 'run specs' task(:spec) { ruby '-S rspec' } task(test: :spec) task(default: :spec) namespace :doc do task :readmes do Dir.glob 'lib/sinatra/*.rb' do |file| ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/quiet_logger_spec.rb
Ruby
mit
12,419
main
860
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/okjson.rb
Ruby
mit
12,419
main
13,724
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/respond_with_spec.rb
Ruby
mit
12,419
main
8,668
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/json_spec.rb
Ruby
mit
12,419
main
3,484
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/reloader_spec.rb
Ruby
mit
12,419
main
15,720
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/config_file_spec.rb
Ruby
mit
12,419
main
3,353
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/cookies_spec.rb
Ruby
mit
12,419
main
20,668
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/content_for_spec.rb
Ruby
mit
12,419
main
9,013
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/namespace_spec.rb
Ruby
mit
12,419
main
27,639
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/link_header_spec.rb
Ruby
mit
12,419
main
2,365
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' ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/custom_logger_spec.rb
Ruby
mit
12,419
main
901
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/streaming_spec.rb
Ruby
mit
12,419
main
9,437
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/spec_helper.rb
Ruby
mit
12,419
main
3,625
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/multi_route_spec.rb
Ruby
mit
12,419
main
1,268
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/haml_helpers_spec.rb
Ruby
mit
12,419
main
1,788
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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/extension_spec.rb
Ruby
mit
12,419
main
676
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 '...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/required_params_spec.rb
Ruby
mit
12,419
main
2,251
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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/spec/capture_spec.rb
Ruby
mit
12,419
main
2,248
# -*- 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/multi_route.rb
Ruby
mit
12,419
main
2,197
# frozen_string_literal: true require 'sinatra/base' module Sinatra # = Sinatra::MultiRoute # # Create multiple routes with one statement. # # == Usage # # Use this extension to create a handler for multiple routes: # # get '/foo', '/bar' do # # ... # end # # Or for multiple verbs: ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/haml_helpers.rb
Ruby
mit
12,419
main
1,159
# frozen_string_literal: true require 'sinatra/base' require 'sinatra/capture' module Sinatra # = Sinatra::HamlHelpers # # This extension provides some of the helper methods that existed in Haml 5 # but were removed in Haml 6. To use this in your app, just +register+ it: # # require 'sinatra/base' # ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/namespace.rb
Ruby
mit
12,419
main
10,515
# frozen_string_literal: true require 'sinatra/base' require 'mustermann' module Sinatra # = Sinatra::Namespace # # <tt>Sinatra::Namespace</tt> is an extension that adds namespaces to an # application. This namespaces will allow you to share a path prefix for the # routes within the namespace, and define f...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/streaming.rb
Ruby
mit
12,419
main
5,800
# frozen_string_literal: true require 'sinatra/base' module Sinatra # = Sinatra::Streaming # # Sinatra 1.3 introduced the +stream+ helper. This addon improves the # streaming API by making the stream object imitate an IO object, turning # it into a real Deferrable and making the body play nicer with middlew...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/reloader.rb
Ruby
mit
12,419
main
14,273
# frozen_string_literal: true require 'sinatra/base' module Sinatra # = Sinatra::Reloader # # <b>DEPRECATED:<b> Please consider using an alternative like # <tt>rerun</tt> or <tt>rack-unreloader</tt> instead. # # Extension to reload modified files. Useful during development, # since it will automaticall...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/config_file.rb
Ruby
mit
12,419
main
5,249
require 'sinatra/base' require 'yaml' require 'erb' module Sinatra # = Sinatra::ConfigFile # # <tt>Sinatra::ConfigFile</tt> is an extension that allows you to load the # application's configuration from YAML files. It automatically detects if # the files contain specific environment settings and it will use...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/link_header.rb
Ruby
mit
12,419
main
3,774
require 'sinatra/base' module Sinatra # = Sinatra::LinkHeader # # <tt>Sinatra::LinkHeader</tt> adds a set of helper methods to generate link # HTML tags and their corresponding Link HTTP headers. # # == Usage # # Once you had set up the helpers in your application (see below), you will # be able to c...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/extension.rb
Ruby
mit
12,419
main
2,601
# frozen_string_literal: true require 'sinatra/base' module Sinatra # = Sinatra::Extension # # <tt>Sinatra::Extension</tt> is a mixin that provides some syntactic sugar # for your extensions. It allows you to call almost any # <tt>Sinatra::Base</tt> method directly inside your extension # module. This mea...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/quiet_logger.rb
Ruby
mit
12,419
main
1,553
# frozen_string_literal: true module Sinatra # = Sinatra::QuietLogger # # QuietLogger extension allows you to define paths excluded # from logging using the +quiet_logger_prefixes+ setting. # It is inspired from rails quiet_logger, but handles multiple paths. # # == Usage # # === Classic Application ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/engine_tracking.rb
Ruby
mit
12,419
main
2,458
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/webdav.rb
Ruby
mit
12,419
main
2,333
# 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' ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/custom_logger.rb
Ruby
mit
12,419
main
1,479
# frozen_string_literal: true module Sinatra # = Sinatra::CustomLogger # # CustomLogger extension allows you to define your own logger instance # using +logger+ setting. That logger then will be available # as #logger helper method in your routes and views. # # == Usage # # === Classic Application ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/content_for.rb
Ruby
mit
12,419
main
6,002
# frozen_string_literal: true require 'sinatra/base' require 'sinatra/capture' module Sinatra # = Sinatra::ContentFor # # <tt>Sinatra::ContentFor</tt> is a set of helpers that allows you to capture # blocks inside views to be rendered later during the request. The most # common use is to populate different ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/test_helpers.rb
Ruby
mit
12,419
main
5,721
# frozen_string_literal: true require 'sinatra/base' require 'rack' begin require 'rack/test' rescue LoadError abort 'Add rack-test to your Gemfile to use this module!' end require 'forwardable' module Sinatra Base.set :environment, :test # Helper methods to ease testing your Sinatra application. Partly extr...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/required_params.rb
Ruby
mit
12,419
main
1,683
# 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_...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/capture.rb
Ruby
mit
12,419
main
2,514
require 'sinatra/base' require 'sinatra/engine_tracking' module Sinatra # # = Sinatra::Capture # # Extension that enables blocks inside other extensions. # It currently works for erb, slim and haml. # Enables mixing of different template languages. # # Example: # # # in hello_world.erb # # ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/json.rb
Ruby
mit
12,419
main
3,456
# frozen_string_literal: true require 'sinatra/base' require 'multi_json' module Sinatra # = Sinatra::JSON # # <tt>Sinatra::JSON</tt> adds a helper method, called +json+, for (obviously) # json generation. # # == Usage # # === Classic Application # # In a classic application simply require the help...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/runner.rb
Ruby
mit
12,419
main
3,648
# frozen_string_literal: true require 'open-uri' require 'net/http' require 'timeout' module Sinatra # NOTE: This feature is experimental, and missing tests! # # Helps you spinning up and shutting down your own sinatra app. This is especially helpful for running # real network tests against a sinatra backend....
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/respond_with.rb
Ruby
mit
12,419
main
8,085
# 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...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/cookies.rb
Ruby
mit
12,419
main
7,147
# 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 ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/contrib.rb
Ruby
mit
12,419
main
1,289
# frozen_string_literal: true require 'sinatra/contrib/setup' module Sinatra module Contrib ## # Common middleware that doesn't bring run time overhead if not used # or breaks if external dependencies are missing. Will extend # Sinatra::Application by default. module Common register :Confi...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
sinatra-contrib/lib/sinatra/contrib/setup.rb
Ruby
mit
12,419
main
1,055
# frozen_string_literal: true require 'sinatra/base' require 'sinatra/contrib/version' module Sinatra module Contrib module Loader def extensions @extensions ||= { helpers: [], register: [] } end def register(name, path) autoload name, path, :register end def help...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/rack-protection.gemspec
Ruby
mit
12,419
main
1,414
# frozen_string_literal: true require_relative 'lib/rack/protection/version' Gem::Specification.new do |s| # general infos s.name = 'rack-protection' s.version = Rack::Protection::VERSION s.description = 'Protect against typical web attacks, works with all Rack apps, including Rails' s.homepage ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/Rakefile
Ruby
mit
12,419
main
2,047
# frozen_string_literal: true $LOAD_PATH.unshift File.expand_path('lib', __dir__) begin require 'bundler' Bundler::GemHelper.install_tasks rescue LoadError => e warn e end desc 'run specs' task(:spec) { ruby '-S rspec' } namespace :doc do task :readmes do Dir.glob 'lib/rack/protection/*.rb' do |file| ...
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/Gemfile
Ruby
mit
12,419
main
312
# frozen_string_literal: true source 'https://rubygems.org' gemspec gem 'rake' gem 'rspec', '~> 3' gem 'rack-test' rack_version = ENV['rack'].to_s rack_version = nil if rack_version.empty? || (rack_version == 'stable') rack_version = { github: 'rack/rack' } if rack_version == 'head' gem 'rack', rack_version
github
sinatra/sinatra
https://github.com/sinatra/sinatra
rack-protection/lib/rack/protection.rb
Ruby
mit
12,419
main
3,352
# frozen_string_literal: true require 'rack/protection/version' require 'rack' module Rack module Protection autoload :AuthenticityToken, 'rack/protection/authenticity_token' autoload :Base, 'rack/protection/base' autoload :CookieTossing, 'rack/protection/cookie_tossing' ...