1
0
Fork 0
mirror of https://github.com/thoughtbot/capybara-webkit synced 2023-03-27 23:22:28 -04:00
capybara-webkit/spec/support/matchers/include_response.rb
Alex Kwiatkowski 5dd835e4ca 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.
2014-02-13 18:36:03 -05:00

24 lines
618 B
Ruby

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