Sha256: b640a5adac8a92385e3b99ac93baf8375b4382b2e22b3699dda9e512c3a69cb7
Contents?: true
Size: 1.54 KB
Versions: 12
Compression:
Stored size: 1.54 KB
Contents
# encoding: utf-8 RSpec::Matchers.define :have_requests_with_status_code do |expected| match do |actual| domains_eq? actual, expected end failure_message_for_should do |actual| expected_domains = format_domains(expected) actual_domains = format_domains(extract_domains(actual)) "expected that \"#{actual.current_url}\" references with the given http status codes:\n#{expected_domains}\n\nBut it references with the given http status codes:\n#{actual_domains}\n" end failure_message_for_should_not do |actual| expected_domains = format_domains(expected) actual_domains = format_domains(extract_domains(actual)) "expected that \"#{actual.current_url}\" not references domains with the given http status codes:\n#{expected_domains}\n\nBut it references with the given http status codes:\n#{actual_domains}\n" end description do "to reference domains with the given http status codes:\n#{format_domains(expected)}" end def domains_eq?(actual, expected) actual_domains = extract_domains(actual) expected.all? { |key, value| Array(actual_domains[key]) == Array(value) } end def extract_domains(page) page.driver.network_traffic.reduce({}) { |memo, o| memo[Addressable::URI.parse(o.url).host] = get_status_codes(o.response_parts); memo} end def format_domains(domains) domains.collect { |key, value| format "* %s (%s)", key, Array(value).collect { |s| "\"#{s}\""}.join(', ')}.join("\n") end def get_status_codes(response_parts) response_parts.collect { |rp| rp.status }.uniq end end
Version data entries
12 entries across 12 versions & 1 rubygems