Class: RSpec::SSE::Matchers::BeSuccessfullyOpened

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sse/matchers.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



329
330
331
# File 'lib/rspec/sse/matchers.rb', line 329

def description
  "be successfully opened"
end

#failure_messageObject



319
320
321
# File 'lib/rspec/sse/matchers.rb', line 319

def failure_message
  "Expected response header of `content-type` is `text/event-stream`, `cache-control` contains `no-store` or `no-cache`, and status code is `2xx`"
end

#failure_message_when_negatedObject



324
325
326
# File 'lib/rspec/sse/matchers.rb', line 324

def failure_message_when_negated
  "Expected response header of `content-type` is not `text/event-stream`, `cache-control` does not contain `no-store` or `no-cache`, and/or status code is not `2xx`"
end

#matches?(actual) ⇒ Boolean

Match if the header and status code indicate a successful SSE connection

Returns:

  • (Boolean)


311
312
313
314
315
316
# File 'lib/rspec/sse/matchers.rb', line 311

def matches?(actual)
  @actual = actual
  @actual.headers["content-type"] == "text/event-stream" \
    && @actual.headers["cache-control"]&.match(/no-(?:store|cache)/) \
    && @actual.status == 200
end