Sha256: 82a2e525365e3191cfca7dff9ee9f528da5ef7dd274f6f77d8a1becf195cb64c
Contents?: true
Size: 1.24 KB
Versions: 8
Compression:
Stored size: 1.24 KB
Contents
require 'helper' require 'prop/middleware' require 'prop/rate_limited' class TestMiddleware < Test::Unit::TestCase context Prop::Middleware do setup do @app = stub() @env = {} @middleware = Prop::Middleware.new(@app) end context "when the app call completes" do setup do @app.expects(:call).with(@env).returns("response") end should "return the response" do assert_equal "response", @middleware.call(@env) end end context "when the app call results in a raised throttle" do setup do @app.expects(:call).with(@env).raises(Prop::RateLimited.new(:handle => "foo", :threshold => 10, :interval => 60, :cache_key => "wibble", :description => "Boom!")) end should "return the rate limited message" do response = @middleware.call(@env) assert_equal 429, response[0] assert_equal ["Boom!"], response[2] end context "with a custom error handler" do setup do @middleware = Prop::Middleware.new(@app, :error_handler => Proc.new { |env, error| "Oops" }) end should "allow setting a custom error handler" do assert_equal "Oops", @middleware.call(@env) end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems