Class: SpecForge::Forge::Expect

Inherits:
Action
  • Object
show all
Defined in:
lib/spec_forge/forge/actions/expect.rb

Overview

Action for the expect: step attribute

Runs expectations against the current response, validating status codes, headers, and JSON body against expected values using RSpec matchers.

Instance Attribute Summary

Attributes inherited from Action

#step

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from SpecForge::Forge::Action

Instance Method Details

#run(forge) ⇒ void

This method returns an undefined value.

Runs all expectations for the step against the current response

Parameters:

  • forge (Forge)

    The forge instance containing response data

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spec_forge/forge/actions/expect.rb', line 21

def run(forge)
  show_expectation_count = step.expects.size > 1

  failed_examples =
    step.expects.flat_map.with_index do |expectation, index|
      failed = forge.runner.run(forge, step, expectation)

      forge.display.expectation_finished(
        failed_examples: failed,
        total_count: expectation.size,
        index: index + 1,
        show_index: show_expectation_count
      )

      failed
    end

  return if failed_examples.empty?

  raise Error::ExpectationFailure.new(failed_examples)
end