Sha256: f70550a50b9008b0c63c4767e098f71d1d02a0a74a89712c827b7e8789711baf

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module RestfullyAccessibleStub
  def stub_get_request(url, resource_name)
    stub_request(:get, url)
      .with(
        headers: request_headers
      ).to_return(
        status: 200,
        body: %Q[{#{resource_name}: "dummy"}]
      )
  end

  def stub_get_request_with_json_response(url, body)
    stub_request(:get, url)
      .with(
        headers: request_headers
      ).to_return(
        status: 200,
        headers: {'Content-Type' => 'application/json'},
        body: body.class == String ? body : body.to_json
      )
  end

  def stub_get_request_not_found(url)
    stub_request(:get, url)
      .with(
        headers: request_headers
      ).to_return(
        status: 404,
        body: "itemNotFound"
      )
  end

  def stub_get_request_unauthorized(url)
    stub_request(:get, url)
      .with(
        headers: request_headers
      ).to_return(
        status: 401,
        body: "unauthorized"
      )
  end

  def request_headers
    {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>"Faraday v#{Faraday::VERSION}"}
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
yao-0.13.1 test/support/restfully_accesible_stub.rb
yao-0.13.0 test/support/restfully_accesible_stub.rb
yao-0.12.0 test/support/restfully_accesible_stub.rb
yao-0.11.3 test/support/restfully_accesible_stub.rb
yao-0.11.2 test/support/restfully_accesible_stub.rb
yao-0.11.1 test/support/restfully_accesible_stub.rb
yao-0.11.0 test/support/restfully_accesible_stub.rb