Class: BeanCounter::TubeExpectation

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bean_counter/tube_expectation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • expected

    [HashSymbol => Numeric, Proc, Range, Regexp, String, Symbol] Options expected when evaluating match.

See Also:



48
49
50
# File 'lib/bean_counter/tube_expectation.rb', line 48

def initialize(expected)
  @expected = expected
end

Instance Attribute Details

#expectedHash (readonly)

The Hash of options given at instantiation that the expectation expects when matching.

Returns:

  • (Hash)


10
11
12
# File 'lib/bean_counter/tube_expectation.rb', line 10

def expected
  @expected
end

#foundStrategy::Tube (readonly)

The tube found by the expecation during matching if one exists.

Returns:

  • (Strategy::Tube)


14
15
16
# File 'lib/bean_counter/tube_expectation.rb', line 14

def found
  @found
end

Instance Method Details

#failure_messageString

Builds the failure message used in the event of a positive expectation failure.

Returns:

  • (String)

    the failure message to be used in the event of a positive expectation failure.



22
23
24
25
# File 'lib/bean_counter/tube_expectation.rb', line 22

def failure_message
  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.

Parameters:

  • given (Object) (defaults to: nil)

    ignored. All expectations should be included in the expected options given at instantiation. Nothing will be infered from the given Object.

Returns:

  • (Boolean)

    If a tube matching the expectation is found, returns true. Otherwise, returns false.

See Also:



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_messageString

Builds the failure message used in the event of a negative expectation failure.

Returns:

  • (String)

    the message to be 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 negative_failure_message
  return '' if found.nil?
  return [
    "expected no tubes matching #{expected.to_s},",
    "found #{strategy.pretty_print_tube(found)}",
  ].join(' ')
end