How to use initialize method of WebMock.Matchers Package

Best Webmock_ruby code snippet using WebMock.Matchers.initialize

webmock.rbi

Source:webmock.rbi Github

copy

Full Screen

...45class WebMock::Deprecation46 def self.warning(message); end47end48class WebMock::NetConnectNotAllowedError < Exception49 def initialize(request_signature); end50end51module WebMock::Util52end53class WebMock::Util::QueryMapper54 def self.collect_query_hash(query_array, empty_accumulator, options); end55 def self.collect_query_parts(query); end56 def self.dehash(hash); end57 def self.fill_accumulator_for_dot(accumulator, key, value); end58 def self.fill_accumulator_for_flat(accumulator, key, value); end59 def self.fill_accumulator_for_flat_array(accumulator, key, value); end60 def self.fill_accumulator_for_subscript(accumulator, key, value); end61 def self.normalize_query_hash(query_hash, empty_accumulator, options); end62 def self.query_to_values(query, options = nil); end63 def self.to_query(parent, value, options = nil); end64 def self.values_to_query(new_query_values, options = nil); end65end66class WebMock::Util::URI67 def self.encode_unsafe_chars_in_userinfo(userinfo); end68 def self.heuristic_parse(uri); end69 def self.is_uri_localhost?(uri); end70 def self.normalize_uri(uri); end71 def self.sort_query_values(query_values); end72 def self.strip_default_port_from_uri_string(uri_string); end73 def self.uris_encoded_and_unencoded(uris); end74 def self.uris_with_inferred_port_and_without(uris); end75 def self.uris_with_scheme_and_without(uris); end76 def self.uris_with_trailing_slash_and_without(uris); end77 def self.variations_of_uri_as_strings(uri_object, only_with_scheme: nil); end78end79module WebMock::Util::URI::CharacterClasses80end81class WebMock::Util::Headers82 def self.basic_auth_header(*credentials); end83 def self.decode_userinfo_from_header(header); end84 def self.normalize_headers(headers); end85 def self.pp_headers_string(headers); end86 def self.sorted_headers_string(headers); end87end88class WebMock::Util::HashCounter89 def each(&block); end90 def get(key); end91 def hash; end92 def hash=(arg0); end93 def initialize; end94 def put(key, num = nil); end95 def select(&block); end96end97class WebMock::Util::HashKeysStringifier98 def self.stringify_keys!(arg, options = nil); end99end100class WebMock::Util::ValuesStringifier101 def self.stringify_values(value); end102end103class WebMock::Util::JSON104 def self.convert_json_to_yaml(json); end105 def self.parse(json); end106 def self.unescape(str); end107end108class WebMock::Util::JSON::ParseError < StandardError109end110class WebMock::VersionChecker111 def check_version!; end112 def colorize(text, color_code); end113 def compare_version; end114 def initialize(library_name, library_version, min_patch_level, max_minor_version = nil, unsupported_versions = nil); end115 def parse_version(version); end116 def too_high?; end117 def too_low?; end118 def unsupported_version?; end119 def version_requirement; end120 def warn_about_too_high; end121 def warn_about_too_low; end122 def warn_about_unsupported_version; end123 def warn_in_red(text); end124end125class WebMock::HashValidator126 def initialize(hash); end127 def validate_keys(*valid_keys); end128end129module WebMock::Matchers130 def have_been_made; end131 def have_been_requested; end132 def have_not_been_made; end133 def have_not_requested(method, uri); end134 def have_requested(method, uri); end135end136class WebMock::Matchers::HashArgumentMatcher137 def ==(_actual, &block); end138 def initialize(expected); end139 def self.from_rspec_matcher(matcher); end140end141class WebMock::Matchers::HashExcludingMatcher < WebMock::Matchers::HashArgumentMatcher142 def ==(actual); end143 def inspect; end144end145class WebMock::Matchers::HashIncludingMatcher < WebMock::Matchers::HashArgumentMatcher146 def ==(actual); end147 def inspect; end148end149class WebMock::Matchers::AnyArgMatcher150 def ==(other); end151 def initialize(ignore); end152end153module WebMock::RSpecMatcherDetector154 def rSpecHashExcludingMatcher?(matcher); end155 def rSpecHashIncludingMatcher?(matcher); end156end157class WebMock::RequestPattern158 def assign_options(options); end159 def body_pattern; end160 def create_uri_pattern(uri); end161 def headers_pattern; end162 def initialize(method, uri, options = nil); end163 def matches?(request_signature); end164 def method_pattern; end165 def set_basic_auth_as_headers!(options); end166 def to_s; end167 def uri_pattern; end168 def validate_basic_auth!(basic_auth); end169 def with(options = nil, &block); end170end171class WebMock::MethodPattern172 def initialize(pattern); end173 def matches?(method); end174 def to_s; end175end176class WebMock::URIPattern177 def add_query_params(query_params); end178 def initialize(pattern); end179 def matches?(uri); end180 def pattern_inspect; end181 def query_params_matches?(uri); end182 def to_s; end183 include WebMock::RSpecMatcherDetector184end185class WebMock::URICallablePattern < WebMock::URIPattern186 def pattern_matches?(uri); end187end188class WebMock::URIRegexpPattern < WebMock::URIPattern189 def pattern_matches?(uri); end190end191class WebMock::URIAddressablePattern < WebMock::URIPattern192 def add_query_params(query_params); end193 def matches_with_variations?(uri); end194 def pattern_inspect; end195 def pattern_matches?(uri); end196 def template_matches_uri?(template, uri); end197end198class WebMock::URIStringPattern < WebMock::URIPattern199 def add_query_params(query_params); end200 def pattern_inspect; end201 def pattern_matches?(uri); end202end203class WebMock::BodyPattern204 def assert_non_multipart_body(content_type); end205 def body_as_hash(body, content_type); end206 def body_format(content_type); end207 def empty_string?(string); end208 def initialize(pattern); end209 def matches?(body, content_type = nil); end210 def matching_body_hashes?(query_parameters, pattern, content_type); end211 def normalize_hash(hash); end212 def pattern; end213 def to_s; end214 def url_encoded_body?(content_type); end215 include WebMock::RSpecMatcherDetector216end217class WebMock::HeadersPattern218 def empty_headers?(headers); end219 def initialize(pattern); end220 def matches?(headers); end221 def pp_to_s; end222 def to_s; end223end224class WebMock::RequestSignature225 def ==(other); end226 def assign_options(options); end227 def body; end228 def body=(arg0); end229 def eql?(other); end230 def hash; end231 def headers; end232 def headers=(headers); end233 def initialize(method, uri, options = nil); end234 def json_headers?; end235 def method; end236 def method=(arg0); end237 def to_s; end238 def uri; end239 def uri=(arg0); end240 def url_encoded?; end241end242class WebMock::ResponsesSequence243 def end?; end244 def increase_position; end245 def initialize(responses); end246 def next_response; end247 def times_to_repeat; end248 def times_to_repeat=(arg0); end249end250class WebMock::RequestStub251 def and_raise(*exceptions); end252 def and_return(*response_hashes, &block); end253 def and_timeout; end254 def has_responses?; end255 def initialize(method, uri); end256 def matches?(request_signature); end257 def request_pattern; end258 def request_pattern=(arg0); end259 def response; end260 def self.from_request_signature(signature); end261 def then; end262 def times(number); end263 def to_rack(app, options = nil); end264 def to_raise(*exceptions); end265 def to_return(*response_hashes, &block); end266 def to_s; end267 def to_timeout; end268 def with(params = nil, &block); end269end270class WebMock::ResponseFactory271 def self.response_for(options); end272end273class WebMock::Response274 def ==(other); end275 def assert_valid_body!; end276 def body; end277 def body=(body); end278 def evaluate(request_signature); end279 def exception; end280 def exception=(exception); end281 def headers; end282 def headers=(headers); end283 def initialize(options = nil); end284 def options=(options); end285 def raise_error_if_any; end286 def read_raw_response(raw_response); end287 def should_timeout; end288 def status; end289 def status=(status); end290 def stringify_body!; end291end292class WebMock::Response::InvalidBody < StandardError293end294class WebMock::DynamicResponse < WebMock::Response295 def evaluate(request_signature); end296 def initialize(responder); end297 def responder; end298 def responder=(arg0); end299end300class WebMock::RackResponse < WebMock::Response301 def body_from_rack_response(response); end302 def build_rack_env(request); end303 def evaluate(request); end304 def initialize(app); end305 def session; end306 def session_options; end307end308class WebMock::StubRequestSnippet309 def body_pattern; end310 def initialize(request_stub); end311 def to_s(with_response = nil); end312end313class WebMock::RequestSignatureSnippet314 def add_body_diff(stub, text); end315 def initialize(request_signature); end316 def pretty_print_to_string(string_to_print); end317 def request_params; end318 def request_signature; end319 def request_stub; end320 def request_stubs; end321 def signature_stub_body_diff(stub); end322 def stubbing_instructions; end323end324class WebMock::RequestBodyDiff325 def body_diff; end326 def initialize(request_signature, request_stub); end327 def parseable_json?(body_pattern); end328 def request_signature; end329 def request_signature_body_hash; end330 def request_signature_diffable?; end331 def request_signature_parseable_json?; end332 def request_stub; end333 def request_stub_body; end334 def request_stub_body_hash; end335 def request_stub_diffable?; end336 def request_stub_parseable_json?; end337end338class WebMock::AssertionFailure339 def self.error_class; end340 def self.error_class=(arg0); end341 def self.failure(message); end342end343class WebMock::RequestExecutionVerifier344 def at_least_times_executed; end345 def at_least_times_executed=(arg0); end346 def at_most_times_executed; end347 def at_most_times_executed=(arg0); end348 def description; end349 def does_not_match?; end350 def expected_times_executed; end351 def expected_times_executed=(arg0); end352 def failure_message; end353 def failure_message_phrase(is_negated = nil); end354 def failure_message_when_negated; end355 def initialize(request_pattern = nil, expected_times_executed = nil, at_least_times_executed = nil, at_most_times_executed = nil); end356 def matches?; end357 def quantity_phrase(is_negated = nil); end358 def request_pattern; end359 def request_pattern=(arg0); end360 def self.executed_requests_message; end361 def times(times); end362 def times_executed; end363 def times_executed=(arg0); end364end365class WebMock::Config366 def allow; end367 def allow=(arg0); end368 def allow_localhost; end369 def allow_localhost=(arg0); end370 def allow_net_connect; end371 def allow_net_connect=(arg0); end372 def initialize; end373 def net_http_connect_on_start; end374 def net_http_connect_on_start=(arg0); end375 def query_values_notation; end376 def query_values_notation=(arg0); end377 def self.allocate; end378 def self.new(*arg0); end379 def show_body_diff; end380 def show_body_diff=(arg0); end381 def show_stubbing_instructions; end382 def show_stubbing_instructions=(arg0); end383 extend Singleton::SingletonClassMethods384 include Singleton385end386class WebMock::CallbackRegistry387 def self.add_callback(options, block); end388 def self.any_callbacks?; end389 def self.callbacks; end390 def self.invoke_callbacks(options, request_signature, response); end391 def self.reset; end392end393class WebMock::RequestRegistry394 def initialize; end395 def requested_signatures; end396 def requested_signatures=(arg0); end397 def reset!; end398 def self.allocate; end399 def self.new(*arg0); end400 def times_executed(request_pattern); end401 def to_s; end402 extend Singleton::SingletonClassMethods403 include Singleton404end405class WebMock::StubRegistry406 def evaluate_response_for_request(response, request_signature); end407 def global_stubs; end408 def initialize; end409 def register_global_stub(order = nil, &block); end410 def register_request_stub(stub); end411 def registered_request?(request_signature); end412 def remove_request_stub(stub); end413 def request_stub_for(request_signature); end414 def request_stubs; end415 def request_stubs=(arg0); end416 def reset!; end417 def response_for_request(request_signature); end418 def self.allocate; end419 def self.new(*arg0); end420 extend Singleton::SingletonClassMethods421 include Singleton422end423module WebMock::API424 def a_request(method, uri); end425 def anythingize_lonely_keys(*args); end426 def assert_not_requested(*args, &block); end427 def assert_request_not_requested(request, options = nil); end428 def assert_request_requested(request, options = nil); end429 def assert_requested(*args, &block); end430 def convert_uri_method_and_options_to_request_and_options(method, uri, options, &block); end431 def hash_excluding(*args); end432 def hash_including(*args); end433 def refute_requested(*args, &block); end434 def remove_request_stub(stub); end435 def reset_executed_requests!; end436 def self.request(method, uri); end437 def stub_http_request(method, uri); end438 def stub_request(*args); end439 extend WebMock::API440end441class WebMock::HttpLibAdapterRegistry442 def each_adapter(&block); end443 def http_lib_adapters; end444 def http_lib_adapters=(arg0); end445 def initialize; end446 def register(lib, adapter); end447 def self.allocate; end448 def self.new(*arg0); end449 extend Singleton::SingletonClassMethods450 include Singleton451end452class WebMock::HttpLibAdapter453 def self.adapter_for(lib); end454end455module Net456end457module Net::WebMockHTTPResponse458 def read_body(dest = nil, &block); end459end460module WebMock::HttpLibAdapters461end462class WebMock::HttpLibAdapters::NetHttpAdapter < WebMock::HttpLibAdapter463 def self.disable!; end464 def self.enable!; end465end466class PatchedStringIO < StringIO467 def orig_read_nonblock(*arg0); end468 def read_nonblock(size, *args, **kwargs); end469end470class StubSocket471 def close; end472 def closed?; end473 def continue_timeout; end474 def continue_timeout=(arg0); end475 def initialize(*args); end476 def io; end477 def read_timeout; end478 def read_timeout=(arg0); end479 def readuntil(*args); end480 def write_timeout; end481 def write_timeout=(arg0); end482end483class StubSocket::StubIO484 def setsockopt(*args); end485end486class Net::WebMockNetBufferedIO < Net::BufferedIO487 def initialize(io, *args, **kwargs); end488 def rbuf_fill; end489end490module WebMock::NetHTTPUtility491 def self.check_right_http_connection; end492 def self.get_uri(net_http, path); end493 def self.puts_warning_for_right_http_if_needed; end494 def self.request_signature_from_request(net_http, request, body = nil); end495 def self.validate_headers(headers); end496end497class WebMock::RequestPatternMatcher498 def at_least_once; end499 def at_least_times(times); end500 def at_least_twice; end501 def at_most_once; end502 def at_most_times(times); end503 def at_most_twice; end504 def description; end505 def does_not_match?(request_pattern); end506 def failure_message; end507 def failure_message_when_negated; end508 def initialize; end509 def matches?(request_pattern); end510 def negative_failure_message; end511 def once; end512 def times(times); end513 def twice; end514end515class WebMock::WebMockMatcher516 def at_least_once; end517 def at_least_times(times); end518 def at_least_twice; end519 def description; end520 def does_not_match?(webmock); end521 def failure_message; end522 def failure_message_when_negated; end523 def initialize(method, uri); end524 def matches?(webmock); end525 def negative_failure_message; end526 def once; end527 def times(times); end528 def twice; end529 def with(options = nil, &block); end530end531class RSpec::ExampleGroups::WorkOSAuditTrail < RSpec::Core::ExampleGroup532 include WebMock::API533 include WebMock::Matchers534end535class RSpec::ExampleGroups::WorkOSBase < RSpec::Core::ExampleGroup536 include WebMock::API537 include WebMock::Matchers...

