Skip to content

Instantly share code, notes, and snippets.

@flazz
Forked from anonymous/gist:239024
Created November 19, 2009 20:43
Show Gist options
  • Save flazz/239034 to your computer and use it in GitHub Desktop.
Save flazz/239034 to your computer and use it in GitHub Desktop.
it "returns 400 on POST if request is missing X-Package-Name header" do
post '/', "FOO", "Content-MD5" => "cccccccccccccccccccccccccccccccc"
last_response.status.should == 400
last_response.body.should == "Missing parameter: package_name"
end
# % spec sp.rb ~
# nil
# {"Content-Type"=>"text/html"}
# F
#
# 1)
# 'foo returns 400 on POST if request is missing X-Package-Name header' FAILED
# expected: "Missing parameter: package_name",
# got: "Missing parameter: X-Package-Name" (using ==)
# ./sp.rb:16:
#
# Finished in 0.051887 seconds
#
# 1 example, 1 failure
# puts output from sinatra app shows no headers sent
# sinatra app below
#!/usr/bin/env ruby
require 'sinatra'
require 'pp'
# return 400 on HEAD, GET, or DELETE
head "/" do
halt 405
end
get "/" do
halt 405
end
delete "/" do
halt 405
end
# All submissions are expected to be POST requests
post '/' do
pp body
pp headers
# All incoming requests must include package_name and md5 query parameters
halt 400, "Missing parameter: X-Package-Name" unless headers["X-Package-Name"]
halt 400, "Missing parameter: Content-MD5" unless headers["Content-MD5"]
# All incoming requests must include a body
halt 400, "Missing body" unless body
"foo"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment