Class: Mocha::Cardinality

### Home Classes Methods

### In Files

- lib/mocha/cardinality.rb

### Parent

Object

### Methods

- ::at_least
- ::at_most
- ::exactly
- ::new
- ::times
- #allowed_any_number_of_times?
- #infinite?
- #invocations_allowed?
- #mocha_inspect
- #needs_verifying?
- #satisfied?
- #times
- #used?
- #verified?

### Files

- COPYING
- README

### Class/Module Index

Quicksearch

- Mocha
- Mocha::API
- Mocha::AnyInstanceMethod
- Mocha::ArgumentIterator
- Mocha::ArrayMethods
- Mocha::BacktraceFilter
- Mocha::Cardinality
- Mocha::Central
- Mocha::ChangeStateSideEffect
- Mocha::ClassMethod
- Mocha::ClassMethods
- Mocha::Configuration
- Mocha::DateMethods
- Mocha::DefaultName
- Mocha::Deprecation
- Mocha::Expectation
- Mocha::ExpectationError
- Mocha::ExpectationList
- Mocha::HashMethods
- Mocha::ImpersonatingAnyInstanceName
- Mocha::ImpersonatingName
- Mocha::InStateOrderingConstraint
- Mocha::InstanceMethod
- Mocha::Integration
- Mocha::Integration::MiniTest
- Mocha::Integration::MiniTest::AssertionCounter
- Mocha::Integration::MiniTest::Version131AndAbove
- Mocha::Integration::TestUnit
- Mocha::Integration::TestUnit::AssertionCounter
- Mocha::Integration::TestUnit::GemVersion200
- Mocha::Integration::TestUnit::GemVersion201AndAbove
- Mocha::Integration::TestUnit::RubyVersion185AndBelow
- Mocha::Integration::TestUnit::RubyVersion186AndAbove
- Mocha::Logger
- Mocha::MethodMatcher
- Mocha::Mock
- Mocha::Mockery
- Mocha::ModuleMethod
- Mocha::Name
- Mocha::ObjectMethods
- Mocha::ParameterMatchers
- Mocha::ParametersMatcher
- Mocha::PrettyParameters
- Mocha::Sequence
- Mocha::Sequence::InSequenceOrderingConstraint
- Mocha::StateMachine
- Mocha::StringMethods
- Mocha::StubbingError
- Mocha::TimeMethods
- Mocha::UnexpectedInvocation
- MiniTest
- MiniTest::Unit
- MiniTest::Unit::TestCase
- Test
- Test::Unit
- Test::Unit::TestCase
- Array
- Date
- Hash
- Object
- String
- Time

No matching classes.

# Mocha::Cardinality

### Constants

INFINITY

### Attributes

maximum[R]
required[R]

### Public Class Methods

at_least(count) click to toggle source

    # File lib/mocha/cardinality.rb, line 13
    def at_least(count)
      new(count, INFINITY)
    end

at_most(count) click to toggle source

    # File lib/mocha/cardinality.rb, line 17
    def at_most(count)
      new(0, count)
    end

exactly(count) click to toggle source

    # File lib/mocha/cardinality.rb, line 9
    def exactly(count)
      new(count, count)
    end

new(required, maximum) click to toggle source

    # File lib/mocha/cardinality.rb, line 30
    def initialize(required, maximum)
      @required, @maximum = required, maximum
    end

times(range_or_count) click to toggle source

    # File lib/mocha/cardinality.rb, line 21
    def times(range_or_count)
      case range_or_count
        when Range then new(range_or_count.first, range_or_count.last)
        else new(range_or_count, range_or_count)
      end
    end

### Public Instance Methods

allowed_any_number_of_times?() click to toggle source

    # File lib/mocha/cardinality.rb, line 50
    def allowed_any_number_of_times?
      required == 0 && infinite?(maximum)
    end

invocations_allowed?(invocation_count) click to toggle source

    # File lib/mocha/cardinality.rb, line 34
    def invocations_allowed?(invocation_count)
      invocation_count < maximum
    end

mocha_inspect() click to toggle source

    # File lib/mocha/cardinality.rb, line 58
    def mocha_inspect
      if allowed_any_number_of_times?
        "allowed any number of times"
      else
        if required == 0 && maximum == 0
          "expected never"
        elsif required == maximum
          "expected exactly #{times(required)}"
        elsif infinite?(maximum)
          "expected at least #{times(required)}"
        elsif required == 0
          "expected at most #{times(maximum)}"
        else
          "expected between #{required} and #{times(maximum)}"
        end
      end
    end

needs_verifying?() click to toggle source

    # File lib/mocha/cardinality.rb, line 42
    def needs_verifying?
      !allowed_any_number_of_times?
    end

satisfied?(invocations_so_far) click to toggle source

    # File lib/mocha/cardinality.rb, line 38
    def satisfied?(invocations_so_far)
      invocations_so_far >= required
    end

used?(invocation_count) click to toggle source

    # File lib/mocha/cardinality.rb, line 54
    def used?(invocation_count)
      (invocation_count > 0) || (maximum == 0)
    end

verified?(invocation_count) click to toggle source

    # File lib/mocha/cardinality.rb, line 46
    def verified?(invocation_count)
      (invocation_count >= required) && (invocation_count <= maximum)
    end

### Protected Instance Methods

infinite?(number) click to toggle source

    # File lib/mocha/cardinality.rb, line 89
    def infinite?(number)
      number.respond_to?(:infinite?) && number.infinite?
    end

times(number) click to toggle source

    # File lib/mocha/cardinality.rb, line 80
    def times(number)
      case number
        when 0 then "no times"
        when 1 then "once"
        when 2 then "twice"
        else "#{number} times"
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.