changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/mocks/precise_counts_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3module Spec
4 module Mocks
5 describe "PreciseCounts" do
6 before(:each) do
7 @mock = mock("test mock")
8 end
9
10 it "should fail when exactly n times method is called less than n times" do
11 @mock.should_receive(:random_call).exactly(3).times
12 @mock.random_call
13 @mock.random_call
14 lambda do
15 @mock.rspec_verify
16 end.should raise_error(MockExpectationError)
17 end
18
19 it "should fail when exactly n times method is never called" do
20 @mock.should_receive(:random_call).exactly(3).times
21 lambda do
22 @mock.rspec_verify
23 end.should raise_error(MockExpectationError)
24 end
25
26 it "should pass if exactly n times method is called exactly n times" do
27 @mock.should_receive(:random_call).exactly(3).times
28 @mock.random_call
29 @mock.random_call
30 @mock.random_call
31 @mock.rspec_verify
32 end
33
34 it "should pass multiple calls with different args and counts" do
35 @mock.should_receive(:random_call).twice.with(1)
36 @mock.should_receive(:random_call).once.with(2)
37 @mock.random_call(1)
38 @mock.random_call(2)
39 @mock.random_call(1)
40 @mock.rspec_verify
41 end
42
43 it "should pass mutiple calls with different args" do
44 @mock.should_receive(:random_call).once.with(1)
45 @mock.should_receive(:random_call).once.with(2)
46 @mock.random_call(1)
47 @mock.random_call(2)
48 @mock.rspec_verify
49 end
50 end
51 end
52end