Full Screen

Full Screen

request_pattern.rb

Source:request_pattern.rb Github

copy

Full Screen

...8 end9 end10 class RequestPattern11 attr_reader :method_pattern, :uri_pattern, :body_pattern, :headers_pattern12 def initialize(method, uri, options = {})13 @method_pattern = MethodPattern.new(method)14 @uri_pattern = create_uri_pattern(uri)15 @body_pattern = nil16 @headers_pattern = nil17 @with_block = nil18 assign_options(options)19 end20 def with(options = {}, &block)21 raise ArgumentError.new('#with method invoked with no arguments. Either options hash or block must be specified.') if options.empty? && !block_given?22 assign_options(options)23 @with_block = block24 self25 end26 def matches?(request_signature)27 content_type = request_signature.headers['Content-Type'] if request_signature.headers28 content_type = content_type.split(';').first if content_type29 @method_pattern.matches?(request_signature.method) &&30 @uri_pattern.matches?(request_signature.uri) &&31 (@body_pattern.nil? || @body_pattern.matches?(request_signature.body, content_type || "")) &&32 (@headers_pattern.nil? || @headers_pattern.matches?(request_signature.headers)) &&33 (@with_block.nil? || @with_block.call(request_signature))34 end35 def to_s36 string = "#{@method_pattern.to_s.upcase}".dup37 string << " #{@uri_pattern.to_s}"38 string << " with body #{@body_pattern.to_s}" if @body_pattern39 string << " with headers #{@headers_pattern.to_s}" if @headers_pattern40 string << " with given block" if @with_block41 string42 end43 private44 def assign_options(options)45 options = WebMock::Util::HashKeysStringifier.stringify_keys!(options, deep: true)46 HashValidator.new(options).validate_keys('body', 'headers', 'query', 'basic_auth')47 set_basic_auth_as_headers!(options)48 @body_pattern = BodyPattern.new(options['body']) if options.has_key?('body')49 @headers_pattern = HeadersPattern.new(options['headers']) if options.has_key?('headers')50 @uri_pattern.add_query_params(options['query']) if options.has_key?('query')51 end52 def set_basic_auth_as_headers!(options)53 if basic_auth = options.delete('basic_auth')54 validate_basic_auth!(basic_auth)55 options['headers'] ||= {}56 options['headers']['Authorization'] = WebMock::Util::Headers.basic_auth_header(basic_auth[0],basic_auth[1])57 end58 end59 def validate_basic_auth!(basic_auth)60 if !basic_auth.is_a?(Array) || basic_auth.map{|e| e.is_a?(String)}.uniq != [true]61 raise "The basic_auth option value should be an array which contains 2 strings: username and password"62 end63 end64 def create_uri_pattern(uri)65 if uri.is_a?(Regexp)66 URIRegexpPattern.new(uri)67 elsif uri.is_a?(Addressable::Template)68 URIAddressablePattern.new(uri)69 else70 URIStringPattern.new(uri)71 end72 end73 end74 class MethodPattern75 def initialize(pattern)76 @pattern = pattern77 end78 def matches?(method)79 @pattern == method || @pattern == :any80 end81 def to_s82 @pattern.to_s83 end84 end85 class URIPattern86 include RSpecMatcherDetector87 def initialize(pattern)88 @pattern = case pattern89 when Addressable::URI, Addressable::Template90 pattern91 else92 WebMock::Util::URI.normalize_uri(pattern)93 end94 @query_params = nil95 end96 def add_query_params(query_params)97 @query_params = if query_params.is_a?(Hash)98 query_params99 elsif query_params.is_a?(WebMock::Matchers::HashIncludingMatcher) \100 || query_params.is_a?(WebMock::Matchers::HashExcludingMatcher)101 query_params102 elsif rSpecHashIncludingMatcher?(query_params)103 WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(query_params)104 elsif rSpecHashExcludingMatcher?(query_params)105 WebMock::Matchers::HashExcludingMatcher.from_rspec_matcher(query_params)106 else107 WebMock::Util::QueryMapper.query_to_values(query_params, notation: Config.instance.query_values_notation)108 end109 end110 def to_s111 str = @pattern.inspect112 str += " with query params #{@query_params.inspect}" if @query_params113 str114 end115 end116 class URIRegexpPattern < URIPattern117 def matches?(uri)118 WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| u.match(@pattern) } &&119 (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation))120 end121 def to_s122 str = @pattern.inspect123 str += " with query params #{@query_params.inspect}" if @query_params124 str125 end126 end127 class URIAddressablePattern < URIPattern128 def matches?(uri)129 if @query_params.nil?130 # Let Addressable check the whole URI131 WebMock::Util::URI.variations_of_uri_as_strings(uri).any? { |u| @pattern.match(u) }132 else133 # WebMock checks the query, Addressable checks everything else134 WebMock::Util::URI.variations_of_uri_as_strings(uri.omit(:query)).any? { |u| @pattern.match(u) } &&135 @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query)136 end137 end138 def add_query_params(query_params)139 @@add_query_params_warned ||= false140 if not @@add_query_params_warned141 @@add_query_params_warned = true142 warn "WebMock warning: ignoring query params in RFC 6570 template and checking them with WebMock"143 end144 super(query_params)145 end146 def to_s147 str = @pattern.pattern.inspect148 str += " with variables #{@pattern.variables.inspect}" if @pattern.variables149 str150 end151 end152 class URIStringPattern < URIPattern153 def matches?(uri)154 if @pattern.is_a?(Addressable::URI)155 if @query_params156 uri.omit(:query) === @pattern &&157 (@query_params.nil? || @query_params == WebMock::Util::QueryMapper.query_to_values(uri.query, notation: Config.instance.query_values_notation))158 else159 uri === @pattern160 end161 else162 false163 end164 end165 def add_query_params(query_params)166 super167 if @query_params.is_a?(Hash) || @query_params.is_a?(String)168 query_hash = (WebMock::Util::QueryMapper.query_to_values(@pattern.query, notation: Config.instance.query_values_notation) || {}).merge(@query_params)169 @pattern.query = WebMock::Util::QueryMapper.values_to_query(query_hash, notation: WebMock::Config.instance.query_values_notation)170 @query_params = nil171 end172 end173 def to_s174 str = WebMock::Util::URI.strip_default_port_from_uri_string(@pattern.to_s)175 str += " with query params #{@query_params.inspect}" if @query_params176 str177 end178 end179 class BodyPattern180 include RSpecMatcherDetector181 BODY_FORMATS = {182 'text/xml' => :xml,183 'application/xml' => :xml,184 'application/json' => :json,185 'text/json' => :json,186 'application/javascript' => :json,187 'text/javascript' => :json,188 'text/html' => :html,189 'application/x-yaml' => :yaml,190 'text/yaml' => :yaml,191 'text/plain' => :plain192 }193 attr_reader :pattern194 def initialize(pattern)195 @pattern = if pattern.is_a?(Hash)196 normalize_hash(pattern)197 elsif rSpecHashIncludingMatcher?(pattern)198 WebMock::Matchers::HashIncludingMatcher.from_rspec_matcher(pattern)199 else200 pattern201 end202 end203 def matches?(body, content_type = "")204 assert_non_multipart_body(content_type)205 if (@pattern).is_a?(Hash)206 return true if @pattern.empty?207 matching_hashes?(body_as_hash(body, content_type), @pattern)208 elsif (@pattern).is_a?(WebMock::Matchers::HashIncludingMatcher)209 @pattern == body_as_hash(body, content_type)210 else211 empty_string?(@pattern) && empty_string?(body) ||212 @pattern == body ||213 @pattern === body214 end215 end216 def to_s217 @pattern.inspect218 end219 private220 def body_as_hash(body, content_type)221 case BODY_FORMATS[content_type]222 when :json then223 WebMock::Util::JSON.parse(body)224 when :xml then225 Crack::XML.parse(body)226 else227 WebMock::Util::QueryMapper.query_to_values(body, notation: Config.instance.query_values_notation)228 end229 end230 def assert_non_multipart_body(content_type)231 if content_type =~ %r{^multipart/form-data}232 raise ArgumentError.new("WebMock does not support matching body for multipart/form-data requests yet :(")233 end234 end235 # Compare two hashes for equality236 #237 # For two hashes to match they must have the same length and all238 # values must match when compared using `#===`.239 #240 # The following hashes are examples of matches:241 #242 # {a: /\d+/} and {a: '123'}243 #244 # {a: '123'} and {a: '123'}245 #246 # {a: {b: /\d+/}} and {a: {b: '123'}}247 #248 # {a: {b: 'wow'}} and {a: {b: 'wow'}}249 #250 # @param [Hash] query_parameters typically the result of parsing251 # JSON, XML or URL encoded parameters.252 #253 # @param [Hash] pattern which contains keys with a string, hash or254 # regular expression value to use for comparison.255 #256 # @return [Boolean] true if the paramaters match the comparison257 # hash, false if not.258 def matching_hashes?(query_parameters, pattern)259 return false unless query_parameters.is_a?(Hash)260 return false unless query_parameters.keys.sort == pattern.keys.sort261 query_parameters.each do |key, actual|262 expected = pattern[key]263 if actual.is_a?(Hash) && expected.is_a?(Hash)264 return false unless matching_hashes?(actual, expected)265 else266 return false unless expected === actual267 end268 end269 true270 end271 def empty_string?(string)272 string.nil? || string == ""273 end274 def normalize_hash(hash)275 Hash[WebMock::Util::HashKeysStringifier.stringify_keys!(hash, deep: true).sort]276 end277 end278 class HeadersPattern279 def initialize(pattern)280 @pattern = WebMock::Util::Headers.normalize_headers(pattern) || {}281 end282 def matches?(headers)283 if empty_headers?(@pattern)284 empty_headers?(headers)285 else286 return false if empty_headers?(headers)287 @pattern.each do |key, value|288 return false unless headers.has_key?(key) && value === headers[key]289 end290 true291 end292 end293 def to_s...

