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

Commit 113866a

Browse files
committed
When Encoding.default_external is set, eg. Rails, ensure RSpec::Core::Bisect::Channel can send and receive binary data (encoded by Marshal.dump)
1 parent e95cfe3 commit 113866a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/rspec/core/bisect/utilities.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ def publish(event, *args)
3232
# parent process.
3333
# @private
3434
class Channel
35+
MARSHAL_DUMP_ENCODING = Marshal.dump("").encoding
36+
3537
def initialize
3638
@read_io, @write_io = IO.pipe
39+
40+
# Ensure the pipe is able to send any content produced by Marshal.dump
41+
@write_io.set_encoding MARSHAL_DUMP_ENCODING
3742
end
3843

3944
def send(message)

spec/rspec/core/bisect/utilities_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,39 @@ def foo(notification); end
3636

3737
expect(channel.receive).to eq :value_from_child
3838
end
39+
40+
describe "with UTF-8 encoding set (eg. Rails)" do
41+
around(:each) do |example|
42+
old_external = old_internal = nil
43+
44+
ignoring_warnings do
45+
old_external, Encoding.default_external = Encoding.default_external, Encoding::UTF_8
46+
old_internal, Encoding.default_internal = Encoding.default_internal, Encoding::UTF_8
47+
end
48+
49+
example.run
50+
51+
ignoring_warnings do
52+
Encoding.default_external = old_external
53+
Encoding.default_internal = old_internal
54+
end
55+
end
56+
57+
it "successfully sends binary data" do
58+
channel = Bisect::Channel.new
59+
expect { channel.send("\xF8") }.not_to raise_error
60+
end
61+
62+
it "supports sending binary data from a child process back to the parent" do
63+
channel = Bisect::Channel.new
64+
65+
in_sub_process do
66+
channel.send("\xF8")
67+
end
68+
69+
expect(channel.receive).to eq("\xF8")
70+
end
71+
end
72+
3973
end
4074
end

0 commit comments

Comments
 (0)