Skip to content

Instantly share code, notes, and snippets.

@openfirmware
Created January 12, 2012 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save openfirmware/1603143 to your computer and use it in GitHub Desktop.
Save openfirmware/1603143 to your computer and use it in GitHub Desktop.
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
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"
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