Sha256: 65fcf08f221eb17264b9e7b6b9ac58b638d14695f4b59b8101148d7e7c70dd9c
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 KB
Contents
require "rspec/core" require "forwardable" require "logger" module RSpec::Httpd::Expectation def do_expect_last_request(expected:, client:) actual = client.result ctx = { request: client.request, actual: actual, expected: expected } case expected when Regexp then expect(actual).to match(expected), -> { format_failure SHOULD_MATCH_ERROR, ctx } when Hash then expect(actual).to include(expected), -> { format_failure SHOULD_INCLUDE_ERROR, ctx } else expect(actual).to eq(expected), -> { format_failure SHOULD_EQUAL_ERROR, ctx } end end SHOULD_MATCH_ERROR = "%request -- %actual should match %expected".freeze SHOULD_INCLUDE_ERROR = "%request -- %actual should include %expected".freeze SHOULD_EQUAL_ERROR = "%request -- %actual should equal %expected".freeze private def format_failure(format, ctx) format.gsub(/\%(\S+)/) do value = ctx.fetch(Regexp.last_match(1).to_sym) case value when Net::HTTPGenericRequest request = value s = "#{request.method} #{request.path}" s += " body:#{request.body.inspect}" if request.body s else value.inspect end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rspec-httpd-0.0.8 | lib/rspec/httpd/expectation.rb |
rspec-httpd-0.0.7 | lib/rspec/httpd/expectation.rb |
rspec-httpd-0.0.5 | lib/rspec/httpd/expectation.rb |