Class: Shoulda::ActiveRecord::Matchers::AllowValueMatcher

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/shoulda/active_record/matchers/allow_value_matcher.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from Helpers

#default_error_message, #get_instance_of, #instance_variable_name_for, #pretty_error_messages

Constructor Details

#initialize(value) ⇒ AllowValueMatcher

Returns a new instance of AllowValueMatcher.



23
24
25
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 23

def initialize(value)
  @value = value
end

Instance Method Details

#descriptionObject



55
56
57
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 55

def description
  "allow #{@attribute} to be set to #{@value.inspect}"
end

#failure_messageObject



47
48
49
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 47

def failure_message
  "Did not expect #{expectation}, got error: #{@matched_error}"
end

#for(attribute) ⇒ Object



27
28
29
30
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 27

def for(attribute)
  @attribute = attribute
  self
end

#matches?(instance) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 37

def matches?(instance)
  @instance = instance
  @expected_message ||= :invalid
  if Symbol === @expected_message
    @expected_message = default_error_message(@expected_message)
  end
  @instance.send("#{@attribute}=", @value)
  !errors_match?
end

#negative_failure_messageObject



51
52
53
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 51

def negative_failure_message
  "Expected #{expectation}, got #{error_description}"
end

#with_message(message) ⇒ Object



32
33
34
35
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 32

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