Sha256: 34494dff72cbcd70a4cd74e6ce824ffb3a821b3d8808fe75be3ba113506e5286
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
require "rspec/request_describer/version" module RSpec module RequestDescriber RESERVED_HEADER_NAMES = %w( Content-Type Host HTTPS ) SUPPORTED_METHODS = %w( GET POST PUT PATCH DELETE ) def self.included(base) base.instance_eval do subject do send_request end let(:send_request) do send http_method, path, request_body, env end let(:request_body) do if headers.any? { |key, value| key.downcase == "content-type" && value == "application/json" } params.to_json else params end end let(:headers) do {} end let(:params) do {} end let(:env) do headers.inject({}) do |result, (key, value)| key = "HTTP_" + key unless RESERVED_HEADER_NAMES.include?(key) key = key.gsub("-", "_").upcase result.merge(key => value) end end let(:endpoint_segments) do current_example = RSpec.respond_to?(:current_example) ? RSpec.current_example : example current_example.full_description.match(/(#{SUPPORTED_METHODS.join("|")}) (\S+)/).to_a end let(:http_method) do endpoint_segments[1].downcase end let(:path) do endpoint_segments[2].gsub(/:(\w+[!?=]?)/) { send($1) } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rspec-request_describer-0.1.0 | lib/rspec/request_describer.rb |