This fixes a stderr redirection test on fast machines. The write pipe was
getting closed before the redirection thread had a chance to copy it's contents into it.
This commit is contained in:
parent
0f85960214
commit
5dd835e4ca
|
@ -19,18 +19,18 @@ describe Capybara::Webkit::Connection do
|
|||
end
|
||||
|
||||
it 'forwards stderr to the given IO object' do
|
||||
read, write = IO.pipe
|
||||
redirected_connection = Capybara::Webkit::Connection.new(:stderr => write)
|
||||
script = 'console.log("hello world")'
|
||||
read_io, write_io = IO.pipe
|
||||
redirected_connection = Capybara::Webkit::Connection.new(:stderr => write_io)
|
||||
redirected_connection.puts "EnableLogging"
|
||||
redirected_connection.puts 0
|
||||
|
||||
script = 'console.log("hello world")'
|
||||
redirected_connection.puts "Execute"
|
||||
redirected_connection.puts 1
|
||||
redirected_connection.puts script.to_s.bytesize
|
||||
redirected_connection.print script
|
||||
sleep(0.5)
|
||||
write.close
|
||||
read.read.should =~ /hello world $/
|
||||
|
||||
expect(read_io).to include_response "hello world \n"
|
||||
end
|
||||
|
||||
it 'does not forward stderr to nil' do
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
RSpec::Matchers.define :include_response do |expected_response|
|
||||
read_timeout = 2
|
||||
read_bytes = 4096
|
||||
response = ""
|
||||
|
||||
match do |read_io|
|
||||
found_response = false
|
||||
|
||||
while !found_response && IO.select([read_io], nil, nil, read_timeout) do
|
||||
response += read_io.read_nonblock(read_bytes)
|
||||
found_response = response.include?(expected_response)
|
||||
end
|
||||
|
||||
found_response
|
||||
end
|
||||
|
||||
failure_message_for_should do |actual|
|
||||
"expected #{response} to include #{expected_response}"
|
||||
end
|
||||
|
||||
failure_message_for_should_not do |actual|
|
||||
"expected #{response} to not include #{expected_response}"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue