Class: SpecForge::Forge::Runner::ContentValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/forge/runner/content_validator.rb

Overview

Validates JSON content against expected matchers

Recursively walks through the response body and expected values, running RSpec matchers at each leaf node and collecting failures.

Instance Method Summary collapse

Constructor Details

#initialize(data, expected) ⇒ ContentValidator

Creates a new content validator

Parameters:

  • data (Hash, Array)

    The response data to validate

  • expected (Hash, Array)

    The expected content matchers



21
22
23
24
25
# File 'lib/spec_forge/forge/runner/content_validator.rb', line 21

def initialize(data, expected)
  @data = data
  @expected = expected
  @failures = []
end

Instance Method Details

#validate!void

This method returns an undefined value.

Validates the data against expected content matchers

Raises:



34
35
36
37
38
# File 'lib/spec_forge/forge/runner/content_validator.rb', line 34

def validate!
  check_content(@data, @expected, path: "")

  raise Error::ContentValidationFailure.new(@failures) if @failures.any?
end