module Asserter class Url attr_accessor :check_protocol attr_accessor :check_host attr_accessor :check_port attr_accessor :check_uri attr_accessor :check_response_string def assert_url_response_of(_options = {}) Helper.validates_presence_of check_protocol, 'check_protocol not set' Helper.validates_presence_of check_host, 'check_host not set' Helper.validates_presence_of check_port, 'check_port not set' Helper.validates_presence_of check_uri, 'check_uri not set' Helper.validates_presence_of check_response_string, 'check_response_string not set' check_url = "#{check_protocol}://#{check_host}:#{check_port}#{check_uri}" $log.writer.info "Checking URL = #{check_url} for \"#{check_response_string}\"" # Net::HTTP.start(check_host, Integer(check_port)) do |http| port = Integer(check_port) Net::HTTP.start(check_host, port) do |http| request = Net::HTTP::Get.new check_uri response = http.request request # Net::HTTPResponse object $log.writer.debug "ResponseCode: #{response.code}" $log.writer.debug "ResponseMessage: #{response.message}" $log.writer.debug "ResponseBody: #{response.body}" unless response.code == '200' $log.writer.error "Got response code: #{response.code}" exit 1 end unless response.body =~ Regexp.new(check_response_string) $log.writer.error "Expected: #{check_response_string}" $log.writer.error "Got: #{response.body}" exit 1 end end end end end