Class: Operandi::RSpec::Matchers::HaveErrorsOnMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(keys) ⇒ HaveErrorsOnMatcher

Returns a new instance of HaveErrorsOnMatcher.



103
104
105
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 103

def initialize(keys)
  @keys = keys
end

Instance Method Details

#descriptionObject



128
129
130
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 128

def description
  "have errors on #{@keys.inspect}"
end

#failure_messageObject



118
119
120
121
122
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 118

def failure_message
  "expected service to have errors on #{@keys.inspect}, " \
    "but missing errors on: #{@missing_keys.inspect}. " \
    "Actual errors: #{errors_summary}"
end

#failure_message_when_negatedObject



124
125
126
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 124

def failure_message_when_negated
  "expected service not to have errors on #{@keys.inspect}"
end

#matches?(service) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
116
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 107

def matches?(service)
  @service = service
  @missing_keys = []

  @keys.each do |key|
    @missing_keys << key unless @service.errors.key?(key)
  end

  @missing_keys.empty?
end