Class: Operandi::RSpec::Matchers::HaveErrorOnMatcher

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

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ HaveErrorOnMatcher

Returns a new instance of HaveErrorOnMatcher.



28
29
30
31
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 28

def initialize(key)
  @key = key
  @expected_message = nil
end

Instance Method Details

#descriptionObject



62
63
64
65
66
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 62

def description
  desc = "have error on :#{@key}"
  desc += " with message #{@expected_message.inspect}" if @expected_message
  desc
end

#failure_messageObject



47
48
49
50
51
52
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 47

def failure_message
  return "expected service to have error on :#{@key}, but errors were: #{errors_summary}" unless has_error_key?
  return message_failure_message unless message_matches?

  ""
end

#failure_message_when_negatedObject



54
55
56
57
58
59
60
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 54

def failure_message_when_negated
  if @expected_message
    "expected service not to have error on :#{@key} with message #{@expected_message.inspect}"
  else
    "expected service not to have error on :#{@key}"
  end
end

#matches?(service) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 38

def matches?(service)
  @service = service

  return false unless has_error_key?
  return false unless message_matches?

  true
end

#with_message(message) ⇒ Object



33
34
35
36
# File 'lib/operandi/rspec/matchers/have_error_on.rb', line 33

def with_message(message)
  @expected_message = message
  self
end