Sha256: e6979e92ab464dfd8ebeb5fe819e96f79315194078bc987624e51681c0606635

Contents?: true

Size: 1.8 KB

Versions: 5

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper'

describe Ethon::Easy::Http::Head do
  let(:easy) { Ethon::Easy.new }
  let(:url) { "http://localhost:3001/" }
  let(:params) { nil }
  let(:form) { nil }
  let(:head) { described_class.new(url, {:params => params, :body => form}) }

  describe "#setup" do
    context "when nothing" do
      it "sets nobody" do
        easy.should_receive(:nobody=).with(true)
        head.setup(easy)
      end

      it "sets url" do
        head.setup(easy)
        expect(easy.url).to eq(url)
      end
    end

    context "when params" do
      let(:params) { {:a => "1&b=2"} }

      it "sets nobody" do
        easy.should_receive(:nobody=).with(true)
        head.setup(easy)
      end

      it "attaches escaped to url" do
        head.setup(easy)
        expect(easy.url).to eq("#{url}?a=1%26b%3D2")
      end

      context "when requesting" do
        before do
          head.setup(easy)
          easy.perform
        end

        it "returns ok" do
          expect(easy.return_code).to eq(:ok)
        end

        it "has no body" do
          expect(easy.response_body).to be_empty
        end

        it "requests parameterized url" do
          expect(easy.effective_url).to eq("http://localhost:3001/?a=1%26b%3D2")
        end

        context "when url already contains params" do
          let(:url) { "http://localhost:3001/?query=here" }

          it "requests parameterized url" do
            expect(easy.effective_url).to eq("http://localhost:3001/?query=here&a=1%26b%3D2")
          end
        end
      end
    end

    context "when body" do
      let(:form) { {:a => 1} }

      context "when requesting" do
        before do
          head.setup(easy)
          easy.perform
        end

        it "returns ok" do
          expect(easy.return_code).to eq(:ok)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ethon-0.7.0 spec/ethon/easy/http/head_spec.rb
ethon-0.6.3 spec/ethon/easy/http/head_spec.rb
ethon-0.6.2 spec/ethon/easy/http/head_spec.rb
ethon-0.6.1 spec/ethon/easy/http/head_spec.rb
ethon-0.6.0 spec/ethon/easy/http/head_spec.rb