Class: ApiSim::Matchers::BaseMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/api_sim/matchers/base_matcher.rb

Constant Summary collapse

DEFAULT_RACK_RESPONSE =
[200, {}, '']
ALWAYS_TRUE_MATCHER =
->(request) { true }

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#request_schemaObject (readonly)

Returns the value of attribute request_schema.



8
9
10
# File 'lib/api_sim/matchers/base_matcher.rb', line 8

def request_schema
  @request_schema
end

Instance Method Details

#custom_matcher?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/api_sim/matchers/base_matcher.rb', line 10

def custom_matcher?
  matcher != ALWAYS_TRUE_MATCHER
end

#match_on_body?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/api_sim/matchers/base_matcher.rb', line 31

def match_on_body?
  false
end

#overridden!Object



14
15
16
# File 'lib/api_sim/matchers/base_matcher.rb', line 14

def overridden!
  @overridden = true
end

#overridden?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/api_sim/matchers/base_matcher.rb', line 18

def overridden?
  !!@overridden
end

#readonly?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/api_sim/matchers/base_matcher.rb', line 35

def readonly?
  false
end

#record_request(request) ⇒ Object



39
40
41
42
43
# File 'lib/api_sim/matchers/base_matcher.rb', line 39

def record_request(request)
  request.body.rewind
  requests.push(RecordedRequest.new(body: request.body.read, request_env: request.env, request_path: request.path,
      query_string: request.params))
end

#requestsObject



27
28
29
# File 'lib/api_sim/matchers/base_matcher.rb', line 27

def requests
  @requests ||= []
end

#reset!Object



22
23
24
25
# File 'lib/api_sim/matchers/base_matcher.rb', line 22

def reset!
  @requests = []
  @overridden = false
end

#response(_) ⇒ Object



51
52
53
# File 'lib/api_sim/matchers/base_matcher.rb', line 51

def response(_)
  [response_code, headers, response_body]
end

#to_sObject



45
46
47
48
49
# File 'lib/api_sim/matchers/base_matcher.rb', line 45

def to_s
  <<-DOC.gsub(/^\s+/, '')
    #{http_method} #{route}
  DOC
end