Class: Matchi::BeWithin

Inherits:
Object
  • Object
show all
Defined in:
lib/matchi/be_within.rb,
lib/matchi/be_within/of.rb

Overview

Wraps the target of a be_within matcher.

Defined Under Namespace

Classes: Of

Instance Method Summary collapse

Constructor Details

#initialize(delta) ⇒ BeWithin

Initialize a wrapper of the be_within matcher with a numeric value.

Examples:

require "matchi/be_within"

Matchi::BeWithin.new(1)

Parameters:

  • delta (Numeric)

    A numeric value.

Raises:

  • (::ArgumentError)


16
17
18
19
20
21
# File 'lib/matchi/be_within.rb', line 16

def initialize(delta)
  raise ::ArgumentError, "delta must be a Numeric" unless delta.is_a?(::Numeric)
  raise ::ArgumentError, "delta must be non-negative" if delta.negative?

  @delta = delta
end

Instance Method Details

#of(expected) ⇒ #match?

Specifies an expected numeric value.

Examples:

require "matchi/be_within"

be_within_wrapper = Matchi::BeWithin.new(1)
be_within_wrapper.of(41)

Parameters:

  • expected (Numeric)

    The expected value.

Returns:

  • (#match?)

    A *be_within of* matcher.



34
35
36
# File 'lib/matchi/be_within.rb', line 34

def of(expected)
  Of.new(@delta, expected)
end