Class: Ubazu::Rspec::Matchers::ActiveRecord::ValidateInclusionOfMatcher

Inherits:
ValidationMatcher
  • Object
show all
Defined in:
lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ValidationMatcher

#failure_message

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#initialize, #negative_failure_message

Constructor Details

This class inherits a constructor from Ubazu::Rspec::Matchers::ActiveRecord::ValidationMatcher

Instance Method Details

#descriptionObject



51
52
53
# File 'lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb', line 51

def description
  "ensured inclusion of #{@attribute} in #{@array.inspect}"
end

#in(array) ⇒ Object



24
25
26
27
# File 'lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb', line 24

def in(array)
  @array = array
  self
end

#matches?(instance) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb', line 34

def matches?(instance)
  @instance = instance
  super(instance)

  @expected_message ||= :blank
  wrong_value = rand(99999999999).to_s.to_sym #wrong symbol
  @instance.send("#{@attribute}=", wrong_value)
  result = !errors_match?

  if result
    true
  else
    @failure_message = "#{@attribute} is not validated for inclusion in #{@array.inspect}"
    false
  end
end

#with_message(message) ⇒ Object



29
30
31
32
# File 'lib/ubazu/rspec/matchers/active_record/validate_inclusion_of_matcher.rb', line 29

def with_message(message)
  @expected_message = message if message
  self
end