Sha256: 68213374776cea87760f68ea42f02462fddef67417494ce659ec90e2bb8118db

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

require "spec_helper"

class HTTPTester < Rapidash::Client
  include Rapidash::HTTPClient
end

class HTTPSiteTester < HTTPTester
  class << self
    attr_accessor :site
  end
end

class HTTPErrorTester < HTTPSiteTester
  def self.raise_error
    true
  end
end

describe Rapidash::HTTPClient do

  let!(:subject) { HTTPTester.new }

  describe ".connection" do
    it "should create a Faraday object" do
      subject.site = "http://example.com/"
      subject.connection.class.should eql(Faraday::Connection)
    end

    it "should raise Configuration error if site nil" do
      expect {
        subject.connection
      }.to raise_error(Rapidash::ConfigurationError)
    end

    it "should use the site variable if set" do
      Faraday.should_receive(:new).with("http://example.com/")
      subject.site = "http://example.com/"
      subject.connection
    end
  end

  describe ".request" do

    before(:each) do
      subject.site = "http://example.com"
    end

    describe "authorization" do
      let!(:subject) { HTTPTester.new(:login => "login", :password => "password") }

      it "should delegate to Faraday's basic auth" do
        expect(subject.connection.builder.handlers).to include(Faraday::Request::BasicAuthentication)
      end
    end

    describe "without authorization" do
      let!(:subject) { HTTPTester.new() }

      it "should delegate to Faraday's basic auth" do
        expect(subject.connection.builder.handlers).to_not include(Faraday::Request::BasicAuthentication)
      end
    end

    it "should call response" do
      response = double(:body => "response")
      subject.connection.should_receive(:run_request).with(:get, "http://example.com/foo", nil, nil).and_return(response)
      subject.request(:get, "foo")
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rapidash-0.3.1 spec/rapidash/http_client_spec.rb
rapidash-0.3.0 spec/rapidash/http_client_spec.rb
rapidash-0.3.0.beta2 spec/rapidash/http_client_spec.rb
rapidash-0.3.0.beta spec/rapidash/http_client_spec.rb