Class: ModelTimeline::RSpec::Matchers::HaveTimelineEntriesMatcher Private
- Inherits:
-
Object
- Object
- ModelTimeline::RSpec::Matchers::HaveTimelineEntriesMatcher
- Defined in:
- lib/model_timeline/rspec/matchers.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
RSpec matcher to check if a model has timeline entries
Instance Method Summary collapse
-
#failure_message ⇒ String
private
Message displayed when the expectation fails.
-
#failure_message_when_negated ⇒ String
private
Message displayed when the negated expectation fails.
-
#initialize(expected_count, association_name) ⇒ HaveTimelineEntriesMatcher
constructor
private
Initialize the matcher.
-
#matches?(subject) ⇒ Boolean
private
Check if the subject matches the expectations.
Constructor Details
#initialize(expected_count, association_name) ⇒ HaveTimelineEntriesMatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the matcher
99 100 101 102 |
# File 'lib/model_timeline/rspec/matchers.rb', line 99 def initialize(expected_count, association_name) @expected_count = expected_count @association_name = association_name end |
Instance Method Details
#failure_message ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Message displayed when the expectation fails
120 121 122 123 124 125 126 127 |
# File 'lib/model_timeline/rspec/matchers.rb', line 120 def if @expected_count.nil? "expected #{@subject} to have timeline entries, but found none" else "expected #{@subject} to have #{@expected_count} timeline entries, " \ "but found #{@subject.public_send(@association_name).count}" end end |
#failure_message_when_negated ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Message displayed when the negated expectation fails
132 133 134 135 136 137 138 |
# File 'lib/model_timeline/rspec/matchers.rb', line 132 def if @expected_count.nil? "expected #{@subject} not to have any timeline entries, but found #{@subject.public_send(@association_name).count}" else "expected #{@subject} not to have #{@expected_count} timeline entries, but found exactly that many" end end |
#matches?(subject) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Check if the subject matches the expectations
108 109 110 111 112 113 114 115 |
# File 'lib/model_timeline/rspec/matchers.rb', line 108 def matches?(subject) @subject = subject if @expected_count.nil? subject.public_send(@association_name).any? else subject.public_send(@association_name).count == @expected_count end end |