Sha256: 4ba8c477ba3a64775ffb6ce73668920565c15a37e5f00329fbbc897be7746025

Contents?: true

Size: 1.21 KB

Versions: 63

Compression:

Stored size: 1.21 KB

Contents

require File.join( File.dirname(File.expand_path(__FILE__)), 'base')

require 'webmock/rspec'
include WebMock

describe RestClient do

  it "a simple request" do
    body = 'abc'
    stub_request(:get, "www.example.com").to_return(:body => body, :status => 200)
    response = RestClient.get "www.example.com"
    response.code.should == 200
    response.body.should == body
  end

  it "a simple request with gzipped content" do
    stub_request(:get, "www.example.com").with(:headers => { 'Accept-Encoding' => 'gzip, deflate' }).to_return(:body => "\037\213\b\b\006'\252H\000\003t\000\313T\317UH\257\312,HM\341\002\000G\242(\r\v\000\000\000", :status => 200,  :headers => { 'Content-Encoding' => 'gzip' } )
    response = RestClient.get "www.example.com"
    response.code.should == 200
    response.body.should == "i'm gziped\n"
  end

  it "a 404" do
    body = "Ho hai ! I'm not here !"
    stub_request(:get, "www.example.com").to_return(:body => body, :status => 404)
    begin
      RestClient.get "www.example.com"
      raise
    rescue RestClient::ResourceNotFound => e
      e.http_code.should == 404
      e.response.code.should == 404
      e.response.body.should == body
      e.http_body.should == body
    end
  end


end

Version data entries

63 entries across 57 versions & 11 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/rest-client-1.6.7/spec/integration_spec.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/rest-client-1.6.7/spec/integration_spec.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/rest-client-1.6.7/spec/integration_spec.rb
tdiary-5.0.8 vendor/bundle/gems/rest-client-1.6.7/spec/integration_spec.rb
rest-client_jxb_fix-1.6.7 spec/integration_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/rest-client-1.6.7/spec/integration_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/rest-client-1.6.7/spec/integration_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/rest-client-1.6.7/spec/integration_spec.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/rest-client-1.6.7/spec/integration_spec.rb
candlepin-api-0.4.0 bundle/ruby/gems/rest-client-1.6.7/spec/integration_spec.rb
candlepin-api-0.4.0 bundle/ruby/1.9.1/gems/rest-client-1.6.7/spec/integration_spec.rb
candlepin-api-0.4.0 bundle/ruby/1.8/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.8.2 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
cft_smartcloud-0.3.3 lib/rest-client-1.6.6-master/spec/integration_spec.rb
vulcan-0.8.1 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.8.0 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.7.2 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.7.1 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.7.0 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb
vulcan-0.6.1 server/vendor/gems/gems/rest-client-1.6.7/spec/integration_spec.rb