facon 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ === 0.4.1 / 2008-12-05
2
+
3
+ * Added #times, #once and #never expectation matchers. Thanks raggi!
4
+ E.g.
5
+ @mock.should.receive(:call_me_thrice).times(3)
6
+ @mock.should.receive(:just_this_1_time).once
7
+ @mock.should.receive(:dont_even_think_about_it).never
8
+
9
+ === 0.4.0 / 2008-12-05
10
+
11
+ * Fix compatibility with Bacon 1.0 and 1.1.
12
+
13
+ === 0.3.1 / 2008-02-19
14
+
15
+ * Fixed a bug where mocks were not being teared down when there is a previous spec failure.
@@ -1,3 +1,4 @@
1
+ Changelog.txt
1
2
  History.txt
2
3
  Manifest.txt
3
4
  README.txt
data/README.txt CHANGED
@@ -73,6 +73,10 @@ You can get the latest trunk from the Git repository on Github:
73
73
  * Throw away unnecessary code.
74
74
  * Implement exactly, at_least, at_most expectations.
75
75
 
76
+ == Contributors
77
+
78
+ * raggi (http://blog.ra66i.org/) for #times, #once, #never expectation matchers.
79
+
76
80
  == Thanks to
77
81
 
78
82
  * RSpec (http://rspec.info/) for creating spec/mocks, from which a lot of the code for Facon is stolen.
@@ -12,5 +12,5 @@ require 'facon/core_ext/object'
12
12
  # Facon is a mocking library in the spirit of the Bacon spec library. Small,
13
13
  # compact, and works with Bacon.
14
14
  module Facon
15
- VERSION = '0.4.0'
15
+ VERSION = '0.4.1'
16
16
  end
@@ -67,7 +67,7 @@ module Facon
67
67
  nil
68
68
  end
69
69
 
70
- if @return_block
70
+ if defined?(@return_block) && @return_block
71
71
  args << block unless block.nil?
72
72
  @return_block.call(*args)
73
73
  else
@@ -103,6 +103,15 @@ module Facon
103
103
  false
104
104
  end
105
105
 
106
+ def times(val)
107
+ @expected_received_count = val
108
+ self
109
+ end
110
+
111
+ def once; times(1); end
112
+
113
+ def never; times(0); end
114
+
106
115
  private
107
116
  def check_arguments(args)
108
117
  case @argument_expectation
@@ -12,6 +12,7 @@ module Facon
12
12
  @stubs = []
13
13
  @proxied_methods = []
14
14
  @error_generator = ErrorGenerator.new(target, name)
15
+ @expectation_ordering = nil unless defined?(@expectation_ordering)
15
16
  end
16
17
 
17
18
  def add_stub(expected_from, method)
@@ -31,7 +31,7 @@ describe "A mock object" do
31
31
  @mock.should_not_receive(:not_expected)
32
32
  @mock.not_expected
33
33
 
34
- lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it 1 time"
34
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :not_expected with (any args) 0 times, but received it 1 time"
35
35
  end
36
36
 
37
37
  it "should raise a MockExpectationError when receiving message specified as not to be received with arguments" do
@@ -114,11 +114,72 @@ describe "A mock object" do
114
114
  end.and_return(:that)
115
115
  }.should.raise(Facon::MockExpectationError).message.should == 'Ambiguous return expectation'
116
116
  end
117
- end
118
117
 
118
+ it "should pass when receiving a message the expected number of times" do
119
+ @mock.should_receive(:message).times(3)
119
120
 
121
+ 3.times do
122
+ @mock.message
123
+ end
124
+
125
+ verify_mock
126
+ end
127
+
128
+ it "should raise a MockExpectationError when receiving a message < expected number of times" do
129
+ @mock.should_receive(:message).times(3)
130
+
131
+ 1.times do
132
+ @mock.message
133
+ end
134
+
135
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :message with (any args) 3 times, but received it 1 time"
136
+ end
137
+
138
+ it "should raise a MockExpectationError when receiving a message > expected number of times" do
139
+ @mock.should_receive(:message).times(3)
140
+
141
+ 5.times do
142
+ @mock.message
143
+ end
144
+
145
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :message with (any args) 3 times, but received it 5 times"
146
+ end
147
+
148
+ it "should pass when receiving a message once as expected" do
149
+ @mock.should.receive(:message).once
120
150
 
151
+ @mock.message
121
152
 
153
+ verify_mock
154
+ end
155
+
156
+ it "should raise a MockExpectationError when never receiving a message but expecting it once" do
157
+ @mock.should.receive(:message).once
158
+
159
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :message with (any args) 1 time, but received it 0 times"
160
+ end
161
+
162
+ it "should raise a MockExpectationError when receiving a message more than once but expecting it once" do
163
+ @mock.should.receive(:message).once
122
164
 
165
+ 2.times do
166
+ @mock.message
167
+ end
123
168
 
169
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :message with (any args) 1 time, but received it 2 times"
170
+ end
124
171
 
172
+ it "should pass when never receiving a message as expected" do
173
+ @mock.should.receive(:message).never
174
+
175
+ verify_mock
176
+ end
177
+
178
+ it "should raise a MockExpectationError when receiving a message but never expecting it" do
179
+ @mock.should.receive(:message).never
180
+
181
+ @mock.message
182
+
183
+ lambda { @mock.spec_verify }.should.raise(Facon::MockExpectationError).message.should == "Mock 'test mock' expected :message with (any args) 0 times, but received it 1 time"
184
+ end
185
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cheah Chu Yeow
@@ -29,10 +29,12 @@ executables: []
29
29
  extensions: []
30
30
 
31
31
  extra_rdoc_files:
32
+ - Changelog.txt
32
33
  - History.txt
33
34
  - Manifest.txt
34
35
  - README.txt
35
36
  files:
37
+ - Changelog.txt
36
38
  - History.txt
37
39
  - Manifest.txt
38
40
  - README.txt