Class: BeanCounter::TubeExpectation
- Inherits:
-
Object
- Object
- BeanCounter::TubeExpectation
- Extended by:
- Forwardable
- Defined in:
- lib/bean_counter/tube_expectation.rb
Instance Attribute Summary collapse
-
#expected ⇒ Hash
readonly
The Hash of options given at instantiation that the expectation expects when matching.
-
#found ⇒ Strategy::Tube
readonly
The tube found by the expecation during matching if one exists.
Instance Method Summary collapse
-
#failure_message ⇒ String
Builds the failure message used in the event of a positive expectation failure.
-
#initialize(expected) ⇒ TubeExpectation
constructor
Creates a new tube expectation.
-
#matches?(given = nil) ⇒ Boolean
Checks all tubes in the Beanstalkd pool for a tube matching the expected options hash given during instantiation.
-
#negative_failure_message ⇒ String
Builds the failure message used in the event of a negative expectation failure.
Constructor Details
#initialize(expected) ⇒ TubeExpectation
Creates a new tube expectation. Uses the given expected
Hash to determine
if any tubes exist that match the expected options.
Each key
in the expected
Hash is a String or a Symbol that identifies
an attribute of a tube that the corresponding value
should be compared
against. All attribute comparisons are performed using the triple-equal
(===) operator/method of the given value
.
See Strategy::MATCHABLE_TUBE_ASSERTIONS for a list of those attributes that can be used when matching.
See BeanCounter::TestAssertions and/or SpecMatchers for more information.
48 49 50 |
# File 'lib/bean_counter/tube_expectation.rb', line 48 def initialize(expected) @expected = expected end |
Instance Attribute Details
#expected ⇒ Hash (readonly)
The Hash of options given at instantiation that the expectation expects when matching.
10 11 12 |
# File 'lib/bean_counter/tube_expectation.rb', line 10 def expected @expected end |
#found ⇒ Strategy::Tube (readonly)
The tube found by the expecation during matching if one exists.
14 15 16 |
# File 'lib/bean_counter/tube_expectation.rb', line 14 def found @found end |
Instance Method Details
#failure_message ⇒ String
Builds the failure message used in the event of a positive expectation failure.
22 23 24 25 |
# File 'lib/bean_counter/tube_expectation.rb', line 22 def return '' unless found.nil? return "expected tube matching #{expected.to_s}, found none." end |
#matches?(given = nil) ⇒ Boolean
Checks all tubes in the Beanstalkd pool for a tube matching the expected options hash given during instantiation. The expectation succeeds if any tube exists that matches all of the expected options. If no tube exists matching all of the given options, the expectation fails.
See Strategy::MATCHABLE_TUBE_ATTRIBUTES for a list of those attributes that can be used when matching.
See Strategy#tube_matches? and/or the #tube_matches? method of the strategy in use for more detailed information on how it is determined whether or not a tube matches the options expected.
See also BeanCounter::TestAssertions and/or SpecMatchers for additional information.
76 77 78 79 80 81 82 |
# File 'lib/bean_counter/tube_expectation.rb', line 76 def matches?(given = nil) @found = strategy.tubes.detect do |tube| strategy.tube_matches?(tube, expected) end return !found.nil? end |
#negative_failure_message ⇒ String
Builds the failure message used in the event of a negative expectation failure.
90 91 92 93 94 95 96 |
# File 'lib/bean_counter/tube_expectation.rb', line 90 def return '' if found.nil? return [ "expected no tubes matching #{expected.to_s},", "found #{strategy.pretty_print_tube(found)}", ].join(' ') end |