Class: SpecForge::Step::Expect
- Inherits:
-
Object
- Object
- SpecForge::Step::Expect
- Defined in:
- lib/spec_forge/step/expect.rb
Overview
Represents an expectation block within a step
Holds the expected status, headers, and body (raw or JSON) that will be validated against the HTTP response. Provides methods to convert expectations into RSpec matchers.
Instance Method Summary collapse
-
#headers_matcher ⇒ Hash?
Returns headers as a hash of matchers.
-
#initialize(status: nil, headers: nil, raw: nil, json: nil) ⇒ Expect
constructor
A new instance of Expect.
-
#json_content_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the JSON content matcher.
-
#json_schema ⇒ Hash?
Returns the JSON schema structure for validation.
-
#json_size_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the JSON size matcher.
-
#size ⇒ Integer
Returns the total number of assertions in this expectation.
-
#status_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the status code as an RSpec matcher.
Constructor Details
#initialize(status: nil, headers: nil, raw: nil, json: nil) ⇒ Expect
Returns a new instance of Expect.
13 14 15 16 17 18 19 20 |
# File 'lib/spec_forge/step/expect.rb', line 13 def initialize(status: nil, headers: nil, raw: nil, json: nil) super( status: status ? Attribute.from(status) : nil, headers: extract_headers(headers), raw: raw ? Attribute.from(raw) : nil, json: extract_json(json) ) end |
Instance Method Details
#headers_matcher ⇒ Hash?
Returns headers as a hash of matchers
56 57 58 59 60 |
# File 'lib/spec_forge/step/expect.rb', line 56 def headers_matcher return if headers.blank? headers.transform_values(&Attribute.resolve_as_matcher_proc) end |
#json_content_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the JSON content matcher
85 86 87 |
# File 'lib/spec_forge/step/expect.rb', line 85 def json_content_matcher json[:content]&.resolve_as_matcher end |
#json_schema ⇒ Hash?
Returns the JSON schema structure for validation
76 77 78 |
# File 'lib/spec_forge/step/expect.rb', line 76 def json_schema json[:schema] end |
#json_size_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the JSON size matcher
67 68 69 |
# File 'lib/spec_forge/step/expect.rb', line 67 def json_size_matcher json[:size]&.resolve_as_matcher end |
#size ⇒ Integer
Returns the total number of assertions in this expectation
Counts all non-blank assertions (status, headers, raw, JSON size/schema/content).
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/spec_forge/step/expect.rb', line 29 def size [ status, headers, raw, json[:size], json[:schema], json[:content] ].compact_blank.size end |
#status_matcher ⇒ RSpec::Matchers::BuiltIn::BaseMatcher?
Returns the status code as an RSpec matcher
45 46 47 48 49 |
# File 'lib/spec_forge/step/expect.rb', line 45 def status_matcher return if status.blank? status.resolve_as_matcher end |