Class: ResponseField

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber-rest-bdd/types.rb

Instance Method Summary collapse

Constructor Details

#initialize(names) ⇒ ResponseField

Returns a new instance of ResponseField.



30
31
32
# File 'lib/cucumber-rest-bdd/types.rb', line 30

def initialize(names)
    @fields = get_fields(names)
end

Instance Method Details

#get_value(response, type) ⇒ Object



38
39
40
# File 'lib/cucumber-rest-bdd/types.rb', line 38

def get_value(response, type)
    return response.get_as_type to_json_path(), parse_type(type)
end

#to_json_pathObject



34
35
36
# File 'lib/cucumber-rest-bdd/types.rb', line 34

def to_json_path()
    return "#{get_root_data_key()}#{@fields.join('.')}"
end

#validate_value(response, value, regex) ⇒ Object



42
43
44
# File 'lib/cucumber-rest-bdd/types.rb', line 42

def validate_value(response, value, regex)
    raise %/Expected #{json_path} value '#{value}' to match regex: #{regex}\n#{response.to_json_s}/ if (regex =~ value).nil?
end