Sha256: 79dc53140a10640b4c3494acabb6767f9b02a5897c8e93365b618a58b501425f

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

describe Shb::Client do

  context "defaults" do
    specify { expect(Shb::Client.new.config.cache).to be_falsey }
    specify { expect(Shb::Client.new.config.cycle_user_agent).to be_falsey }
    specify { expect(Shb::Client.new.config.use_cookies).to be_falsey }
    specify { expect(Shb::Client.new.class.default_options[:parser]).to eq Shb::Parser }
    specify { expect(Shb::Client.new.class.default_options[:follow_redirects]).to be_falsey }
    specify { expect(Shb::Client.new.class.default_options[:headers]['User-Agent']).to eq Shb::AbstractClient::USER_AGENT }
  end

  context "simple requests" do
    before do 
      stub_request(:any, 'supremegolf.com').to_return {|r| 
        {
          status:200, 
          body: r.method.to_s.downcase
        }
      }
    end
    let(:shb) { Shb::Client.new }

    specify { expect(shb.get('/').code).to eq 200 }
    specify { expect(shb.get('/').body).to eq "get" }
    specify { expect(shb.post('/').code).to eq 200 }
    specify { expect(shb.post('/').body).to eq "post" }
    specify { expect(shb.put('/').code).to eq 200 }
    specify { expect(shb.put('/').body).to eq "put" }
    specify { expect(shb.delete('/').code).to eq 200 }
    specify { expect(shb.delete('/').body).to eq "delete" }
  end

  context "requests with data" do
    before do 
      stub_request(:any, 'supremegolf.com?q=1').to_return {|r| 
        { status:200, body: [r.uri.query, r.body].join('&') }
      }
    end
    let(:shb) { Shb::Client.new }

    specify { expect(shb.get('/', query: {q: 1}).body).to eq "q=1&" }
    specify { expect(shb.post('/', query: {q: 1}, body: {body: 1}).body).to eq "q=1&body=1" }
    specify { expect(shb.put('/', query: {q: 1}, body: {body: 1}).body).to eq "q=1&body=1" }
    specify { expect(shb.delete('/', query: {q: 1}, body: {body: 1}).body).to eq "q=1&body=1" }
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shb-0.1.4 spec/shb_spec.rb