Class: BeanCounter::TubeExpectation
- Inherits:
-
Object
- Object
- BeanCounter::TubeExpectation
- Extended by:
- Forwardable
- Defined in:
- lib/bean_counter/tube_expectation.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
The value that the expectation expects.
-
#found ⇒ Object
readonly
The tube found by the expecation during matching.
Instance Method Summary collapse
-
#failure_message ⇒ Object
Builds the failure message used in the event of a positive expectation failure.
-
#initialize(expected) ⇒ TubeExpectation
constructor
Create a new tube expectation.
-
#matches?(given = nil) ⇒ Boolean
Checks all tubes in the beanstalkd pool for a tube matching the expected options hash given at instantiation.
-
#negative_failure_message ⇒ Object
Builds the failure message used in the event of a negative expectation failure.
Constructor Details
#initialize(expected) ⇒ TubeExpectation
Create 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 BeanCounter::MiniTest and/or BeanCounter::SpecMatchers for more information.
31 32 33 |
# File 'lib/bean_counter/tube_expectation.rb', line 31 def initialize(expected) @expected = expected end |
Instance Attribute Details
#expected ⇒ Object (readonly)
The value that the expectation expects
8 9 10 |
# File 'lib/bean_counter/tube_expectation.rb', line 8 def expected @expected end |
#found ⇒ Object (readonly)
The tube found by the expecation during matching
11 12 13 |
# File 'lib/bean_counter/tube_expectation.rb', line 11 def found @found end |
Instance Method Details
#failure_message ⇒ Object
Builds the failure message used in the event of a positive expectation failure
16 17 18 19 |
# File 'lib/bean_counter/tube_expectation.rb', line 16 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 at 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#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::MiniTest and/or BeanCounter::SpecMatchers for additional information.
47 48 49 50 51 52 53 |
# File 'lib/bean_counter/tube_expectation.rb', line 47 def matches?(given = nil) @found = strategy.tubes.detect do |tube| strategy.tube_matches?(tube, expected) end return !found.nil? end |
#negative_failure_message ⇒ Object
Builds the failure message used in the event of a negative expectation failure
58 59 60 61 62 63 64 |
# File 'lib/bean_counter/tube_expectation.rb', line 58 def return '' if found.nil? return [ "expected no tubes matching #{expected.to_s},", "found #{strategy.pretty_print_tube(found)}", ].join(' ') end |