Class: DataMapper::Matchers::ValidationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/dm/matchers/validation_matcher.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property) ⇒ ValidationMatcher

Returns a new instance of ValidationMatcher.



17
18
19
20
21
# File 'lib/dm/matchers/validation_matcher.rb', line 17

def initialize(property)
  @property = property.to_sym
	@validation_subject = self.class.instance_eval { @validation_subject }
	@msg_reg = self.class.instance_eval { @default_msg_reg }
end

Class Method Details

.set_default_msg_reg(msg_reg) ⇒ Object



10
11
12
# File 'lib/dm/matchers/validation_matcher.rb', line 10

def set_default_msg_reg(msg_reg)
  @default_msg_reg = msg_reg
end

.set_validation_subject(subject) ⇒ Object



6
7
8
# File 'lib/dm/matchers/validation_matcher.rb', line 6

def set_validation_subject(subject)
  @validation_subject = subject
end

Instance Method Details

#descriptionObject



41
42
43
# File 'lib/dm/matchers/validation_matcher.rb', line 41

def description
  "validate #{@validation_subject} of #{@property}"
end

#failure_messageObject



29
30
31
32
33
# File 'lib/dm/matchers/validation_matcher.rb', line 29

def failure_message
  msg = "expected to validate #{@validation_subject} of #{@property}"
  msg = %Q'#{msg} with message "#{@msg}"' if @msg
  msg
end

#negative_failure_messageObject



35
36
37
38
39
# File 'lib/dm/matchers/validation_matcher.rb', line 35

def negative_failure_message
  msg = "expected to not validate #{@validation_subject} of #{@property}"
  msg = %Q'#{msg} with message "#{@msg}"' if @msg
  msg
end

#with_message(msg) ⇒ Object



23
24
25
26
27
# File 'lib/dm/matchers/validation_matcher.rb', line 23

def with_message(msg)
  @msg = msg
  @msg_reg = /^#{Regexp.escape(@msg)}$/
  self
end