Created
February 7, 2011 04:25
-
-
Save ahawkins/813994 to your computer and use it in GitHub Desktop.
api_steps.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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