__ __ ______
/ / / /_ _________________/ ____/________________
/ /_/ / / / / __ \ _ \_ __/____ \/ __ \ _ \ ___/
/ __ / /_/ / /_/ / __/ / ____/ / /_/ / __/ /__
/_/ /_/\__, / ____/\___/_/ /_____/ ____/\___/\___/
/____/_/ /_/
A full stack testing framework for HTTP APIs.
By extending minitest/spec
HyperSpec provides a Ruby DSL for testing
HTTP APIs from the outside.
service "http://api.lolcat.biz" do
resource "/lolz" do
get do
it { responds_with.status :ok }
it { response.json['lolz].must be_an(Array) }
with_query("q=monorail") do
it "only lists lolz that match the query" do
response.json['lolz'].each do |lol|
lol['title'].must =~ /monorail/
end
end
end
end
post do
context "without request body" do
it { responds_with.status :unprocessable_entity }
end
context "with request body" do
context "in JSON format" do
with_headers { 'Content-Type' => 'application/json' }
with_request_body { "title" => "Roflcopter!" }.to_json
it { responds_with.status :created }
it { response.json['lol']['title'].must == 'Roflcopter!' }
end
end
end
end
end
Sets the BASE_URI
of the API.
Sets the URI
under test. Absolute or relative to the current scope.
Selects the HTTP method for the request.
Sets the query parameters used for a request. Merges with previously set parameters.
Sets the headers used for a request. Merges with previously set headers.
Sets the body used for a request. Overrides previously set parameters.
An object for accessing properties of the "raw" response.
Issues the request and returns an object that has the following convenience matchers:
Allows for comparing against named status code symbols.
- DSL for matching representations.
- Efficient ways of building up and verifying precondition state.
- Verify an eventual consistent state.
- Allowing whitebox testing by "wormholing" into the application(s).
- How to test a testing library? #meta
Thanks to Daniel Bornkessel for inspiring me to do README driven development.