File: cardinality_test.rb

package info (click to toggle)
ruby-mocha 0.11.3-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 2,300 kB
  • sloc: ruby: 9,935; makefile: 2
file content (56 lines) | stat: -rw-r--r-- 2,271 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require File.expand_path('../../test_helper', __FILE__)
require 'mocha/cardinality'

class CardinalityTest < Test::Unit::TestCase

  include Mocha

  def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum
    cardinality = Cardinality.new(2, 3)
    assert cardinality.invocations_allowed?(0)
    assert cardinality.invocations_allowed?(1)
    assert cardinality.invocations_allowed?(2)
    assert !cardinality.invocations_allowed?(3)
  end

  def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold
    cardinality = Cardinality.new(2, 3)
    assert !cardinality.satisfied?(0)
    assert !cardinality.satisfied?(1)
    assert cardinality.satisfied?(2)
    assert cardinality.satisfied?(3)
  end

  def test_should_describe_cardinality
    assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect

    assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect
    assert_equal 'expected at most twice', Cardinality.at_most(2).mocha_inspect
    assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect

    assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect
    assert_equal 'expected at least twice', Cardinality.at_least(2).mocha_inspect
    assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect

    assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect
    assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect
    assert_equal 'expected exactly twice', Cardinality.exactly(2).mocha_inspect
    assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect

    assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect
    assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect
  end

  def test_should_need_verifying
    assert Cardinality.exactly(2).needs_verifying?
    assert Cardinality.at_least(3).needs_verifying?
    assert Cardinality.at_most(2).needs_verifying?
    assert Cardinality.times(4).needs_verifying?
    assert Cardinality.times(2..4).needs_verifying?
  end

  def test_should_not_need_verifying
    assert_equal false, Cardinality.at_least(0).needs_verifying?
  end

end