All Projects → mdub → Sham_rack

mdub / Sham_rack

Licence: mit
run Rack applications in-process, without a server

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Sham rack

Async sinatra
A plugin for Sinatra to provide a DSL extension for using Thin for asynchronous responses
Stars: ✭ 434 (+156.8%)
Mutual labels:  sinatra, rack
Bugsnag Ruby
Bugsnag error monitoring & reporting software for rails, sinatra, rack and ruby
Stars: ✭ 211 (+24.85%)
Mutual labels:  sinatra, rack
Sinatra
Classy web-development dressed in a DSL (official / canonical repo)
Stars: ✭ 11,497 (+6702.96%)
Mutual labels:  sinatra, rack
rack-cargo
🚚 Batch requests for Rack apps (works with Rails, Sinatra, etc)
Stars: ✭ 17 (-89.94%)
Mutual labels:  rack, sinatra
rack-simple user agent
Rack::SimpleUserAgent is stupidly simple UA detector
Stars: ✭ 13 (-92.31%)
Mutual labels:  rack, sinatra
encrypted cookie
AES-128 encrypted session cookies for Rack (and Sinatra and other frameworks).
Stars: ✭ 54 (-68.05%)
Mutual labels:  rack, sinatra
Rack Reducer
Declaratively filter data via URL params, in any Rack app, with any ORM.
Stars: ✭ 241 (+42.6%)
Mutual labels:  sinatra, rack
serverless-rack
Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems
Stars: ✭ 58 (-65.68%)
Mutual labels:  rack, sinatra
Ferrocarril
🚆 Experiments to embed Ruby on Rails in Rust with mruby
Stars: ✭ 66 (-60.95%)
Mutual labels:  sinatra, rack
Mock server
A lightweight Sinatra application backed by sqlite that can mock ReST responses. Has interface to easily create, search & maintain mocks. No need to program mocks into a language specific implementation.
Stars: ✭ 107 (-36.69%)
Mutual labels:  sinatra
Pipes
Repository for Pipes
Stars: ✭ 107 (-36.69%)
Mutual labels:  sinatra
Sinatra Partial
Just the partials helper in a gem. That is all.
Stars: ✭ 105 (-37.87%)
Mutual labels:  sinatra
Capybara discoball
Spin up an external server just for Capybara
Stars: ✭ 116 (-31.36%)
Mutual labels:  rack
Trebekbot
An addictive Jeopardy! bot for Slack. Fun fact, after I added this to my work Slack I was told to limit it to a single channel because productivity ground to a halt. (Five years later, the #jeopardy channel is still going strong.)
Stars: ✭ 147 (-13.02%)
Mutual labels:  sinatra
Timber Ruby
🌲 Great Ruby logging made easy.
Stars: ✭ 154 (-8.88%)
Mutual labels:  sinatra
Rack Weixin
微信公众平台 开放消息接口 Rack Middleware
Stars: ✭ 105 (-37.87%)
Mutual labels:  rack
As
VCV Rack Modules
Stars: ✭ 104 (-38.46%)
Mutual labels:  rack
Draftsman
Ruby gem that lets you create draft versions of your database records.
Stars: ✭ 159 (-5.92%)
Mutual labels:  sinatra
Pinatra
A PHP copy of Sinatra: a DSL for quickly creating web applications in PHP with minimal effort.
Stars: ✭ 151 (-10.65%)
Mutual labels:  sinatra
Prax.cr
Rack proxy server for development (Crystal port)
Stars: ✭ 142 (-15.98%)
Mutual labels:  rack

ShamRack

Gem Version Build Status

ShamRack plumbs HTTP requests into Rack.

What's it for, again?

Well, it makes it easy to stub out external (HTTP) services, which is handy in development and testing environments, or when you want to test your HTTP client code.

You can also use it to test your Rack application (or Sinatra, or Rails, or Merb) using a variety of HTTP client libraries, to check interoperability. For instance, you could test your app using:

all without having to boot it in a server.

Installing it

gem install sham_rack

Using it

A simple inline application

require 'sham_rack'

ShamRack.at("www.greetings.com") do |env|
  ["200 OK", { "Content-type" => "text/plain" }, ["Hello, world!"]]
end

require 'open-uri'
open("http://www.greetings.com/").read            #=> "Hello, world!"

Sinatra integration

ShamRack.at("sinatra.xyz").sinatra do
  get "/hello/:subject" do
    "Hello, #{params[:subject]}"
  end
end

open("http://sinatra.xyz/hello/stranger").read  #=> "Hello, stranger"

Rackup support

ShamRack.at("rackup.xyz").rackup do
  use Some::Middleware
  use Some::Other::Middleware
  run MyApp.new
end

Any old Rack app

ShamRack.at("google.com").mount(my_google_stub)

General-purpose stubbing

@stub_app = ShamRack.at("stubbed.com").stub
@stub_app.register_resource("/greeting", "Hello, world!", "text/plain")

open("http://stubbed.com/greeting").read       #=> "Hello, world!"
@stub_app.last_request.path                    #=> "/greeting"

On a specific port

ShamRack.at("example.com", 8080) do |env|
  ["200 OK", { "Content-type" => "text/plain" }, ["Hello, world!"]]
end

Or, just use Sinatra, as described above ... it's almost as succinct, and heaps more powerful.

Avoiding (accidental) real network connections

ShamRack.prevent_network_connections

When you're done testing

ShamRack.reset

open("http://stubbed.com/greeting").read       #=> OpenURI::HTTPError

Supported HTTP client libraries

Net::HTTP and friends

ShamRack supports requests made using Net::HTTP, or any of the numerous APIs built on top of it:

uri = URI.parse("http://www.greetings.com/")
Net::HTTP.get_response(uri).body                      #=> "Hello, world!"

require 'open-uri'
open("http://www.greetings.com/").read                #=> "Hello, world!"

require 'restclient'
RestClient.get("http://www.greetings.com/").to_s      #=> "Hello, world!"

require 'mechanize'
Mechanize.new.get("http://www.greetings.com/").body   #=> "Hello, world!"

Patron (experimental)

We've recently added support for Patron:

require 'sham_rack/patron'

patron = Patron::Session.new
patron.get("http://www.greetings.com/").body          #=> "Hello, world!"

What's the catch?

  • Your Rack request-handling code runs in the same Ruby VM, in fact the same Thread, as your request.

Thanks to

  • Blaine Cook for FakeWeb, which was an inspiration for ShamRack.
  • Perryn Fowler for his efforts plumbing Net::HTTP into ActionController::TestProcess.
  • Christian Neukirchen et al for the chewy goodness that is Rack.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].