Class: RSpec::ActiveRecord::Expectations::Matchers::TransactionMatcher
- Inherits:
-
Object
- Object
- RSpec::ActiveRecord::Expectations::Matchers::TransactionMatcher
- Defined in:
- lib/rspec/activerecord/expectations/matchers/transaction_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
- #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(transaction_type) ⇒ TransactionMatcher
constructor
A new instance of TransactionMatcher.
-
#less_than(n) ⇒ Object
(also: #fewer_than)
QUANTIFIERS.
- #less_than_or_equal_to(n) ⇒ Object (also: #at_most)
- #matches?(block) ⇒ Boolean
- #once ⇒ Object
- #supports_block_expectations? ⇒ Boolean
-
#thrice ⇒ Object
hehe.
- #times ⇒ Object (also: #time)
- #twice ⇒ Object
Constructor Details
#initialize(transaction_type) ⇒ TransactionMatcher
Returns a new instance of TransactionMatcher.
6 7 8 9 10 11 12 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 6 def initialize(transaction_type) @collector = Collector.new @query_type = transaction_type @message_builder = MessageBuilder.new(self) self.at_least(1) end |
Instance Attribute Details
#collector ⇒ Object (readonly)
Returns the value of attribute collector.
4 5 6 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_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/transaction_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/transaction_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/transaction_matcher.rb', line 4 def query_type @query_type end |
Instance Method Details
#actual_count ⇒ Object
94 95 96 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 94 def actual_count @collector.queries_of_type(@query_type) end |
#exactly(n) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 70 def exactly(n) @quantifier = n @comparison = :exactly @match_method = -> { actual_count == @quantifier } self end |
#failure_message ⇒ Object
14 15 16 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 14 def @message_builder. end |
#failure_message_when_negated ⇒ Object
18 19 20 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 18 def @message_builder. end |
#greater_than(n) ⇒ Object Also known as: more_than
54 55 56 57 58 59 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 54 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
62 63 64 65 66 67 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 62 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
38 39 40 41 42 43 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 38 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
46 47 48 49 50 51 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 46 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
26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 26 def matches?(block) raise NoComparisonError unless @match_method block.call result = @match_method.call @collector.finalize result end |
#once ⇒ Object
77 78 79 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 77 def once exactly(1).time end |
#supports_block_expectations? ⇒ Boolean
22 23 24 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 22 def supports_block_expectations? true end |
#thrice ⇒ Object
hehe
85 86 87 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 85 def thrice # hehe exactly(3).times end |
#times ⇒ Object Also known as: time
89 90 91 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 89 def times self # NOOP end |
#twice ⇒ Object
81 82 83 |
# File 'lib/rspec/activerecord/expectations/matchers/transaction_matcher.rb', line 81 def twice exactly(2).times end |