rspec-mocks 2.14.0.rc1 → 2.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +25 -0
- data/features/message_expectations/allow_any_instance_of.feature +26 -0
- data/features/message_expectations/expect_any_instance_of.feature +27 -0
- data/features/message_expectations/expect_message_using_expect.feature +4 -0
- data/features/method_stubs/README.md +28 -2
- data/features/method_stubs/any_instance.feature +5 -1
- data/features/method_stubs/as_null_object.feature +6 -1
- data/features/method_stubs/simple_return_value_with_allow.feature +44 -0
- data/features/method_stubs/{simple_return_value.feature → simple_return_value_with_stub.feature} +0 -0
- data/features/method_stubs/stub_implementation.feature +23 -1
- data/lib/rspec/mocks.rb +35 -0
- data/lib/rspec/mocks/any_instance/chain.rb +27 -18
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +1 -28
- data/lib/rspec/mocks/any_instance/recorder.rb +1 -2
- data/lib/rspec/mocks/any_instance/stub_chain.rb +2 -1
- data/lib/rspec/mocks/error_generator.rb +7 -0
- data/lib/rspec/mocks/extensions/marshal.rb +7 -7
- data/lib/rspec/mocks/matchers/receive.rb +5 -1
- data/lib/rspec/mocks/message_expectation.rb +142 -63
- data/lib/rspec/mocks/method_double.rb +0 -9
- data/lib/rspec/mocks/proxy.rb +0 -5
- data/lib/rspec/mocks/proxy_for_nil.rb +2 -1
- data/lib/rspec/mocks/syntax.rb +15 -5
- data/lib/rspec/mocks/test_double.rb +2 -2
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +26 -0
- data/spec/rspec/mocks/block_return_value_spec.rb +18 -0
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +205 -0
- data/spec/rspec/mocks/extensions/marshal_spec.rb +54 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +10 -0
- data/spec/rspec/mocks/mock_spec.rb +31 -3
- data/spec/rspec/mocks/partial_mock_spec.rb +3 -3
- data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +81 -0
- data/spec/rspec/mocks/test_double_spec.rb +16 -6
- metadata +24 -9
@@ -42,10 +42,34 @@ module RSpec
|
|
42
42
|
verify @double
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
46
|
-
expect
|
45
|
+
it "prevents confusing double-negative expressions involving `never`" do
|
46
|
+
expect {
|
47
|
+
@double.should_not_receive(:not_expected).never
|
48
|
+
}.to raise_error(/trying to negate it again/)
|
49
|
+
end
|
50
|
+
|
51
|
+
def expect_and_return_warning
|
52
|
+
expect(RSpec).to receive(:deprecate).with(/`and_return` on a negative message expectation/)
|
53
|
+
end
|
47
54
|
|
48
|
-
|
55
|
+
it "warns when `should_not_receive().and_return` is used" do
|
56
|
+
expect_and_return_warning
|
57
|
+
@double.should_not_receive(:foo).and_return(1)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "warns when `should_receive().never.and_return` is used" do
|
61
|
+
expect_and_return_warning
|
62
|
+
@double.should_receive(:foo).never.and_return(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "warns when `expect().not_to receive().and_return` is used" do
|
66
|
+
expect_and_return_warning
|
67
|
+
expect(@double).not_to receive(:foo).and_return(1)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "warns when `expect().to receive().never.and_return` is used" do
|
71
|
+
expect_and_return_warning
|
72
|
+
expect(@double).to receive(:foo).never.and_return(1)
|
49
73
|
end
|
50
74
|
|
51
75
|
it "passes when receiving message specified as not to be received with different args" do
|
@@ -92,6 +116,10 @@ module RSpec
|
|
92
116
|
@double.should_not_receive(:not_expected).with("unexpected text")
|
93
117
|
@double.not_expected "really unexpected text"
|
94
118
|
verify @double
|
119
|
+
|
120
|
+
@double.should_receive(:not_expected).with("unexpected text").never
|
121
|
+
@double.not_expected "really unexpected text"
|
122
|
+
verify @double
|
95
123
|
end
|
96
124
|
|
97
125
|
it "allows block to calculate return values" do
|
@@ -36,7 +36,7 @@ module RSpec
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should_not_receive returns a negative message expectation" do
|
39
|
-
expect(object.should_not_receive(:foobar)).to
|
39
|
+
expect(object.should_not_receive(:foobar)).to be_negative
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should_receive mocks out the method" do
|
@@ -55,8 +55,8 @@ module RSpec
|
|
55
55
|
expect(object.foobar(hash[:a])).to equal(1)
|
56
56
|
end
|
57
57
|
|
58
|
-
it "should_receive returns a message expectation" do
|
59
|
-
expect(object.should_receive(:foobar)).
|
58
|
+
it "should_receive returns a positive message expectation" do
|
59
|
+
expect(object.should_receive(:foobar)).not_to be_negative
|
60
60
|
object.foobar
|
61
61
|
end
|
62
62
|
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module RSpec
|
4
|
+
module Mocks
|
5
|
+
|
6
|
+
describe ".allow_message" do
|
7
|
+
let(:subject) { Object.new }
|
8
|
+
|
9
|
+
it "sets up basic message allowance" do
|
10
|
+
expect {
|
11
|
+
::RSpec::Mocks.allow_message(subject, :basic)
|
12
|
+
}.to change {
|
13
|
+
subject.respond_to?(:basic)
|
14
|
+
}.to(true)
|
15
|
+
|
16
|
+
expect(subject.basic).to eq(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets up message allowance with params and return value" do
|
20
|
+
expect {
|
21
|
+
::RSpec::Mocks.allow_message(subject, :x).with(:in).and_return(:out)
|
22
|
+
}.to change {
|
23
|
+
subject.respond_to?(:x)
|
24
|
+
}.to(true)
|
25
|
+
|
26
|
+
expect(subject.x(:in)).to eq(:out)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "supports block implementations" do
|
30
|
+
::RSpec::Mocks.allow_message(subject, :message) { :value }
|
31
|
+
expect(subject.message).to eq(:value)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "does not set an expectation that the message will be received" do
|
35
|
+
::RSpec::Mocks.allow_message(subject, :message)
|
36
|
+
expect { verify subject }.not_to raise_error
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".expect_message" do
|
41
|
+
let(:subject) { Object.new }
|
42
|
+
|
43
|
+
it "sets up basic message expectation, verifies as uncalled" do
|
44
|
+
expect {
|
45
|
+
::RSpec::Mocks.expect_message(subject, :basic)
|
46
|
+
}.to change {
|
47
|
+
subject.respond_to?(:basic)
|
48
|
+
}.to(true)
|
49
|
+
|
50
|
+
expect { verify subject }.to raise_error(RSpec::Mocks::MockExpectationError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "fails if never is specified and the message is called" do
|
54
|
+
expect {
|
55
|
+
::RSpec::Mocks.expect_message(subject, :foo).never
|
56
|
+
subject.foo
|
57
|
+
}.to raise_error(/expected.*0 times/)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "sets up basic message expectation, verifies as called" do
|
61
|
+
::RSpec::Mocks.expect_message(subject, :basic)
|
62
|
+
subject.basic
|
63
|
+
verify subject
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets up message expectation with params and return value" do
|
67
|
+
::RSpec::Mocks.expect_message(subject, :msg).with(:in).and_return(:out)
|
68
|
+
expect(subject.msg(:in)).to eq(:out)
|
69
|
+
verify subject
|
70
|
+
end
|
71
|
+
|
72
|
+
it "accepts a block implementation for the expected message" do
|
73
|
+
::RSpec::Mocks.expect_message(subject, :msg) { :value }
|
74
|
+
expect(subject.msg).to eq(:value)
|
75
|
+
verify subject
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
@@ -31,13 +31,18 @@ module RSpec
|
|
31
31
|
expect { double.foo }.to raise_error(/Mock "MyDouble" received/)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
[[:should, :expect], [:expect], [:should]].each do |syntax|
|
35
|
+
context "with syntax #{syntax.inspect}" do
|
36
|
+
include_context "with syntax", syntax
|
37
|
+
it 'stubs the methods passed in the stubs hash' do
|
38
|
+
double = Module.new do
|
39
|
+
TestDouble.extend_onto(self, "MyDouble", :a => 5, :b => 10)
|
40
|
+
end
|
38
41
|
|
39
|
-
|
40
|
-
|
42
|
+
expect(double.a).to eq(5)
|
43
|
+
expect(double.b).to eq(10)
|
44
|
+
end
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
43
48
|
it 'indicates what type of test double it is in error messages' do
|
@@ -51,6 +56,11 @@ module RSpec
|
|
51
56
|
double = Module.new { TestDouble.extend_onto(self) }
|
52
57
|
expect { double.foo }.to raise_error(/Mock received/)
|
53
58
|
end
|
59
|
+
|
60
|
+
it 'warns of deprecation of :null_object => true' do
|
61
|
+
RSpec.should_receive :deprecate
|
62
|
+
double = Class.new { TestDouble.extend_onto self, 'name', :null_object => true }
|
63
|
+
end
|
54
64
|
end
|
55
65
|
end
|
56
66
|
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 2.14.0
|
4
|
+
prerelease:
|
5
|
+
version: 2.14.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Steven Baker
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-07-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -114,9 +114,11 @@ files:
|
|
114
114
|
- features/argument_matchers/general_matchers.feature
|
115
115
|
- features/argument_matchers/type_matchers.feature
|
116
116
|
- features/message_expectations/README.md
|
117
|
+
- features/message_expectations/allow_any_instance_of.feature
|
117
118
|
- features/message_expectations/any_instance.feature
|
118
119
|
- features/message_expectations/block_local_expectations.feature.pending
|
119
120
|
- features/message_expectations/call_original.feature
|
121
|
+
- features/message_expectations/expect_any_instance_of.feature
|
120
122
|
- features/message_expectations/expect_message_using_expect.feature
|
121
123
|
- features/message_expectations/expect_message_using_should_receive.feature
|
122
124
|
- features/message_expectations/receive_counts.feature
|
@@ -124,7 +126,8 @@ files:
|
|
124
126
|
- features/method_stubs/README.md
|
125
127
|
- features/method_stubs/any_instance.feature
|
126
128
|
- features/method_stubs/as_null_object.feature
|
127
|
-
- features/method_stubs/
|
129
|
+
- features/method_stubs/simple_return_value_with_allow.feature
|
130
|
+
- features/method_stubs/simple_return_value_with_stub.feature
|
128
131
|
- features/method_stubs/stub_chain.feature
|
129
132
|
- features/method_stubs/stub_implementation.feature
|
130
133
|
- features/method_stubs/to_ary.feature
|
@@ -158,8 +161,10 @@ files:
|
|
158
161
|
- spec/rspec/mocks/bug_report_8165_spec.rb
|
159
162
|
- spec/rspec/mocks/bug_report_830_spec.rb
|
160
163
|
- spec/rspec/mocks/bug_report_957_spec.rb
|
164
|
+
- spec/rspec/mocks/combining_implementation_instructions_spec.rb
|
161
165
|
- spec/rspec/mocks/configuration_spec.rb
|
162
166
|
- spec/rspec/mocks/double_spec.rb
|
167
|
+
- spec/rspec/mocks/extensions/marshal_spec.rb
|
163
168
|
- spec/rspec/mocks/failing_argument_matchers_spec.rb
|
164
169
|
- spec/rspec/mocks/hash_excluding_matcher_spec.rb
|
165
170
|
- spec/rspec/mocks/hash_including_matcher_spec.rb
|
@@ -187,6 +192,7 @@ files:
|
|
187
192
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
188
193
|
- spec/rspec/mocks/stub_spec.rb
|
189
194
|
- spec/rspec/mocks/stubbed_message_expectations_spec.rb
|
195
|
+
- spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb
|
190
196
|
- spec/rspec/mocks/test_double_spec.rb
|
191
197
|
- spec/rspec/mocks/to_ary_spec.rb
|
192
198
|
- spec/rspec/mocks/twice_counts_spec.rb
|
@@ -207,20 +213,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
207
213
|
version: '0'
|
208
214
|
segments:
|
209
215
|
- 0
|
210
|
-
hash:
|
216
|
+
hash: 3612137047295133706
|
211
217
|
none: false
|
212
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
219
|
requirements:
|
214
|
-
- - ! '
|
220
|
+
- - ! '>='
|
215
221
|
- !ruby/object:Gem::Version
|
216
|
-
version:
|
222
|
+
version: '0'
|
223
|
+
segments:
|
224
|
+
- 0
|
225
|
+
hash: 3612137047295133706
|
217
226
|
none: false
|
218
227
|
requirements: []
|
219
228
|
rubyforge_project: rspec
|
220
229
|
rubygems_version: 1.8.24
|
221
230
|
signing_key:
|
222
231
|
specification_version: 3
|
223
|
-
summary: rspec-mocks-2.14.0
|
232
|
+
summary: rspec-mocks-2.14.0
|
224
233
|
test_files:
|
225
234
|
- features/README.md
|
226
235
|
- features/Scope.md
|
@@ -230,9 +239,11 @@ test_files:
|
|
230
239
|
- features/argument_matchers/general_matchers.feature
|
231
240
|
- features/argument_matchers/type_matchers.feature
|
232
241
|
- features/message_expectations/README.md
|
242
|
+
- features/message_expectations/allow_any_instance_of.feature
|
233
243
|
- features/message_expectations/any_instance.feature
|
234
244
|
- features/message_expectations/block_local_expectations.feature.pending
|
235
245
|
- features/message_expectations/call_original.feature
|
246
|
+
- features/message_expectations/expect_any_instance_of.feature
|
236
247
|
- features/message_expectations/expect_message_using_expect.feature
|
237
248
|
- features/message_expectations/expect_message_using_should_receive.feature
|
238
249
|
- features/message_expectations/receive_counts.feature
|
@@ -240,7 +251,8 @@ test_files:
|
|
240
251
|
- features/method_stubs/README.md
|
241
252
|
- features/method_stubs/any_instance.feature
|
242
253
|
- features/method_stubs/as_null_object.feature
|
243
|
-
- features/method_stubs/
|
254
|
+
- features/method_stubs/simple_return_value_with_allow.feature
|
255
|
+
- features/method_stubs/simple_return_value_with_stub.feature
|
244
256
|
- features/method_stubs/stub_chain.feature
|
245
257
|
- features/method_stubs/stub_implementation.feature
|
246
258
|
- features/method_stubs/to_ary.feature
|
@@ -274,8 +286,10 @@ test_files:
|
|
274
286
|
- spec/rspec/mocks/bug_report_8165_spec.rb
|
275
287
|
- spec/rspec/mocks/bug_report_830_spec.rb
|
276
288
|
- spec/rspec/mocks/bug_report_957_spec.rb
|
289
|
+
- spec/rspec/mocks/combining_implementation_instructions_spec.rb
|
277
290
|
- spec/rspec/mocks/configuration_spec.rb
|
278
291
|
- spec/rspec/mocks/double_spec.rb
|
292
|
+
- spec/rspec/mocks/extensions/marshal_spec.rb
|
279
293
|
- spec/rspec/mocks/failing_argument_matchers_spec.rb
|
280
294
|
- spec/rspec/mocks/hash_excluding_matcher_spec.rb
|
281
295
|
- spec/rspec/mocks/hash_including_matcher_spec.rb
|
@@ -303,6 +317,7 @@ test_files:
|
|
303
317
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
304
318
|
- spec/rspec/mocks/stub_spec.rb
|
305
319
|
- spec/rspec/mocks/stubbed_message_expectations_spec.rb
|
320
|
+
- spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb
|
306
321
|
- spec/rspec/mocks/test_double_spec.rb
|
307
322
|
- spec/rspec/mocks/to_ary_spec.rb
|
308
323
|
- spec/rspec/mocks/twice_counts_spec.rb
|