Class: ElabsMatchers::Matchers::BeValidWith::BeValidWithMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/elabs_matchers/matchers/be_valid_with.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ BeValidWithMatcher

Returns a new instance of BeValidWithMatcher



10
11
12
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 10

def initialize(values)
  @values = values
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes



8
9
10
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 8

def attributes
  @attributes
end

#recordObject (readonly)

Returns the value of attribute record



8
9
10
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 8

def record
  @record
end

Instance Method Details

#as(*attributes) ⇒ Object

Tell the matcher which attributes to check

Example: post.should be_valid_with(“Elabs”).as(:title)

Parameters:

  • attributes (*Array)

    The method name(s) that has the validation(s) attached to it



33
34
35
36
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 33

def as(*attributes)
  @attributes = [*attributes]
  self
end

#descriptionObject



48
49
50
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 48

def description
  "be valid with #{@values.inspect} as #{@attributes.inspect}"
end

#does_not_match?(record) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 19

def does_not_match?(record)
  @record = record
  errors.all? and correct_number_of_errors?
end

#failure_messageObject Also known as: failure_message_for_should



38
39
40
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 38

def failure_message
  common_failure_message(:valid)
end

#failure_message_when_negatedObject Also known as: failure_message_for_should_not



43
44
45
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 43

def failure_message_when_negated
  common_failure_message(:invalid)
end

#matches?(record) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/elabs_matchers/matchers/be_valid_with.rb', line 14

def matches?(record)
  @record = record
  errors.none?
end