Sha256: 1050a90ca8bfeffff8e47d481996ead42a7ab878597d9759ecba856c96e65108
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
# frozen_string_literal: true require 'rspec/matchers' require 'rspec/webservice_matchers/util' require 'validated_object' # Pass when the response code is 200, following redirects if necessary. module RSpec module WebserviceMatchers module BeUp class TestResult < ValidatedObject::Base attr_accessor :success, :status_code alias success? success validates :success, inclusion: [true, false] validates :status_code, inclusion: 100..510 end def self.test(url:nil, domain:nil) raise 'Must specify a url or domain' if url.nil? && domain.nil? TestResult.new do |r| r.status_code = Util.status(url || domain, follow: true) r.success = (r.status_code == 200) end end RSpec::Matchers.define :be_up do status = nil match do |url_or_domain_name| result = BeUp.test(url: url_or_domain_name) status = result.status_code result.success? end failure_message do "Received status #{status}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rspec-webservice_matchers-4.9.0 | lib/rspec/webservice_matchers/be_up.rb |