0.0
No commit activity in last 3 years
No release in over 3 years
HttpTesting allows testing HTTP requests.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.0.0
 Project Readme

HttpTesting¶ ↑

Library for testing HTTP requests in Ruby.

Install¶ ↑

gem install http-testing

General usage pattern¶ ↑

#Start HttpTesting context
c = HttpTesting::Context.start(30013) do |request, response|
  # request - instance of WEBrick::HTTPRequest
  # response - instance of WEBrick::HTTPResponse

  #Assert request properties

  #Set response
end

#Your code that will send the request goes here

#Wait for request to complete
c.wait

#Check the result of request

RSpec sample¶ ↑

require 'spec_helper'

describe "HTTP requests sender" do
  it "should get '/say-hello'" do
    #Start HttpTesting context on port 30013
    c = HttpTesting::Context.start(30013) do |request, response|
      # request - instance of WEBrick::HTTPRequest
      # response - instance of WEBrick::HTTPResponse

      #Check method and path
      request.request_method.should eql "GET"
      request.path.should eql '/say-hello'

      #Set response
      response.body = "Hello World"
    end

    #Send get request
    result = Net::HTTP.get(URI.parse('http://localhost:30013/say-hello'))

    #Wait for request to complete
    c.wait

    #Check the result
    result.should eql "Hello World"
  end  

  it "should post '/hello-there'" do
    #Starting context
    c = HttpTesting::Context.start(30013) do |request, response|
      #Checking method, path and body of request
      request.request_method.should eql "POST"
      request.path.should eql '/hello-there'
      request.body.should eql "from=Mike"

      #Set response
      response.body = "Hello"
    end

    #Send post request
    response = Net::HTTP.post_form(URI.parse('http://localhost:30013/hello-there'), :from => "Mike")

    #Wait for request to complete
    c.wait

    #Check the result
    response.body.should eql "Hello"
  end
end