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, #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


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

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

#failure_messageObject


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

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
# File 'lib/shoulda/active_record/matchers/allow_value_matcher.rb', line 37

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

#negative_failure_messageObject


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

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