Class: RSpectacular::ActiveRecord::Matchers::DatelinessMatcher
- Inherits:
-
Object
- Object
- RSpectacular::ActiveRecord::Matchers::DatelinessMatcher
- Includes:
- Shoulda::ActiveRecord::Helpers
- Defined in:
- lib/rspectacular/matchers/active_record/dateliness_matcher.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(date_field) ⇒ DatelinessMatcher
constructor
A new instance of DatelinessMatcher.
- #matches?(dateable) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(date_field) ⇒ DatelinessMatcher
Returns a new instance of DatelinessMatcher.
7 8 9 10 |
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 7 def initialize(date_field) @date_field = date_field.to_s @date_method = "#{date_field.to_s}=".to_sym end |
Instance Method Details
#description ⇒ Object
29 30 31 |
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 29 def description "should be contain a valid date" end |
#failure_message ⇒ Object
21 22 23 |
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 21 def "Expected #{@date_field} to contain a valid date, got: #{(@dateable)}" end |
#matches?(dateable) ⇒ Boolean
12 13 14 15 16 17 18 19 |
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 12 def matches?(dateable) @dateable = dateable dateable.send(@date_method, Date.today) dateable.valid? !dateable.errors[@date_field].include?("is not a valid date") end |
#negative_failure_message ⇒ Object
25 26 27 |
# File 'lib/rspectacular/matchers/active_record/dateliness_matcher.rb', line 25 def "Expected #{@date_field} to contain an invalid date, got: #{(@dateable)}" end |