Class: Webspicy::Web::Specification::Post::ETagCachingProtocol

Inherits:
Object
  • Object
show all
Includes:
Specification::Post
Defined in:
lib/webspicy/web/specification/post/etag_caching_protocol.rb

Constant Summary collapse

MATCH =
/It supports the ETag\/If-None-Match caching protocol/

Constants included from Specification::Condition

Specification::Condition::MATCH_ALL

Instance Attribute Summary

Attributes included from Specification::Condition

#matching_description, #tester

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Specification::Post

#contribute_to_openapi_verb, #instrument

Methods included from Specification::Condition

#bind, #fail!, #sooner_or_later, #to_s

Class Method Details

.match(service, descr) ⇒ Object



10
11
12
13
# File 'lib/webspicy/web/specification/post/etag_caching_protocol.rb', line 10

def self.match(service, descr)
  return nil unless descr =~ MATCH
  ETagCachingProtocol.new
end

Instance Method Details

#check!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webspicy/web/specification/post/etag_caching_protocol.rb', line 15

def check!
  res = invocation.response
  etag = res.headers['ETag']
  fail!("No ETag response header found") unless etag

  url, _ = test_case.specification.instantiate_url(test_case.params)
  url = scope.to_real_url(url, test_case){|u,_| u }

  response = client.api.get(url, {}, test_case.headers.merge({
    'If-None-Match' => etag
  }))
  fail!("304 expected") unless response.status == 304

  response = client.api.get(url, {}, test_case.headers.merge({
    'If-None-Match' => "W/somethingelse"
  }))
  fail!("2xx expected") if response.status == 304
end