File: http_error_spec.rb

package info (click to toggle)
ruby-yajl 1.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 3,068; ruby: 2,619; makefile: 4; sh: 3
file content (31 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
begin
  require 'yajl/bzip2'
rescue
  warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
end
require 'yajl/gzip'
require 'yajl/deflate'
require 'yajl/http_stream'

describe "Yajl HTTP error" do
  before do
    @uri = 'file://' + File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.error.dump")
    @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.error.dump"), 'r')
    allow(TCPSocket).to receive(:new).and_return(@request)
    allow(@request).to receive(:write)
    begin
      Yajl::HttpStream.get(@uri)
    rescue Yajl::HttpStream::HttpError => e
      @error = e
    end
  end

  it "should contain the error code in the message" do
    expect(@error.message).to match(/404/)
  end

  it "should provide the HTTP response headers" do
    expect(@error.headers.keys).to include('ETag', 'Content-Length', 'Server')
  end
end