Tôi đang khỉ vá Capybara :: Phiên với phương thức set_headers gán cho Capybara :: RackTest :: thuộc tính tùy chọn của trình duyệt (mà tôi đã thay đổi từ attr_reader thành attr_accessor).Cách tốt nhất để đặt tiêu đề yêu cầu tùy chỉnh khi sử dụng Capybara trong thông số yêu cầu RSpec là gì?
Các bản vá lỗi:
class Capybara::RackTest::Browser
attr_accessor :options
end
class Capybara::Session
def set_headers(headers)
if driver.browser.respond_to?(:options=) #because we've monkey patched it above
options = driver.browser.options
if options.nil? || options[:headers].nil?
options ||= {}
options[:headers] = headers
else
options[:headers].merge!(headers)
end
else
raise Capybara::NotSupportedByDriverError
end
end
end
Trong yêu cầu spec của tôi, tôi đang làm:
page.set_headers("REMOTE_ADDR" => "1.2.3.4")
visit root_path
này hoạt động, nhưng tôi đang tự hỏi nếu có một cách tốt hơn, nó có vẻ hơi quá mức để chỉ có thể đặt remote_ip/remote_addr tùy chỉnh theo yêu cầu. Có suy nghĩ gì không?