Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Created February 7, 2011 04:25
Show Gist options
  • Save ahawkins/813994 to your computer and use it in GitHub Desktop.
Save ahawkins/813994 to your computer and use it in GitHub Desktop.
api_steps.rb
module ApiHelper
def post_json(hash, path)
uri = URI.parse(@api_server.url(path))
request = Net::HTTP::Post.new(uri.path)
request.content_type = 'application/json'
request.body = ActiveSupport::JSON.encode(hash)
response = Net::HTTP.new(uri.host, uri.port).start {|http| http.request(request) }
end
def post_form(data, path)
uri = URI.parse(@api_server.url(path))
res = Net::HTTP.post_form(uri,data)
end
def get_url(path)
Net::HTTP.get_response(URI.parse(@api_server.url(path)))
end
end
World(ApiHelper)
Given /^the server is running$/ do
if !@api_server
@api_server = Capybara::Server.new(Capybara.app).boot
end
@api_server
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment