Class: RSpec::ActiveRecord::Expectations::Matchers::QueryCountMatcher
- Inherits:
-
Object
- Object
- RSpec::ActiveRecord::Expectations::Matchers::QueryCountMatcher
- Defined in:
- lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb
Instance Attribute Summary collapse
-
#collector ⇒ Object
readonly
Returns the value of attribute collector.
-
#comparison ⇒ Object
readonly
Returns the value of attribute comparison.
-
#quantifier ⇒ Object
readonly
Returns the value of attribute quantifier.
-
#query_type ⇒ Object
readonly
Returns the value of attribute query_type.
Instance Method Summary collapse
-
#actual_count ⇒ Object
helper for message builder.
- #exactly(n) ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
- #greater_than(n) ⇒ Object (also: #more_than)
- #greater_than_or_equal_to(n) ⇒ Object (also: #at_least)
-
#initialize ⇒ QueryCountMatcher
constructor
A new instance of QueryCountMatcher.
-
#less_than(n) ⇒ Object
(also: #fewer_than)
QUANTIFIERS.
- #less_than_or_equal_to(n) ⇒ Object (also: #at_most)
- #matches?(block) ⇒ Boolean
- #supports_block_expectations? ⇒ Boolean
Constructor Details
#initialize ⇒ QueryCountMatcher
Returns a new instance of QueryCountMatcher.
6 7 8 9 10 11 12 13 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 6 def initialize @collector = Collector.new @message_builder = MessageBuilder.new(self) @match_method = nil @quantifier = nil @query_type = nil end |
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
4 5 6 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 4 def collector @collector end |
#comparison ⇒ Object (readonly)
Returns the value of attribute comparison.
4 5 6 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 4 def comparison @comparison end |
#quantifier ⇒ Object (readonly)
Returns the value of attribute quantifier.
4 5 6 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 4 def quantifier @quantifier end |
#query_type ⇒ Object (readonly)
Returns the value of attribute query_type.
4 5 6 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 4 def query_type @query_type end |
Instance Method Details
#actual_count ⇒ Object
helper for message builder
98 99 100 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 98 def actual_count @collector.queries_of_type(@query_type) end |
#exactly(n) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 72 def exactly(n) @quantifier = n @comparison = :exactly @match_method = -> { actual_count == @quantifier } self end |
#failure_message ⇒ Object
15 16 17 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 15 def @message_builder. end |
#failure_message_when_negated ⇒ Object
19 20 21 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 19 def @message_builder. end |
#greater_than(n) ⇒ Object Also known as: more_than
56 57 58 59 60 61 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 56 def greater_than(n) @quantifier = n @comparison = :greater_than @match_method = -> { actual_count > @quantifier } self end |
#greater_than_or_equal_to(n) ⇒ Object Also known as: at_least
64 65 66 67 68 69 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 64 def greater_than_or_equal_to(n) @quantifier = n @comparison = :greater_than_or_equal_to @match_method = -> { actual_count >= @quantifier } self end |
#less_than(n) ⇒ Object Also known as: fewer_than
QUANTIFIERS
40 41 42 43 44 45 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 40 def less_than(n) @quantifier = n @comparison = :less_than @match_method = -> { actual_count < @quantifier } self end |
#less_than_or_equal_to(n) ⇒ Object Also known as: at_most
48 49 50 51 52 53 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 48 def less_than_or_equal_to(n) @quantifier = n @comparison = :less_than_or_equal_to @match_method = -> { actual_count <= @quantifier } self end |
#matches?(block) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 27 def matches?(block) raise NoComparisonError unless @match_method raise NoQueryTypeError unless @collector.valid_type?(@query_type) block.call result = @match_method.call @collector.finalize result end |
#supports_block_expectations? ⇒ Boolean
23 24 25 |
# File 'lib/rspec/activerecord/expectations/matchers/query_count_matcher.rb', line 23 def supports_block_expectations? true end |