__ __ ______
/ / / /_ _________________/ ____/________________
/ /_/ / / / / __ \ _ \_ __/____ \/ __ \ _ \ ___/
/ __ / /_/ / /_/ / __/ / ____/ / /_/ / __/ /__
/_/ /_/\__, / ____/\___/_/ /_____/ ____/\___/\___/
/____/_/ /_/
A full stack testing framework for HTTP APIs.
By extending minitest/spec
HyperSpec provides a Ruby DSL for testing
HTTP APIs from the outside.
#source: examples/readme/service_spec.rb
service "http://localhost:4567" do
def responds_with_json_where
JSON.parse(response.body)
end
resource "/lolz" do
get do
it { responds_with.status :ok }
it { responds_with_json_where['lolz'].must_be_instance_of Array }
with_query("q=monorail") do
it "only lists lolz that match the query" do
responds_with_json_where['lolz'].wont_be_empty
responds_with_json_where['lolz'].each do |lol|
lol['title'].must_match /monorail/
end
end
end
with_query("q=looong") do
it "only lists lolz that match the query" do
responds_with_json_where['lolz'].wont_be_empty
responds_with_json_where['lolz'].each do |lol|
lol['title'].must_match /looong/
end
end
end
end
post do
describe "without request body" do
it { responds_with.status :unprocessable_entity }
end
describe "with request body" do
with_headers({ 'Content-Type' => 'application/json' }) do
with_request_body({ "title" => "Roflcopter!" }.to_json) do
it { responds_with.status :created }
it do
responds_with_json_where['lol']['title'].
must_equal 'Roflcopter!'
end
end
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 component of a request. Overrides previously set parameters.
Sets the headers of a request. Merges with previously set headers.
Sets the body of 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.
- Adding an output format for docs.
- Efficient ways of building up and verifying precondition state.
- Verify an eventual consistent state.
- Allowing whitebox testing by "wormholing" into the application(s).
Thanks to:
- Daniel Bornkessel for inspiring me to do
README
driven development. - Matthias Georgi for suggestions for code improvements.
- Lars Gierth for updating the example server to respond with 415 Unsupported Media Type in the appropriate case.
- Anton Lindqvist for adding HTTP Basic Auth
- Josh Devins for noticing missing HTTP status codes and
with_query
documentation inconsistency.
- Change dependency declaration.
- Change behavior of
with_query
to override instead of append.
- Add complete list of HTTP response codes.
- Correcting environment dependencies.
- Adding support for HTTP Basic Auth.
- Initial release