module HttpHeadersValidations
Public Class Methods
assert_expected_header(expected_header, expected_value, actual_value)
click to toggle source
# File lib/http_headers_validations.rb, line 11 def self.assert_expected_header(expected_header, expected_value, actual_value) if (!actual_value.nil? && expected_value.is_a?(Regexp) && actual_value.match?(expected_value)) || (expected_value.to_s == actual_value.to_s) failed = false text = "Expected Header '#{expected_header}' matched!" else failed = true text = "Expected Header '#{HttpHeadersUtils.bold(expected_header)}' failed! '#{expected_value}' #{HttpHeadersUtils.bold('was')} '#{actual_value}'." end icon = failed ? "🛑" : "🍏" report(text, failed, icon) return text if failed end
assert_extra_header(actual_header, actual_value, ignored_headers, avoid_headers)
click to toggle source
# File lib/http_headers_validations.rb, line 27 def self.assert_extra_header(actual_header, actual_value, ignored_headers, avoid_headers) if avoid_headers.include? actual_header.downcase icon = "🛑" failed = true text = "Extra Header '#{actual_header}' is not allowed!" elsif ignored_headers.include? actual_header.downcase icon = "🍏" failed = false text = "Extra Header '#{actual_header}' marked for ignore!" else icon = "⚠️" failed = false text = "Warning: Extra Header '#{HttpHeadersUtils.bold(actual_header)}' with value '#{actual_value}' was unexpected." end report(text, failed, icon) return text if failed end
report(text, failed, icon)
click to toggle source
# File lib/http_headers_validations.rb, line 5 def self.report(text, failed, icon) if failed || HttpHeadersUtils.verbose puts "\t#{icon} #{text}" end end