facon 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Changelog.txt +15 -0
- data/Manifest.txt +1 -0
- data/README.txt +4 -0
- data/lib/facon.rb +1 -1
- data/lib/facon/expectation.rb +10 -1
- data/lib/facon/proxy.rb +1 -0
- data/spec/expectation_spec.rb +63 -2
- metadata +3 -1
data/Changelog.txt
ADDED
@@ -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.
|
data/Manifest.txt
CHANGED
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.
|
data/lib/facon.rb
CHANGED
data/lib/facon/expectation.rb
CHANGED
@@ -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
|
data/lib/facon/proxy.rb
CHANGED
data/spec/expectation_spec.rb
CHANGED
@@ -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.
|
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
|