Class: Contracto::RSpec::JsonHelper::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/contracto/rspec/json_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, options = {}) ⇒ Response

Returns a new instance of Response.



25
26
27
28
# File 'lib/contracto/rspec/json_helper.rb', line 25

def initialize(body, options = {})
  @body = body
  @options = options
end

Instance Method Details

#parse_json_with_optionsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/contracto/rspec/json_helper.rb', line 38

def parse_json_with_options
  if @options[:ignore]
    if @json.is_a?(Array)
      @json.each do |json|
        @options[:ignore].each do |key|
          json.delete(key.to_s)
        end
      end
    else
      @options[:ignore].each do |key|
        @json.delete(key.to_s)
      end
    end
  end
end

#to_jsonObject



30
31
32
33
34
35
36
# File 'lib/contracto/rspec/json_helper.rb', line 30

def to_json
  JSON.parse(@body).tap do |json|
    @json = json
    parse_json_with_options
  end
  @json
end