Class: RSpec::Matchers::BuiltIn::BeBetween Private

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/matchers/built_in/be_between.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation for be_between. Not intended to be instantiated directly.

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

RSpec::Matchers::BuiltIn::BaseMatcher::UNDEFINED

Instance Method Summary (collapse)

Methods inherited from BaseMatcher

#diffable?, #expects_call_stack_jump?, #failure_message_when_negated, #match_unless_raises, #supports_block_expectations?

Methods included from Composable

#===, #and, #description_of, enumerable?, #or, surface_descriptions_in, #values_match?

Methods included from Pretty

#name, split_words, #to_sentence, #to_word

Constructor Details

- (BeBetween) initialize(min, max)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BeBetween



8
9
10
11
# File 'lib/rspec/matchers/built_in/be_between.rb', line 8

def initialize(min, max)
  @min, @max = min, max
  inclusive
end

Instance Method Details

- (String) description

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
# File 'lib/rspec/matchers/built_in/be_between.rb', line 57

def description
  "be between #{@min.inspect} and #{@max.inspect} (#{@mode})"
end

- (Object) exclusive

Makes the between comparison exclusive.

Examples:

expect(3).to be_between(2, 4).exclusive


33
34
35
36
37
38
# File 'lib/rspec/matchers/built_in/be_between.rb', line 33

def exclusive
  @less_than_operator = :<
  @greater_than_operator = :>
  @mode = :exclusive
  self
end

- (String) failure_message

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



51
52
53
# File 'lib/rspec/matchers/built_in/be_between.rb', line 51

def failure_message
  "#{super}#{not_comparable_clause}"
end

- (Object) inclusive

Note:

The matcher is inclusive by default; this simply provides a way to be more explicit about it.

Makes the between comparison inclusive.

Examples:

expect(3).to be_between(2, 3).inclusive


21
22
23
24
25
26
# File 'lib/rspec/matchers/built_in/be_between.rb', line 21

def inclusive
  @less_than_operator = :<=
  @greater_than_operator = :>=
  @mode = :inclusive
  self
end

- (Boolean) matches?(actual)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
45
46
47
# File 'lib/rspec/matchers/built_in/be_between.rb', line 42

def matches?(actual)
  @actual = actual
  comparable? && compare
rescue ArgumentError
  false
end