Sha256: d7ae383a7c5fa4e477e907f4bfb88f43215cc6f04dda60e24bc6ce8290f06389

Contents?: true

Size: 1.56 KB

Versions: 65

Compression:

Stored size: 1.56 KB

Contents

require 'sinatra'

module VCR
  class SinatraApp < ::Sinatra::Base
    disable :protection

    get '/' do
      "GET to root"
    end

    get '/search' do
      "query: #{params[:q]}"
    end

    get '/localhost_test' do
      "Localhost response"
    end

    get '/foo' do
      "FOO!"
    end

    get '/redirect-to-root' do
      redirect to('/')
    end

    post '/foo' do
      "FOO!"
    end

    post '/return-request-body' do
      request.body
    end

    get '/set-cookie-headers/1' do
      headers 'Set-Cookie' => 'foo'
      'header set'
    end

    get '/set-cookie-headers/2' do
      headers 'Set-Cookie' => %w[ bar foo ]
      'header set'
    end

    get '/204' do
      status 204
    end

    get '/404_not_200' do
      status 404
      '404 not 200'
    end

    # we use a global counter so that every response is different;
    # this ensures that the test demonstrates that the response
    # is being played back (and not running a 2nd real request)
    $record_and_playback_response_count ||= 0
    get '/record-and-playback' do
      "Response #{$record_and_playback_response_count += 1}"
    end

    post '/record-and-playback' do
      "Response #{$record_and_playback_response_count += 1}"
    end

    @_boot_failed = false

    class << self
      def port
        server.port
      end

      def server
        raise "Sinatra app failed to boot." if @_boot_failed
        @server ||= begin
          VCR::LocalhostServer.new(new)
        rescue
          @_boot_failed = true
          raise
        end
      end

      alias boot server
    end
  end
end

Version data entries

65 entries across 65 versions & 9 rubygems

Version Path
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.49.21 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.49.15 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.49.13 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.49.9 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.44.4 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.30.7 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
color_me_shop-1.0.0 vendor/bundle/ruby/2.5.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
cloudsmith-api-0.21.4 vendor/bundle/ruby/2.3.0/gems/vcr-3.0.3/spec/support/sinatra_app.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/vcr-3.0.3/spec/support/sinatra_app.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/vcr-3.0.3/spec/support/sinatra_app.rb
vcr-3.0.3 spec/support/sinatra_app.rb
vcr-3.0.2 spec/support/sinatra_app.rb
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/vcr-2.9.3/spec/support/sinatra_app.rb
vcr-3.0.1 spec/support/sinatra_app.rb
vcr-3.0.0 spec/support/sinatra_app.rb
mustwin-vcr-2.9.3 spec/support/sinatra_app.rb
vcr-2.9.3 spec/support/sinatra_app.rb
vcr-2.9.2 spec/support/sinatra_app.rb