Class: RSpec::SleepingKingStudios::Matchers::ActiveModel::HaveErrors::ErrorExpectation

Inherits:
Struct
  • Object
show all
Defined in:
lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb

Overview

Stores an expectation of receiving an error for a specified attribute, as well as zero or more message expectations.

See Also:

Since:

  • 1.0.0

Defined Under Namespace

Modules: MessagesMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, expected = true, received = false) ⇒ ErrorExpectation

Returns a new instance of ErrorExpectation.

Parameters:

  • attribute (String, Symbol)

    The attribute for which an error is expected to be or has been received.

  • expected (Boolean) (defaults to: true)

    Whether an error is expected for the specified attribute.

  • received (Boolean) (defaults to: false)

    Whether an error has been received for the specified attribute.

Since:

  • 1.0.0



41
42
43
44
45
46
47
48
# File 'lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb', line 41

def initialize attribute, expected = true, received = false
  super attribute.intern, expected, received

  @messages = []
  class << @messages
    include MessagesMethods
  end # eigenclass
end

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



13
14
15
# File 'lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb', line 13

def attribute
  @attribute
end

#expectedObject

Returns the value of attribute expected

Returns:

  • (Object)

    the current value of expected



13
14
15
# File 'lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb', line 13

def expected
  @expected
end

#messagesArray<MessageExpectation> (readonly)

The message expectations for the specified attribute. The returned array supports several additional methods: #expected, #missing, and #received.



58
59
60
# File 'lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb', line 58

def messages
  @messages
end

#receivedObject

Returns the value of attribute received

Returns:

  • (Object)

    the current value of received



13
14
15
# File 'lib/rspec/sleeping_king_studios/matchers/active_model/have_errors/error_expectation.rb', line 13

def received
  @received
end