Full Screen

Full Screen

api_spec.rb

Source:api_spec.rb Github

copy

Full Screen

...12 it 'uses WebMock::Matchers::HashIncludingMatcher' do13 expect(subject).to be_a(WebMock::Matchers::HashIncludingMatcher)14 end15 # by testing equality for HashIncludingMatcher (which stringifies the passed hash) we are16 # testing HashIncludingMatcher.initialize behavior as well17 context "when args correspond to an hash" do18 it "creates 'HashIncludingMatcher'" do19 expect(subject).to eq("data" => :one)20 end21 end22 context "when args are one or many keys" do23 subject {klass.new.hash_including(:foo, :bar)}24 let(:anything) { WebMock::Matchers::AnyArgMatcher.new(nil) }25 it "creates 'HashIncludingMatcher' with keys anythingized" do26 expect(subject).to eq("foo" => anything, "bar" => anything )27 end28 end29 context "when args are both keys and key/value pairs" do30 subject {klass.new.hash_including(:foo, :bar, data: :one)}31 let(:anything) { WebMock::Matchers::AnyArgMatcher.new(nil) }32 it "creates 'HashIncludingMatcher' with keys anythingized" do33 expect(subject).to eq("foo" => anything, "bar" => anything, "data" => :one)34 end35 end36 context "when args are an empty hash" do37 subject {klass.new.hash_including({})}38 it "creates 'HashIncludingMatcher' with an empty hash" do39 expect(subject).to eq({})40 end41 end42 end43 context 'when mixed into a class with a parent that defines `hash_including`' do44 subject { klass.new.hash_including(*args) }45 let(:args) { %w(:foo, :bar, {:data => :one}) }46 let(:klass) do47 Class.new(48 Class.new do49 def hash_including(*args)50 args51 end52 end53 ) { include WebMock::API }54 end55 it 'uses super and passes the args untampered' do56 expect(subject).to eq(args)57 end58 end59 end60 describe '#hash_excluding' do61 subject { klass.new.hash_excluding(args) }62 let(:args) { { data: :one } }63 context 'when mixed into a class that does not define `hash_including`' do64 let(:klass) do65 Class.new do66 include WebMock::API67 end68 end69 it 'uses WebMock::Matchers::HashIncludingMatcher' do70 expect(subject).to be_a(WebMock::Matchers::HashExcludingMatcher)71 end72 # by testing equality for HashIncludingMatcher (which stringifies the passed hash) we are73 # testing HashIncludingMatcher.initialize behavior as well74 context 'when args correspond to an hash' do75 context 'creates "HashExcludingMatcher"' do76 it 'equals hash with similar key but different value' do77 expect(subject).to eq('data' => :two)78 end79 it 'equals hash with similar value but different key' do80 expect(subject).to eq('data2' => :one)81 end82 it 'equals hash with defferent value and key' do83 expect(subject).to eq('data2' => :two)84 end85 it 'not equals with similar value and key' do86 expect(subject).not_to eq('data' => :one)87 end...

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1 def initialize(regexp)2 def ===(str)3 def initialize(string)4 def ===(str)5 def initialize(hash)6 def ===(hash)7 def initialize(hash)8 def ===(hash)9 def initialize(array)10 def ===(array)11 array.include?(value)12 def initialize(array)13 def ===(array)14 def initialize(value)15 def ===(value)16 def ===(value)17 def ===(value)

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1 let(:stub) { stub_request(:get, 'http://example.com') }2 stub.to_return(:body => 'test')3 let(:stub) { stub_request(:get, 'http://example.com') }4 stub.to_return(:body => 'test')5 WebMock::Matchers::HaveRequested.should have_been_requested(stub)6 def initialize(connection)7 let(:connection) { double("connection") }8 subject { ConnectionManager.new(connection) }9 connection.should_receive(:connect)10 def initialize(connection)

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1 def initialize(method, uri)2def stub_request(*args)3 WebMock::RequestStub.new(*args)4def a_request(*args)5 WebMock::RequestPattern.new(*args)6 to_return(:status => 200, :body => "", :headers => {})7 a = a_request(:get, 'http://www.google.com')8WebMock::RequestPattern.new(:get, "http://www.google.com", {:headers=>{"Accept"=>"*/*"}})9 def initialize(method, uri)10def stub_request(*args)11 WebMock::RequestStub.new(*args)12def a_request(*args)13 WebMock::RequestPattern.new(*args)14 to_return(:status => 200, :body => "", :headers => {})15 a = a_request(:get, 'http://www.google.com')16WebMock::RequestPattern.new(:get, "http://www.google.com", {:headers=>{"Accept"=>"*/*"}})

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1 with(:body => WebMock::Matchers::RegexpMatcher.new(/foo/))2WebMock::RequestStub.new(:any, "http://example.com").with(:body => "foo").should have_been_requested3WebMock::RequestStub.new(:any, "http://example.com").with(:body => "bar").should_not have_been_requested4 with(:body => WebMock::Matchers::RegexpMatcher.new(/foo/))5WebMock::RequestStub.new(:any, "http://example.com").with(:body => "foo bar").should have_been_requested6WebMock::RequestStub.new(:any, "http://example.com").with(:body => "bar").should_not have_been_requested7 with(:body => WebMock::Matchers::HashIncludingMatcher.new({:foo => "bar"}))8WebMock::RequestStub.new(:any, "http://example.com").with(:body => {:foo => "bar"}).should have_been_requested9WebMock::RequestStub.new(:any, "http://example.com").with(:body => {:foo => "baz"}).should_not have_been_requested10 with(:body => WebMock::Matchers::HashIncludingMatcher.new({:foo => "bar"}))

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1WebMock::API.stub_request(:get, initialize("http://localhost:8080/1.rb"))2WebMock::API.stub_request(:get, initialize("http://localhost:8080/2.rb"))3WebMock::API.stub_request(:get, initialize("http://localhost:8080/3.rb"))4WebMock::API.stub_request(:get, initialize("http://localhost:8080/4.rb"))5WebMock::API.stub_request(:get, initialize("http://localhost:8080/5.rb"))6WebMock::API.stub_request(:get, initialize("http://localhost:8080/6.rb"))

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1body_matcher = WebMock::Matchers::RequestBodyMatcher.new(/"foo":"bar"/)2 with(body: body_matcher)3assert_requested(:post, 'http://www.example.com',4assert_not_requested(:post, 'http://www.example.com',5 def initialize(method, uri)6def stub_request(*args)7 WebMock::RequestStub.new(*args)8def a_request(*args)9 WebMock::RequestPattern.new(*args)10 to_return(:status => 200, :body => "", :headers => {})11 a = a_request(:get, 'http://www.google.com')12WebMock::RequestPattern.new(:get, "http://www.google.com", {:headers=>{"Accept"=>"*/*"}})

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1WebMock::API.stub_request(:get, initialize("http://localhost:8080/1.rb"))2WebMock::API.stub_request(:get, initialize("http://localhost:8080/2.rb"))3WebMock::API.stub_request(:get, initialize("http://localhost:8080/3.rb"))4WebMock::API.stub_request(:get, initialize("http://localhost:8080/4.rb"))5WebMock::API.stub_request(:get, initialize("http://localhost:8080/5.rb"))6WebMock::API.stub_request(:get, initialize("http://localhost:8080/6.rb"))

Full Screen

Full Screen

initialize

Using AI Code Generation

copy

Full Screen

1 def initialize(regexp)2 def ===(str)3 def initialize(string)4 def ===(str)5 def initialize(hash)6 def ===(hash)7 def initialize(hash)8 def ===(hash)9 def initialize(array)10 def ===(array)11 array.include?(value)12 def initialize(array)13 def ===(array)14 def initialize(value)15 def ===(value)16 def ===(value)17 def ===(value)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Webmock_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful