Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit e5efd86

Browse files
committed
Add spec for exception when failure_lines has a bad encoding
1 parent 8c88d97 commit e5efd86

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

spec/rspec/core/encoding_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# # encoding: utf-8
2+
require 'spec_helper'
3+
require 'rspec/core/notifications'
4+
5+
RSpec.describe "FailedExampleNotification" do
6+
break unless String.method_defined?(:encoding)
7+
8+
include FormatterSupport
9+
10+
let(:notification) { ::RSpec::Core::Notifications::FailedExampleNotification.new(example) }
11+
12+
before do
13+
allow(example).to receive(:file_path) { __FILE__ }
14+
end
15+
16+
describe '#message_lines' do
17+
let(:message_with_invalid_byte_sequence) do
18+
"\xEF \255 \xAD".force_encoding(Encoding::UTF_8)
19+
end
20+
let(:exception) do
21+
instance_double(
22+
Exception,
23+
:backtrace => [ "#{__FILE__}:#{__LINE__}"],
24+
:message => message_with_invalid_byte_sequence,
25+
)
26+
end
27+
let(:example_group) do
28+
class_double(
29+
RSpec::Core::ExampleGroup,
30+
:metadata => {},
31+
:parent_groups => [],
32+
:location => "#{__FILE__}:#{__LINE__}"
33+
)
34+
end
35+
36+
before do
37+
allow(example).to receive(:example_group) { example_group }
38+
end
39+
40+
context "when failure_lines contains an invalid byte sequence" do
41+
it "raises an ArgumentError" do
42+
expect { lines = notification.message_lines }.to raise_error(ArgumentError)
43+
end
44+
end
45+
46+
end
47+
end

0 commit comments

Comments
 (0)