Class: RSpec::Rails::Api::Utils
- Inherits:
-
Object
- Object
- RSpec::Rails::Api::Utils
- Defined in:
- lib/rspec/rails/api/utils.rb
Overview
Helper methods
Class Method Summary collapse
-
.deep_set(hash, path, value) ⇒ Hash
Sets a value at given dotted path in a hash.
-
.hash_from_response(value) ⇒ Hash
Returns a hash from an object.
Class Method Details
.deep_set(hash, path, value) ⇒ Hash
Sets a value at given dotted path in a hash
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rspec/rails/api/utils.rb', line 19 def deep_set(hash, path, value) raise 'path should be an array' unless path.is_a? Array return value if path.count.zero? current_key = path.shift.to_s.to_sym hash[current_key] = {} unless hash[current_key].is_a?(Hash) hash[current_key] = deep_set(hash[current_key], path, value) hash end |
.hash_from_response(value) ⇒ Hash
Returns a hash from an object
37 38 39 40 41 |
# File 'lib/rspec/rails/api/utils.rb', line 37 def hash_from_response(value) return JSON.parse(value.body) if value.respond_to? :body value end |