Sha256: 44744f273a5776af9f43b1677cfcc68258c925f7f9b40c7fafbfa6c7c97b75a2

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

require 'horseman/connection'
require 'net/http'

describe Horseman::Connection do
  subject do
    c = described_class.new
    c.url = 'http://www.example.com/some/path'
    c
  end
  
  context "when building requests" do  
    let(:request) {subject.build_request(:verb => :get)}
    
    it "uses the proper path" do
      request.path.should eq '/some/path'
    end
    
    context "using GET" do
      it "uses the proper request type" do
        request.class.should be Net::HTTP::Get
      end
    end
    
    context "using POST" do
      let(:request) {subject.build_request(:verb => :post)}
      
      it "uses the proper request type" do
        request.class.should be Net::HTTP::Post
      end

      context "with form data" do
        let(:request) {subject.build_request(:verb => :post, :form => {:field1=>'value1', :field2=>'value2'})}
        
        it "properly sets request body" do
          request.body.should eq 'field1=value1&field2=value2'
        end
      end

      context "without form data" do    
        it "properly sets request body" do
          request.body.should be_nil
        end
      end
    end    
  end
  
  context "when accessed using http" do
    it "does not use SSL" do
      subject.http.use_ssl?.should be_false
    end
  end
  
  context "when accessed using https" do
    subject do
      c = described_class.new
      c.url = 'https://www.example.com'
      c
    end

    it "uses SSL" do
      subject.http.use_ssl?.should be_true
    end
  end  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
horseman-0.0.1 spec/horseman/connection_spec.rb