Class: Rspec::RequestSnapshot::Handlers::JSON

Inherits:
Base
  • Object
show all
Defined in:
lib/rspec/request_snapshot/handlers/json.rb

Instance Method Summary collapse

Methods inherited from Base

#dynamic_attributes, #initialize

Constructor Details

This class inherits a constructor from Rspec::RequestSnapshot::Handlers::Base

Instance Method Details

#comparable(str) ⇒ Object



18
19
20
# File 'lib/rspec/request_snapshot/handlers/json.rb', line 18

def comparable(str)
  JSON.parse(str)
end

#compare(actual, expected) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rspec/request_snapshot/handlers/json.rb', line 2

def compare(actual, expected)
  equal = true

  actual.each do |key, value|
    if actual[key].is_a?(Hash)
      equal &= compare_hash(key, actual, expected)
    elsif actual[key].is_a?(Array)
      equal &= compare_array(key, actual, expected)
    else
      equal &= compare_value(key, actual, expected)
    end
  end

  equal
end

#writable(str) ⇒ Object



22
23
24
# File 'lib/rspec/request_snapshot/handlers/json.rb', line 22

def writable(str)
  JSON.pretty_generate(JSON.parse(str))
end