Skip to content

Commit

Permalink
Add Cardinality#invocations_never_allowed?
Browse files Browse the repository at this point in the history
I'm planning to use this in a subsequent commit.
  • Loading branch information
floehopper committed Nov 13, 2024
1 parent 19b27d1 commit b24bd4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/mocha/cardinality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def invocations_allowed?
@invocations.size < maximum
end

def invocations_never_allowed?
maximum.zero?
end

def satisfied?
@invocations.size >= required
end
Expand Down
7 changes: 7 additions & 0 deletions test/unit/cardinality_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximu
assert !cardinality.invocations_allowed?
end

def test_should_never_allow_invocations
cardinality = Cardinality.new.exactly(0)
assert cardinality.invocations_never_allowed?
cardinality << new_invocation
assert cardinality.invocations_never_allowed?
end

def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold
cardinality = Cardinality.new(2, 3)
assert !cardinality.satisfied?
Expand Down

0 comments on commit b24bd4e

Please sign in to comment.