Module: Committee::Test::Methods

Defined in:
lib/committee/test/methods.rb

Instance Method Summary collapse

Instance Method Details

#assert_schema_conformObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/committee/test/methods.rb', line 3

def assert_schema_conform
  if (data = schema_contents).is_a?(String)
    warn_string_deprecated
    data = MultiJson.decode(data)
  end

  @schema ||= begin
    schema = JsonSchema.parse!(data)
    schema.expand_references!
    schema
  end
  @router ||= Committee::Router.new(@schema, prefix: schema_url_prefix)

  unless link = @router.find_request_link(last_request)
    response = "`#{last_request.request_method} #{last_request.path_info}` undefined in schema."
    raise Committee::InvalidResponse.new(response)
  end

  if validate_response?(last_response.status)
    data = MultiJson.decode(last_response.body)
    Committee::ResponseValidator.new(link).call(last_response.status, last_response.headers, data)
  end
end

#assert_schema_content_typeObject



27
28
29
# File 'lib/committee/test/methods.rb', line 27

def assert_schema_content_type
  Committee.warn_deprecated("Committee: use of #assert_schema_content_type is deprecated; use #assert_schema_conform instead.")
end

#schema_contentsObject

can be overridden alternatively to #schema_path in case the schema is easier to access as a string blob



34
35
36
# File 'lib/committee/test/methods.rb', line 34

def schema_contents
  MultiJson.decode(File.read(schema_path))
end

#schema_pathObject



38
39
40
# File 'lib/committee/test/methods.rb', line 38

def schema_path
  raise "Please override #schema_contents or #schema_path."
end

#schema_url_prefixObject



42
43
44
# File 'lib/committee/test/methods.rb', line 42

def schema_url_prefix
  nil
end

#validate_response?(status) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/committee/test/methods.rb', line 50

def validate_response?(status)
  Committee::ResponseValidator.validate?(status)
end

#warn_string_deprecatedObject



46
47
48
# File 'lib/committee/test/methods.rb', line 46

def warn_string_deprecated
  Committee.warn_deprecated("Committee: returning a string from `#schema_contents` is deprecated; please return a deserialized hash instead.")
end