Module: Rspec::ApiHelpers::ExampleMethods

Defined in:
lib/rspec/api_helpers/example_methods.rb

Defined Under Namespace

Classes: ObjectHash

Instance Method Summary collapse

Instance Method Details

#object_hash(hash, existing: true) ⇒ Object



32
33
34
# File 'lib/rspec/api_helpers/example_methods.rb', line 32

def object_hash(hash, existing: true)
  ObjectHash.new(hash, existing: existing)
end

#objectize_resource(json, root:, existing: true) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/rspec/api_helpers/example_methods.rb', line 21

def objectize_resource(json, root:, existing: true)
  hash = HashWithIndifferentAccess.new(JSON.parse(json))
  if root
    obj = object_hash(hash[root], existing: existing)
  else
    obj = object_hash(hash, existing: existing)
  end

  return obj
end

#objectize_resources(json, root:, existing: true) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rspec/api_helpers/example_methods.rb', line 6

def objectize_resources(json, root:, existing: true)
  array = []
  array_hash = HashWithIndifferentAccess.new(JSON.parse(json))

  if root
    array_hash = array_hash[root]
  end

  array_hash.each do |resource|
    array << object_hash(resource, existing: existing)
  end

  return array
end

#superset_mismatch_error(superset, subset) ⇒ Object



65
66
67
# File 'lib/rspec/api_helpers/example_methods.rb', line 65

def superset_mismatch_error(superset, subset)
  "Expected \n #{subset.to_a.to_s} \n to be included in \n #{superset.to_a.to_s}"
end