Class: Salestation::RSpec::GliaInputValidationErrorMatcher

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers::Composable
Defined in:
lib/salestation/rspec/glia_input_validation_error_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGliaInputValidationErrorMatcher

Returns a new instance of GliaInputValidationErrorMatcher.



12
13
14
15
16
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 12

def initialize
  @fields = []
  @field_error_types = {}
  @field_error_messages = {}
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



10
11
12
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 10

def actual
  @actual
end

#expectedObject (readonly)

Returns the value of attribute expected.



10
11
12
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 10

def expected
  @expected
end

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



10
11
12
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 10

def failure_message
  @failure_message
end

Instance Method Details

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 33

def matches?(actual)
  @fields.all? do |field|
    check_field_exists(actual, *field) &&
      check_field_error_types(field, actual) &&
      check_field_error_messages(field, actual)
  end
end

#on(*nested_fields) ⇒ Object



18
19
20
21
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 18

def on(*nested_fields)
  @fields << nested_fields
  self
end

#with_message(*messages) ⇒ Object



28
29
30
31
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 28

def with_message(*messages)
  @field_error_messages[field_to_key(@fields.last)] = messages
  self
end

#with_type(*types) ⇒ Object



23
24
25
26
# File 'lib/salestation/rspec/glia_input_validation_error_matcher.rb', line 23

def with_type(*types)
  @field_error_types[field_to_key(@fields.last)] = types
  self
end