Class: HasFace::Test::Matchers::ValidateHasFaceFor
- Inherits:
-
Object
- Object
- HasFace::Test::Matchers::ValidateHasFaceFor
- Defined in:
- lib/has_face/test/matchers.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
- #has_correct_allow_blank(validator) ⇒ Object
- #has_correct_allow_nil(validator) ⇒ Object
-
#initialize(expected, options) ⇒ ValidateHasFaceFor
constructor
A new instance of ValidateHasFaceFor.
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
- #with_options_message ⇒ Object
Constructor Details
#initialize(expected, options) ⇒ ValidateHasFaceFor
Returns a new instance of ValidateHasFaceFor.
7 8 9 10 |
# File 'lib/has_face/test/matchers.rb', line 7 def initialize(expected, ) @expected = expected @options = end |
Instance Method Details
#failure_message ⇒ Object
24 25 26 |
# File 'lib/has_face/test/matchers.rb', line 24 def "expected #{@actual.class.to_s} to validate has face for #{@expected.inspect} #{}" end |
#has_correct_allow_blank(validator) ⇒ Object
32 33 34 35 |
# File 'lib/has_face/test/matchers.rb', line 32 def has_correct_allow_blank(validator) return true if @options[:allow_blank].nil? validator.instance_variable_get('@allow_blank') == @options[:allow_blank] end |
#has_correct_allow_nil(validator) ⇒ Object
37 38 39 40 |
# File 'lib/has_face/test/matchers.rb', line 37 def has_correct_allow_nil(validator) return true if @options[:allow_nil].nil? validator.instance_variable_get('@allow_nil') == @options[:allow_nil] end |
#matches?(actual) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/has_face/test/matchers.rb', line 12 def matches?(actual) @actual = actual @actual.class.validators.any? do |validator| validator.is_a?(HasFace::Validator) && \ validator.attributes.include?(@expected) && \ has_correct_allow_blank(validator) && \ has_correct_allow_nil(validator) end end |
#negative_failure_message ⇒ Object
28 29 30 |
# File 'lib/has_face/test/matchers.rb', line 28 def "expected #{@actual.class.to_s} not to validate has face for #{@expected.inspect} #{}" end |
#with_options_message ⇒ Object
42 43 44 45 46 |
# File 'lib/has_face/test/matchers.rb', line 42 def if @options.present? "with options #{@options.inspect}" end end |