Class: ErrorConfigSupport

Inherits:
Object
  • Object
show all
Defined in:
lib/features/support/error_config_support.rb

Class Method Summary collapse

Class Method Details

.prepare_error_config(table_hashes) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/features/support/error_config_support.rb', line 3

def prepare_error_config(table_hashes)

  error_config = {
    headers: {},
  }
  table_hashes.each do |hash|
    type = hash['type']
    name = hash['name']
    value = hash['value']

    case type
    when 'header'
      error_config[:headers][name] = value
    when 'property'
      case name
      when 'status'
        error_config[:status] = value.to_i
      when 'body'
        if value.start_with?('@')
          body = File.read(value[1..])
        else
          body = value
        end
        error_config[:body] = body
        error_config[:headers]['ETag'] = Digest::SHA1.hexdigest(body.to_s)
      else
        raise "Unknown property '#{name}'"
      end
    else
      raise "Unknown type '#{type}'"
    end
  end

  Maze::Server.error_configs.add(error_config)
end