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
# File 'lib/committee/test/methods.rb', line 3

def assert_schema_conform
  assert_schema_content_type

  @schema ||= Committee::Schema.new(File.read(schema_path))
  @router ||= Committee::Router.new(@schema)

  link_schema, type_schema =
    @router.routes_request?(last_request, prefix: schema_url_prefix)

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

  data = MultiJson.decode(last_response.body)
  Committee::ResponseValidator.new(
    data,
    @schema,
    link_schema,
    type_schema
  ).call
end

#assert_schema_content_typeObject



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

def assert_schema_content_type
  unless last_response.headers["Content-Type"] =~ %r{application/json}
    raise Committee::InvalidResponse,
      %{"Content-Type" response header must be set to "application/json".}
  end
end

#schema_pathObject



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

def schema_path
  raise "Please override #schema_path."
end

#schema_url_prefixObject



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

def schema_url_prefix
  nil
end