Sha256: b82081587c326b072f3ddeed2487cf92c9ffa47100e9e514e7faf92d923b81ab

Contents?: true

Size: 1.39 KB

Versions: 22

Compression:

Stored size: 1.39 KB

Contents

require 'rack'

class MyRackApp
  class NonArrayResponse
    # The rack response body need not implement #join,
    # but it must implement #each.  It need not be an Array.
    # ActionDispatch::Response, for example, exercises that fact.
    # See: http://rack.rubyforge.org/doc/SPEC.html

    def each(*args, &blk)
      ["This is not in an array!"].each(*args, &blk)
    end
  end

  def self.call(env)
    case env.values_at('REQUEST_METHOD', 'PATH_INFO')
      when ['GET', '/']
        [200, {}, ["This is my root!"]]
      when ['GET', '/greet']
        name = env['QUERY_STRING'][/name=([^&]*)/, 1] || "World"
        [200, {}, ["Hello, #{name}"]]
      when ['GET', '/non_array_response']
        [200, {}, NonArrayResponse.new]
      when ['GET', '/locked']
        [200, {}, ["Single threaded response."]]
      when ['POST', '/greet']
        name = env["rack.input"].read[/name=([^&]*)/, 1] || "World"
        [200, {}, ["Good to meet you, #{name}!"]]
      when ['GET', '/compute']
        if env['SERVER_PORT'] == 80 && env["SCRIPT_NAME"] == ""
          [200, {}, [""]]
        else
          [401, {}, [""]]
        end
      when ['GET', '/error']
        env['rack.errors'].puts('Error!')
        [500, {}, ['']]
      else
        [404, {}, ['']]
    end
  end
end

class MyLockedRackApp
  MUTEX = Mutex.new

  def self.call(env)
    lock = Rack::Lock.new(MyRackApp, MUTEX)
    lock.call(env)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
webmock-1.17.4 spec/support/my_rack_app.rb
webmock-1.17.3 spec/support/my_rack_app.rb
webmock-1.17.2 spec/support/my_rack_app.rb
webmock-1.17.1 spec/support/my_rack_app.rb
webmock-1.17.0 spec/support/my_rack_app.rb
webmock-1.16.1 spec/support/my_rack_app.rb
webmock-1.16.0 spec/support/my_rack_app.rb
webmock-1.15.2 spec/support/my_rack_app.rb
webmock-1.15.0 spec/support/my_rack_app.rb
webmock-1.14.0 spec/support/my_rack_app.rb
webmock-1.13.0 spec/support/my_rack_app.rb
webmock-1.12.3 spec/support/my_rack_app.rb
webmock-1.12.2 spec/support/my_rack_app.rb
webmock-1.12.1 spec/support/my_rack_app.rb
webmock-1.12.0 spec/support/my_rack_app.rb
webmock-1.11.0 spec/support/my_rack_app.rb
webmock-1.10.2 spec/support/my_rack_app.rb
webmock-1.10.1 spec/support/my_rack_app.rb
webmock-1.10.0 spec/support/my_rack_app.rb
webmock-1.9.3 spec/support/my_rack_app.rb