Class: RSpec::JsonApi::Matchers::HaveNoContent

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

Overview

The HaveNoContent class is designed to verify that a given string is empty.

This matcher is primarily used within RSpec tests to assert that a given string lacks content, effectively ensuring that expected content is absent, which can be particularly useful in testing API responses or other outputs where the absence of content signifies a specific state or outcome.

Instance Method Summary collapse

Instance Method Details

#failure_messageString

Provides a failure message for when the actual string contains content, contrary to the expectation of being empty.

Returns:

  • (String)

    A descriptive message indicating the expectation was for the string to have no content, yet content was found.



26
27
28
# File 'lib/rspec/json_api/matchers/have_no_content.rb', line 26

def failure_message
  "expected the string to be empty but it contained content"
end

#failure_message_when_negatedString

Provides a failure message for when the expectation is negated (i.e., expecting content) and the actual string is unexpectedly empty.

Returns:

  • (String)

    A descriptive message indicating that content was expected in the string, but it was found to be empty.



35
36
37
# File 'lib/rspec/json_api/matchers/have_no_content.rb', line 35

def failure_message_when_negated
  "expected the string not to be empty, yet it was devoid of content"
end

#matches?(actual) ⇒ Boolean

Determines whether the actual string is empty, signifying no content.

Parameters:

  • actual (String)

    The string to be evaluated.

Returns:

  • (Boolean)

    Returns true if the string is empty, indicating no content; false otherwise.



17
18
19
# File 'lib/rspec/json_api/matchers/have_no_content.rb', line 17

def matches?(actual)
  actual == ""
end