Created
January 12, 2012 21:11
-
-
Save openfirmware/1603143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
When /^I send a GET request for "([^"]*)"$/ do |path| | |
get path | |
end | |
When /^I send more than one GET request in a second to "([^"]*)"$/ do |path| | |
# We'll assume this happens in < 1 second | |
get path | |
get path | |
end | |
Then /^the response code should be "([^"]*)"$/ do |code| | |
last_response.status.should == code.to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: My Dumb API | |
In order to retrieve an API response | |
As a web API developer | |
I want an API to respond to my requests | |
Scenario: API is available | |
When I send a GET request for "http://example.com/api/" | |
Then the response code should be "200" | |
Scenario: Exceeding API Query Rate | |
When I send more than one GET request in a second to "http://example.com/api" | |
Then the response code should be "403" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RailsApp::Application.routes.draw do | |
mount Rack::Builder.new { | |
use Rack::Throttle::Interval, :min => 1.0 | |
run proc { |env| | |
[200, {}, ["OK"]] | |
} | |
} => "/api" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment