ultra-pure-gem 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/ultra-pure-gem.gemspec +12 -0
  3. data/webmock-3.26.2/CHANGELOG.md +2148 -0
  4. data/webmock-3.26.2/LICENSE +20 -0
  5. data/webmock-3.26.2/README.md +1229 -0
  6. data/webmock-3.26.2/lib/webmock/api.rb +111 -0
  7. data/webmock-3.26.2/lib/webmock/assertion_failure.rb +13 -0
  8. data/webmock-3.26.2/lib/webmock/callback_registry.rb +37 -0
  9. data/webmock-3.26.2/lib/webmock/config.rb +20 -0
  10. data/webmock-3.26.2/lib/webmock/cucumber.rb +12 -0
  11. data/webmock-3.26.2/lib/webmock/deprecation.rb +11 -0
  12. data/webmock-3.26.2/lib/webmock/errors.rb +19 -0
  13. data/webmock-3.26.2/lib/webmock/http_lib_adapters/async_http_client_adapter.rb +228 -0
  14. data/webmock-3.26.2/lib/webmock/http_lib_adapters/curb_adapter.rb +354 -0
  15. data/webmock-3.26.2/lib/webmock/http_lib_adapters/em_http_request_adapter.rb +239 -0
  16. data/webmock-3.26.2/lib/webmock/http_lib_adapters/excon_adapter.rb +167 -0
  17. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter.rb +9 -0
  18. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_lib_adapter_registry.rb +21 -0
  19. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/client.rb +17 -0
  20. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/request.rb +28 -0
  21. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/response.rb +95 -0
  22. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/streamer.rb +44 -0
  23. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb/webmock.rb +77 -0
  24. data/webmock-3.26.2/lib/webmock/http_lib_adapters/http_rb_adapter.rb +39 -0
  25. data/webmock-3.26.2/lib/webmock/http_lib_adapters/httpclient_adapter.rb +260 -0
  26. data/webmock-3.26.2/lib/webmock/http_lib_adapters/manticore_adapter.rb +147 -0
  27. data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http.rb +310 -0
  28. data/webmock-3.26.2/lib/webmock/http_lib_adapters/net_http_response.rb +36 -0
  29. data/webmock-3.26.2/lib/webmock/http_lib_adapters/patron_adapter.rb +132 -0
  30. data/webmock-3.26.2/lib/webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +190 -0
  31. data/webmock-3.26.2/lib/webmock/matchers/any_arg_matcher.rb +15 -0
  32. data/webmock-3.26.2/lib/webmock/matchers/hash_argument_matcher.rb +23 -0
  33. data/webmock-3.26.2/lib/webmock/matchers/hash_excluding_matcher.rb +17 -0
  34. data/webmock-3.26.2/lib/webmock/matchers/hash_including_matcher.rb +19 -0
  35. data/webmock-3.26.2/lib/webmock/minitest.rb +43 -0
  36. data/webmock-3.26.2/lib/webmock/rack_response.rb +73 -0
  37. data/webmock-3.26.2/lib/webmock/request_body_diff.rb +66 -0
  38. data/webmock-3.26.2/lib/webmock/request_execution_verifier.rb +79 -0
  39. data/webmock-3.26.2/lib/webmock/request_pattern.rb +428 -0
  40. data/webmock-3.26.2/lib/webmock/request_registry.rb +37 -0
  41. data/webmock-3.26.2/lib/webmock/request_signature.rb +56 -0
  42. data/webmock-3.26.2/lib/webmock/request_signature_snippet.rb +63 -0
  43. data/webmock-3.26.2/lib/webmock/request_stub.rb +134 -0
  44. data/webmock-3.26.2/lib/webmock/response.rb +161 -0
  45. data/webmock-3.26.2/lib/webmock/responses_sequence.rb +42 -0
  46. data/webmock-3.26.2/lib/webmock/rspec/matchers/request_pattern_matcher.rb +80 -0
  47. data/webmock-3.26.2/lib/webmock/rspec/matchers/webmock_matcher.rb +69 -0
  48. data/webmock-3.26.2/lib/webmock/rspec/matchers.rb +29 -0
  49. data/webmock-3.26.2/lib/webmock/rspec.rb +44 -0
  50. data/webmock-3.26.2/lib/webmock/stub_registry.rb +84 -0
  51. data/webmock-3.26.2/lib/webmock/stub_request_snippet.rb +40 -0
  52. data/webmock-3.26.2/lib/webmock/test_unit.rb +22 -0
  53. data/webmock-3.26.2/lib/webmock/util/hash_counter.rb +45 -0
  54. data/webmock-3.26.2/lib/webmock/util/hash_keys_stringifier.rb +27 -0
  55. data/webmock-3.26.2/lib/webmock/util/hash_validator.rb +19 -0
  56. data/webmock-3.26.2/lib/webmock/util/headers.rb +77 -0
  57. data/webmock-3.26.2/lib/webmock/util/parsers/json.rb +72 -0
  58. data/webmock-3.26.2/lib/webmock/util/parsers/parse_error.rb +7 -0
  59. data/webmock-3.26.2/lib/webmock/util/parsers/xml.rb +16 -0
  60. data/webmock-3.26.2/lib/webmock/util/query_mapper.rb +283 -0
  61. data/webmock-3.26.2/lib/webmock/util/uri.rb +113 -0
  62. data/webmock-3.26.2/lib/webmock/util/values_stringifier.rb +22 -0
  63. data/webmock-3.26.2/lib/webmock/util/version_checker.rb +113 -0
  64. data/webmock-3.26.2/lib/webmock/version.rb +5 -0
  65. data/webmock-3.26.2/lib/webmock/webmock.rb +175 -0
  66. data/webmock-3.26.2/lib/webmock.rb +61 -0
  67. metadata +106 -0
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ module Matchers
5
+ # this is a based on RSpec::Mocks::ArgumentMatchers::HashExcludingMatcher
6
+ # https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
7
+ class HashExcludingMatcher < HashArgumentMatcher
8
+ def ==(actual)
9
+ super { |key, value| !actual.key?(key) || value != actual[key] }
10
+ end
11
+
12
+ def inspect
13
+ "hash_excluding(#{@expected.inspect})"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ module Matchers
5
+ # this is a based on RSpec::Mocks::ArgumentMatchers::HashIncludingMatcher
6
+ # https://github.com/rspec/rspec-mocks/blob/master/lib/rspec/mocks/argument_matchers.rb
7
+ class HashIncludingMatcher < HashArgumentMatcher
8
+ def ==(actual)
9
+ super { |key, value| actual.key?(key) && value === actual[key] }
10
+ rescue NoMethodError
11
+ false
12
+ end
13
+
14
+ def inspect
15
+ "hash_including(#{@expected.inspect})"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require 'minitest/test'
5
+ test_class = Minitest::Test
6
+ assertions = "assertions"
7
+ rescue LoadError
8
+ require "minitest/unit"
9
+ test_class = MiniTest::Unit::TestCase
10
+ assertions = "_assertions"
11
+ end
12
+
13
+ require 'webmock'
14
+
15
+ WebMock.enable!
16
+
17
+ test_class.class_eval do
18
+ include WebMock::API
19
+
20
+ alias_method :teardown_without_webmock, :teardown
21
+ def teardown_with_webmock
22
+ teardown_without_webmock
23
+ WebMock.reset!
24
+ end
25
+ alias_method :teardown, :teardown_with_webmock
26
+
27
+ [:assert_request_requested, :assert_request_not_requested].each do |name|
28
+ alias_method :"#{name}_without_assertions_count", name
29
+ define_method :"#{name}_with_assertions_count" do |*args|
30
+ self.send("#{assertions}=", self.send("#{assertions}") + 1)
31
+ send :"#{name}_without_assertions_count", *args
32
+ end
33
+ alias_method name, :"#{name}_with_assertions_count"
34
+ end
35
+ end
36
+
37
+ begin
38
+ error_class = MiniTest::Assertion
39
+ rescue NameError
40
+ error_class = Minitest::Assertion
41
+ end
42
+
43
+ WebMock::AssertionFailure.error_class = error_class
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ class RackResponse < Response
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def evaluate(request)
10
+ env = build_rack_env(request)
11
+
12
+ status, headers, response = @app.call(env)
13
+
14
+ Response.new(
15
+ body: body_from_rack_response(response),
16
+ headers: headers,
17
+ status: [status, Rack::Utils::HTTP_STATUS_CODES[status]]
18
+ )
19
+ end
20
+
21
+ def body_from_rack_response(response)
22
+ body = "".dup
23
+ response.each { |line| body << line }
24
+ response.close if response.respond_to?(:close)
25
+ return body
26
+ end
27
+
28
+ def build_rack_env(request)
29
+ uri = request.uri
30
+ headers = (request.headers || {}).dup
31
+ body = request.body || ''
32
+
33
+ env = {
34
+ # CGI variables specified by Rack
35
+ 'REQUEST_METHOD' => request.method.to_s.upcase,
36
+ 'CONTENT_TYPE' => headers.delete('Content-Type'),
37
+ 'CONTENT_LENGTH' => body.bytesize,
38
+ 'PATH_INFO' => uri.path,
39
+ 'QUERY_STRING' => uri.query || '',
40
+ 'SERVER_NAME' => uri.host,
41
+ 'SERVER_PORT' => uri.port,
42
+ 'SCRIPT_NAME' => ""
43
+ }
44
+
45
+ env['HTTP_AUTHORIZATION'] = 'Basic ' + [uri.userinfo].pack('m').delete("\r\n") if uri.userinfo
46
+
47
+ # Rack-specific variables
48
+ env['rack.input'] = StringIO.new(body)
49
+ env['rack.errors'] = $stderr
50
+ if !Rack.const_defined?(:RELEASE) || Rack::RELEASE < "3"
51
+ env['rack.version'] = Rack::VERSION
52
+ end
53
+ env['rack.url_scheme'] = uri.scheme
54
+ env['rack.run_once'] = true
55
+ env['rack.session'] = session
56
+ env['rack.session.options'] = session_options
57
+
58
+ headers.each do |k, v|
59
+ env["HTTP_#{k.tr('-','_').upcase}"] = v
60
+ end
61
+
62
+ env
63
+ end
64
+
65
+ def session
66
+ @session ||= {}
67
+ end
68
+
69
+ def session_options
70
+ @session_options ||= {}
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hashdiff"
4
+ require "json"
5
+
6
+ module WebMock
7
+ class RequestBodyDiff
8
+
9
+ def initialize(request_signature, request_stub)
10
+ @request_signature = request_signature
11
+ @request_stub = request_stub
12
+ end
13
+
14
+ def body_diff
15
+ return {} unless request_signature_diffable? && request_stub_diffable?
16
+
17
+ Hashdiff.diff(request_signature_body_hash, request_stub_body_hash)
18
+ end
19
+
20
+ attr_reader :request_signature, :request_stub
21
+ private :request_signature, :request_stub
22
+
23
+ private
24
+
25
+ def request_signature_diffable?
26
+ request_signature.json_headers? && request_signature_parseable_json?
27
+ end
28
+
29
+ def request_stub_diffable?
30
+ request_stub_body.is_a?(Hash) || request_stub_parseable_json?
31
+ end
32
+
33
+ def request_signature_body_hash
34
+ JSON.parse(request_signature.body)
35
+ end
36
+
37
+ def request_stub_body_hash
38
+ return request_stub_body if request_stub_body.is_a?(Hash)
39
+
40
+ JSON.parse(request_stub_body)
41
+ end
42
+
43
+ def request_stub_body
44
+ request_stub.request_pattern &&
45
+ request_stub.request_pattern.body_pattern &&
46
+ request_stub.request_pattern.body_pattern.pattern
47
+ end
48
+
49
+ def request_signature_parseable_json?
50
+ parseable_json?(request_signature.body)
51
+ end
52
+
53
+ def request_stub_parseable_json?
54
+ parseable_json?(request_stub_body)
55
+ end
56
+
57
+ def parseable_json?(body_pattern)
58
+ return false unless body_pattern.is_a?(String)
59
+
60
+ JSON.parse(body_pattern)
61
+ true
62
+ rescue JSON::ParserError
63
+ false
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebMock
4
+ class RequestExecutionVerifier
5
+
6
+ attr_accessor :request_pattern, :expected_times_executed, :times_executed, :at_least_times_executed, :at_most_times_executed
7
+
8
+ def initialize(request_pattern = nil, expected_times_executed = nil, at_least_times_executed = nil, at_most_times_executed = nil)
9
+ @request_pattern = request_pattern
10
+ @expected_times_executed = expected_times_executed
11
+ @at_least_times_executed = at_least_times_executed
12
+ @at_most_times_executed = at_most_times_executed
13
+ end
14
+
15
+ def matches?
16
+ @times_executed =
17
+ RequestRegistry.instance.times_executed(@request_pattern)
18
+
19
+ if @at_least_times_executed
20
+ @times_executed >= @at_least_times_executed
21
+ elsif @at_most_times_executed
22
+ @times_executed <= @at_most_times_executed
23
+ else
24
+ @times_executed == (@expected_times_executed || 1)
25
+ end
26
+ end
27
+
28
+ def does_not_match?
29
+ @times_executed =
30
+ RequestRegistry.instance.times_executed(@request_pattern)
31
+ if @expected_times_executed
32
+ @times_executed != @expected_times_executed
33
+ else
34
+ @times_executed == 0
35
+ end
36
+ end
37
+
38
+ def description
39
+ "request #{request_pattern} #{quantity_phrase.strip}"
40
+ end
41
+
42
+ def failure_message
43
+ failure_message_phrase(false)
44
+ end
45
+
46
+ def failure_message_when_negated
47
+ failure_message_phrase(true)
48
+ end
49
+
50
+ def self.executed_requests_message
51
+ "\n\nThe following requests were made:\n\n#{RequestRegistry.instance}\n" + "="*60
52
+ end
53
+
54
+ private
55
+
56
+ def failure_message_phrase(is_negated=false)
57
+ negation = is_negated ? "was not" : "was"
58
+ "The request #{request_pattern} #{negation} expected to execute #{quantity_phrase(is_negated)}but it executed #{times(times_executed)}" +
59
+ self.class.executed_requests_message
60
+ end
61
+
62
+ def quantity_phrase(is_negated=false)
63
+ if @at_least_times_executed
64
+ "at least #{times(@at_least_times_executed)} "
65
+ elsif @at_most_times_executed
66
+ "at most #{times(@at_most_times_executed)} "
67
+ elsif @expected_times_executed
68
+ "#{times(@expected_times_executed)} "
69
+ else
70
+ is_negated ? "" : "#{times(1)} "
71
+ end
72
+ end
73
+
74
+ def times(times)
75
+ "#{times} time#{ (times == 1) ? '' : 's'}"
76
+ end
77
+
78
+ end
79
+ end