Sha256: 5558d92e67851edc708d4be68f72ec38e9eeccddcd71d24e98cd07e2155a8327

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe Weary::Request do
  
  it "should contain a url" do
    test = Weary::Request.new("http://google.com")
    test.uri.is_a?(URI).should == true
  end
  
  it "should parse the http method" do
    test = Weary::Request.new("http://google.com", "POST")
    test.method.should == :post
  end
  
  it "should craft a Net/HTTP Request" do
    test = Weary::Request.new("http://google.com").send :http
    test.class.should == Net::HTTP
  end
  
  it "should perform the request and retrieve a response" do
    test = Weary::Request.new("http://foo.bar")
    method = test.method
    response = Weary::Response.new(mock_response(method, 301, {'Location' => 'http://bar.foo'}), method)
    test.stub!(:perform).and_return(response)
    test.perform.code.should == 301
    test.perform.redirected?.should == true
  end
  
  it "should follow redirects" do
    test = Weary::Request.new("http://foo.bar")
    method = test.method   
    response = Weary::Response.new(mock_response(method, 301, {'Location' => 'http://bar.foo'}), method)
    response.stub!(:follow_redirect).and_return Weary::Response.new(mock_response(method, 200, {}), method)
    test.stub!(:perform).and_return(response)
    test.perform.code.should == 301
    test.perform.redirected?.should == true
    test.perform.follow_redirect.code.should == 200
    # not exactly kosher.
  end
  
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
mwunsch-weary-0.3.0 spec/weary/request_spec.rb
mwunsch-weary-0.3.1 spec/weary/request_spec.rb
mwunsch-weary-0.4.0 spec/weary/request_spec.rb
mwunsch-weary-0.4.1 spec/weary/request_spec.rb
mwunsch-weary-0.4.3 spec/weary/request_spec.rb
weary-0.3.0 spec/weary/request_spec.rb
weary-0.3.1 spec/weary/request_spec.rb
weary-0.4.0 spec/weary/request_spec.rb
weary-0.4.1 spec/weary/request_spec.rb
weary-0.4.3 spec/weary/request_spec.rb