Sha256: 198e4fbbc0cf45c3c2a6fb26986330c144a14c0d43a423926090aa49a8922cc8

Contents?: true

Size: 1.31 KB

Versions: 15

Compression:

Stored size: 1.31 KB

Contents

require 'rubygems'
gem 'rspec'
require 'spec'
require File.join(File.dirname(__FILE__), '..', 'lib', 'weary')

def get_fixture(filename)
  open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename.to_s}")).read
end

def mock_response(request_method = :get, code=200, header={}, body=nil)
  response_class = Net::HTTPResponse::CODE_TO_OBJ[code.to_s]
  message = case code
    when 200
      "OK"
    when 301
      "Moved Permanently"
    when 302
      "Moved Temporarily"
    when 400
      "Bad Request"
    when 401
      "Unauthorized"
    when 403
      "Forbidden"
    when 404
      "Not Found"
    when 405
      "Method Not Allowed"
    when 409
      "Conflict"
    when 422
      "Unprocessable Entity"
    when 401...500
      "Client Error"
    when 500...600
      "Server Error"
    else
      "Unknown"
  end
  response = response_class.new("1.1", code, "Hello World!")
  response.initialize_http_header(header)
  response.stub!(:body).and_return(body)
  response.stub!(:message).and_return(message)
  
  response
end

def mock_request(url, method = :get, options={}, mock_header={}, mock_body=nil)
  request = Weary::Request.new(url, method, options)
  http_response = mock_response(method, 200, mock_header, mock_body)
  request.stub!(:perform).and_return Weary::Response.new(http_response, method)
  
  request
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
mwunsch-weary-0.2.3 spec/spec_helper.rb
mwunsch-weary-0.3.0 spec/spec_helper.rb
mwunsch-weary-0.3.1 spec/spec_helper.rb
mwunsch-weary-0.4.0 spec/spec_helper.rb
mwunsch-weary-0.4.1 spec/spec_helper.rb
mwunsch-weary-0.4.3 spec/spec_helper.rb
mwunsch-weary-0.5.0 spec/spec_helper.rb
weary-0.5.1 spec/spec_helper.rb
weary-0.3.0 spec/spec_helper.rb
weary-0.3.1 spec/spec_helper.rb
weary-0.4.0 spec/spec_helper.rb
weary-0.4.1 spec/spec_helper.rb
weary-0.4.3 spec/spec_helper.rb
weary-0.5.0 spec/spec_helper.rb
weary-0.2.3 spec/spec_helper.rb