summaryrefslogtreecommitdiff
path: root/spec/ruby/core/encoding/invalid_byte_sequence_error/error_bytes_spec.rb
blob: a8f7354b16ca8f8e2ca318c4bd1afbbd93c8163f (plain)
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
# -*- encoding: binary -*-
require_relative '../fixtures/classes'

describe "Encoding::InvalidByteSequenceError#error_bytes" do
  before :each do
    @exception, @errinfo = EncodingSpecs::InvalidByteSequenceError.exception
    @exception2, @errinfo2 = EncodingSpecs::InvalidByteSequenceErrorIndirect.exception
  end

  it "returns a String" do
    @exception.error_bytes.should be_an_instance_of(String)
    @exception2.error_bytes.should be_an_instance_of(String)
  end

  it "returns the bytes that caused the exception" do
    @exception.error_bytes.size.should == 1
    @exception.error_bytes.should == "\xF1"
    @exception.error_bytes.should == @errinfo[-2]

    @exception2.error_bytes.size.should == 1
    @exception2.error_bytes.should == "\xA1"
    @exception2.error_bytes.should == @errinfo2[-2]
  end

  it "uses BINARY as the encoding" do
    @exception.error_bytes.encoding.should == Encoding::BINARY

    @exception2.error_bytes.encoding.should == Encoding::BINARY
  end
end