rspec-mocks 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +104 -36
- data/README.md +35 -4
- data/lib/rspec/mocks.rb +52 -13
- data/lib/rspec/mocks/any_instance.rb +10 -0
- data/lib/rspec/mocks/any_instance/chain.rb +17 -0
- data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -1
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +9 -6
- data/lib/rspec/mocks/any_instance/message_chains.rb +10 -1
- data/lib/rspec/mocks/any_instance/proxy.rb +112 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +49 -18
- data/lib/rspec/mocks/any_instance/stub_chain.rb +5 -3
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +5 -3
- data/lib/rspec/mocks/argument_matchers.rb +28 -12
- data/lib/rspec/mocks/configuration.rb +29 -0
- data/lib/rspec/mocks/error_generator.rb +2 -5
- data/lib/rspec/mocks/example_methods.rb +122 -13
- data/lib/rspec/mocks/instance_method_stasher.rb +26 -2
- data/lib/rspec/mocks/marshal_extension.rb +41 -0
- data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
- data/lib/rspec/mocks/matchers/receive.rb +6 -20
- data/lib/rspec/mocks/matchers/receive_message_chain.rb +7 -5
- data/lib/rspec/mocks/matchers/receive_messages.rb +1 -2
- data/lib/rspec/mocks/message_chain.rb +9 -9
- data/lib/rspec/mocks/message_expectation.rb +6 -5
- data/lib/rspec/mocks/method_double.rb +67 -10
- data/lib/rspec/mocks/method_reference.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +10 -14
- data/lib/rspec/mocks/object_reference.rb +7 -4
- data/lib/rspec/mocks/proxy.rb +95 -8
- data/lib/rspec/mocks/space.rb +58 -9
- data/lib/rspec/mocks/syntax.rb +128 -210
- data/lib/rspec/mocks/targets.rb +6 -8
- data/lib/rspec/mocks/test_double.rb +16 -25
- data/lib/rspec/mocks/verifying_double.rb +15 -12
- data/lib/rspec/mocks/verifying_message_expecation.rb +3 -3
- data/lib/rspec/mocks/verifying_proxy.rb +23 -17
- data/lib/rspec/mocks/version.rb +3 -1
- metadata +29 -257
- metadata.gz.sig +0 -0
- data/features/README.md +0 -75
- data/features/Scope.md +0 -17
- data/features/Upgrade.md +0 -22
- data/features/argument_matchers/README.md +0 -27
- data/features/argument_matchers/explicit.feature +0 -59
- data/features/argument_matchers/general_matchers.feature +0 -85
- data/features/argument_matchers/type_matchers.feature +0 -26
- data/features/message_expectations/README.md +0 -75
- data/features/message_expectations/allow_any_instance_of.feature +0 -26
- data/features/message_expectations/any_instance.feature +0 -43
- data/features/message_expectations/block_local_expectations.feature.pending +0 -55
- data/features/message_expectations/call_original.feature +0 -23
- data/features/message_expectations/expect_message_using_expect.feature +0 -107
- data/features/message_expectations/expect_message_using_should_receive.feature +0 -118
- data/features/message_expectations/message_chains_using_expect.feature +0 -49
- data/features/message_expectations/receive_counts.feature +0 -209
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +0 -50
- data/features/method_stubs/README.md +0 -77
- data/features/method_stubs/allow_any_instance_of.feature +0 -136
- data/features/method_stubs/as_null_object.feature +0 -40
- data/features/method_stubs/receive_message_chain.feature +0 -51
- data/features/method_stubs/simple_return_value_with_allow.feature +0 -44
- data/features/method_stubs/simple_return_value_with_stub.feature +0 -64
- data/features/method_stubs/stub_implementation.feature +0 -48
- data/features/method_stubs/to_ary.feature +0 -51
- data/features/mutating_constants/README.md +0 -82
- data/features/mutating_constants/hiding_defined_constant.feature +0 -64
- data/features/mutating_constants/stub_defined_constant.feature +0 -78
- data/features/mutating_constants/stub_undefined_constant.feature +0 -50
- data/features/outside_rspec/standalone.feature +0 -33
- data/features/spies/spy_partial_mock_method.feature +0 -34
- data/features/spies/spy_pure_mock_method.feature +0 -76
- data/features/spies/spy_unstubbed_method.feature +0 -18
- data/features/step_definitions/additional_cli_steps.rb +0 -11
- data/features/support/env.rb +0 -22
- data/features/support/rubinius.rb +0 -6
- data/features/test_frameworks/test_unit.feature +0 -54
- data/features/verifying_doubles/README.md +0 -17
- data/features/verifying_doubles/class_doubles.feature +0 -73
- data/features/verifying_doubles/dynamic_classes.feature +0 -71
- data/features/verifying_doubles/instance_doubles.feature +0 -103
- data/features/verifying_doubles/object_doubles.feature +0 -65
- data/features/verifying_doubles/partial_doubles.feature +0 -34
- data/lib/rspec/mocks/extensions/marshal.rb +0 -17
- data/lib/rspec/mocks/framework.rb +0 -35
- data/lib/rspec/mocks/method_signature_verifier.rb +0 -207
- data/lib/rspec/mocks/ruby_features.rb +0 -24
- data/spec/rspec/mocks/and_call_original_spec.rb +0 -268
- data/spec/rspec/mocks/and_return_spec.rb +0 -23
- data/spec/rspec/mocks/and_yield_spec.rb +0 -126
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +0 -41
- data/spec/rspec/mocks/any_instance_spec.rb +0 -1045
- data/spec/rspec/mocks/array_including_matcher_spec.rb +0 -41
- data/spec/rspec/mocks/at_least_spec.rb +0 -123
- data/spec/rspec/mocks/at_most_spec.rb +0 -90
- data/spec/rspec/mocks/before_all_spec.rb +0 -132
- data/spec/rspec/mocks/block_return_value_spec.rb +0 -70
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +0 -204
- data/spec/rspec/mocks/configuration_spec.rb +0 -242
- data/spec/rspec/mocks/double_spec.rb +0 -874
- data/spec/rspec/mocks/example_methods_spec.rb +0 -13
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -54
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +0 -184
- data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +0 -67
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +0 -94
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +0 -74
- data/spec/rspec/mocks/matchers/have_received_spec.rb +0 -347
- data/spec/rspec/mocks/matchers/receive_message_chain_spec.rb +0 -198
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +0 -140
- data/spec/rspec/mocks/matchers/receive_spec.rb +0 -418
- data/spec/rspec/mocks/method_signature_verifier_spec.rb +0 -272
- data/spec/rspec/mocks/methods_spec.rb +0 -26
- data/spec/rspec/mocks/mock_expectation_error_spec.rb +0 -22
- data/spec/rspec/mocks/mock_ordering_spec.rb +0 -114
- data/spec/rspec/mocks/multiple_return_value_spec.rb +0 -132
- data/spec/rspec/mocks/mutate_const_spec.rb +0 -542
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +0 -52
- data/spec/rspec/mocks/null_object_mock_spec.rb +0 -133
- data/spec/rspec/mocks/once_counts_spec.rb +0 -52
- data/spec/rspec/mocks/options_hash_spec.rb +0 -35
- data/spec/rspec/mocks/order_group_spec.rb +0 -27
- data/spec/rspec/mocks/partial_double_spec.rb +0 -308
- data/spec/rspec/mocks/partial_double_using_mocks_directly_spec.rb +0 -95
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +0 -145
- data/spec/rspec/mocks/precise_counts_spec.rb +0 -68
- data/spec/rspec/mocks/record_messages_spec.rb +0 -26
- data/spec/rspec/mocks/serialization_spec.rb +0 -90
- data/spec/rspec/mocks/space_spec.rb +0 -244
- data/spec/rspec/mocks/stash_spec.rb +0 -46
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -168
- data/spec/rspec/mocks/stub_implementation_spec.rb +0 -81
- data/spec/rspec/mocks/stub_spec.rb +0 -327
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +0 -58
- data/spec/rspec/mocks/syntax_agnostic_message_matchers_spec.rb +0 -101
- data/spec/rspec/mocks/syntax_spec.rb +0 -19
- data/spec/rspec/mocks/test_double_spec.rb +0 -49
- data/spec/rspec/mocks/to_ary_spec.rb +0 -54
- data/spec/rspec/mocks/twice_counts_spec.rb +0 -66
- data/spec/rspec/mocks/verifying_double_spec.rb +0 -590
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +0 -69
- data/spec/rspec/mocks_spec.rb +0 -192
- data/spec/spec_helper.rb +0 -121
@@ -1,95 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec::Mocks
|
4
|
-
describe "PartialDoubleUsingMocksDirectly" do
|
5
|
-
let(:klass) do
|
6
|
-
Class.new do
|
7
|
-
module MethodMissing
|
8
|
-
remove_method :method_missing rescue nil
|
9
|
-
def method_missing(m, *a, &b)
|
10
|
-
if m == :captured_by_method_missing
|
11
|
-
"response generated by method missing"
|
12
|
-
else
|
13
|
-
super(m, *a, &b)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
extend MethodMissing
|
19
|
-
include MethodMissing
|
20
|
-
|
21
|
-
def existing_method
|
22
|
-
:original_value
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:obj) { klass.new }
|
29
|
-
|
30
|
-
# See http://rubyforge.org/tracker/index.php?func=detail&aid=10263&group_id=797&atid=3149
|
31
|
-
# specify "should clear expectations on verify" do
|
32
|
-
# obj.should_receive(:msg)
|
33
|
-
# obj.msg
|
34
|
-
# verify obj
|
35
|
-
# expect {
|
36
|
-
# obj.msg
|
37
|
-
# }.to raise_error(NoMethodError)
|
38
|
-
#
|
39
|
-
# end
|
40
|
-
it "fails when expected message is not received" do
|
41
|
-
obj.should_receive(:msg)
|
42
|
-
expect {
|
43
|
-
verify obj
|
44
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "fails when message is received with incorrect args" do
|
48
|
-
obj.should_receive(:msg).with(:correct_arg)
|
49
|
-
expect {
|
50
|
-
obj.msg(:incorrect_arg)
|
51
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
52
|
-
obj.msg(:correct_arg)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "passes when expected message is received" do
|
56
|
-
obj.should_receive(:msg)
|
57
|
-
obj.msg
|
58
|
-
verify obj
|
59
|
-
end
|
60
|
-
|
61
|
-
it "passes when message is received with correct args" do
|
62
|
-
obj.should_receive(:msg).with(:correct_arg)
|
63
|
-
obj.msg(:correct_arg)
|
64
|
-
verify obj
|
65
|
-
end
|
66
|
-
|
67
|
-
it "restores the original method if it existed" do
|
68
|
-
expect(obj.existing_method).to equal(:original_value)
|
69
|
-
obj.should_receive(:existing_method).and_return(:mock_value)
|
70
|
-
expect(obj.existing_method).to equal(:mock_value)
|
71
|
-
verify obj
|
72
|
-
expect(obj.existing_method).to equal(:original_value)
|
73
|
-
end
|
74
|
-
|
75
|
-
context "with an instance method handled by method_missing" do
|
76
|
-
it "restores the original behavior" do
|
77
|
-
expect(obj.captured_by_method_missing).to eq("response generated by method missing")
|
78
|
-
obj.stub(:captured_by_method_missing) { "foo" }
|
79
|
-
expect(obj.captured_by_method_missing).to eq("foo")
|
80
|
-
reset obj
|
81
|
-
expect(obj.captured_by_method_missing).to eq("response generated by method missing")
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
context "with a class method handled by method_missing" do
|
86
|
-
it "restores the original behavior" do
|
87
|
-
expect(klass.captured_by_method_missing).to eq("response generated by method missing")
|
88
|
-
klass.stub(:captured_by_method_missing) { "foo" }
|
89
|
-
expect(klass.captured_by_method_missing).to eq("foo")
|
90
|
-
reset klass
|
91
|
-
expect(klass.captured_by_method_missing).to eq("response generated by method missing")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "Passing argument matchers" do
|
6
|
-
before(:each) do
|
7
|
-
@double = double('double')
|
8
|
-
Kernel.stub(:warn)
|
9
|
-
end
|
10
|
-
|
11
|
-
after(:each) do
|
12
|
-
verify @double
|
13
|
-
end
|
14
|
-
|
15
|
-
context "handling argument matchers" do
|
16
|
-
it "accepts true as boolean()" do
|
17
|
-
@double.should_receive(:random_call).with(boolean())
|
18
|
-
@double.random_call(true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "accepts false as boolean()" do
|
22
|
-
@double.should_receive(:random_call).with(boolean())
|
23
|
-
@double.random_call(false)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "accepts fixnum as kind_of(Numeric)" do
|
27
|
-
@double.should_receive(:random_call).with(kind_of(Numeric))
|
28
|
-
@double.random_call(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "accepts float as an_instance_of(Numeric)" do
|
32
|
-
@double.should_receive(:random_call).with(kind_of(Numeric))
|
33
|
-
@double.random_call(1.5)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "accepts fixnum as instance_of(Fixnum)" do
|
37
|
-
@double.should_receive(:random_call).with(instance_of(Fixnum))
|
38
|
-
@double.random_call(1)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "does NOT accept fixnum as instance_of(Numeric)" do
|
42
|
-
@double.should_not_receive(:random_call).with(instance_of(Numeric))
|
43
|
-
@double.random_call(1)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "does NOT accept float as instance_of(Numeric)" do
|
47
|
-
@double.should_not_receive(:random_call).with(instance_of(Numeric))
|
48
|
-
@double.random_call(1.5)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "accepts string as anything()" do
|
52
|
-
@double.should_receive(:random_call).with("a", anything(), "c")
|
53
|
-
@double.random_call("a", "whatever", "c")
|
54
|
-
end
|
55
|
-
|
56
|
-
it "matches duck type with one method" do
|
57
|
-
@double.should_receive(:random_call).with(duck_type(:length))
|
58
|
-
@double.random_call([])
|
59
|
-
end
|
60
|
-
|
61
|
-
it "matches duck type with two methods" do
|
62
|
-
@double.should_receive(:random_call).with(duck_type(:abs, :div))
|
63
|
-
@double.random_call(1)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "matches no args against any_args()" do
|
67
|
-
@double.should_receive(:random_call).with(any_args)
|
68
|
-
@double.random_call()
|
69
|
-
end
|
70
|
-
|
71
|
-
it "matches one arg against any_args()" do
|
72
|
-
@double.should_receive(:random_call).with(any_args)
|
73
|
-
@double.random_call("a string")
|
74
|
-
end
|
75
|
-
|
76
|
-
it "matches no args against no_args()" do
|
77
|
-
@double.should_receive(:random_call).with(no_args)
|
78
|
-
@double.random_call()
|
79
|
-
end
|
80
|
-
|
81
|
-
it "matches hash with hash_including same hash" do
|
82
|
-
@double.should_receive(:random_call).with(hash_including(:a => 1))
|
83
|
-
@double.random_call(:a => 1)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "matches array with array_including same array" do
|
87
|
-
@double.should_receive(:random_call).with(array_including(1,2))
|
88
|
-
@double.random_call([1,2])
|
89
|
-
end
|
90
|
-
|
91
|
-
it "matches any arbitrary object using #===" do
|
92
|
-
matcher = double
|
93
|
-
matcher.should_receive(:===).with(4).and_return(true)
|
94
|
-
|
95
|
-
@double.should_receive(:foo).with(matcher)
|
96
|
-
@double.foo(4)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "handling non-matcher arguments" do
|
101
|
-
it "matches non special symbol (can be removed when deprecated symbols are removed)" do
|
102
|
-
@double.should_receive(:random_call).with(:some_symbol)
|
103
|
-
@double.random_call(:some_symbol)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "matches string against regexp" do
|
107
|
-
@double.should_receive(:random_call).with(/bcd/)
|
108
|
-
@double.random_call("abcde")
|
109
|
-
end
|
110
|
-
|
111
|
-
it "matches regexp against regexp" do
|
112
|
-
@double.should_receive(:random_call).with(/bcd/)
|
113
|
-
@double.random_call(/bcd/)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "matches against a hash submitted and received by value" do
|
117
|
-
@double.should_receive(:random_call).with(:a => "a", :b => "b")
|
118
|
-
@double.random_call(:a => "a", :b => "b")
|
119
|
-
end
|
120
|
-
|
121
|
-
it "matches against a hash submitted by reference and received by value" do
|
122
|
-
opts = {:a => "a", :b => "b"}
|
123
|
-
@double.should_receive(:random_call).with(opts)
|
124
|
-
@double.random_call(:a => "a", :b => "b")
|
125
|
-
end
|
126
|
-
|
127
|
-
it "matches against a hash submitted by value and received by reference" do
|
128
|
-
opts = {:a => "a", :b => "b"}
|
129
|
-
@double.should_receive(:random_call).with(:a => "a", :b => "b")
|
130
|
-
@double.random_call(opts)
|
131
|
-
end
|
132
|
-
|
133
|
-
it "matches a class against itself" do
|
134
|
-
@double.should_receive(:foo).with(Fixnum)
|
135
|
-
@double.foo(Fixnum)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "matches a class against an instance of itself" do
|
139
|
-
@double.should_receive(:foo).with(Fixnum)
|
140
|
-
@double.foo(3)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "PreciseCounts" do
|
6
|
-
before(:each) do
|
7
|
-
@double = double("test double")
|
8
|
-
end
|
9
|
-
|
10
|
-
it "fails when exactly n times method is called less than n times" do
|
11
|
-
@double.should_receive(:do_something).exactly(3).times
|
12
|
-
@double.do_something
|
13
|
-
@double.do_something
|
14
|
-
expect {
|
15
|
-
verify @double
|
16
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "fails fast when exactly n times method is called more than n times" do
|
20
|
-
@double.should_receive(:do_something).exactly(3).times
|
21
|
-
@double.do_something
|
22
|
-
@double.do_something
|
23
|
-
@double.do_something
|
24
|
-
expect {
|
25
|
-
@double.do_something
|
26
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "fails when exactly n times method is never called" do
|
30
|
-
@double.should_receive(:do_something).exactly(3).times
|
31
|
-
expect {
|
32
|
-
verify @double
|
33
|
-
}.to raise_error(RSpec::Mocks::MockExpectationError)
|
34
|
-
end
|
35
|
-
|
36
|
-
it "passes if exactly n times method is called exactly n times" do
|
37
|
-
@double.should_receive(:do_something).exactly(3).times
|
38
|
-
@double.do_something
|
39
|
-
@double.do_something
|
40
|
-
@double.do_something
|
41
|
-
verify @double
|
42
|
-
end
|
43
|
-
|
44
|
-
it "returns the value given by a block when the exactly once method is called" do
|
45
|
-
@double.should_receive(:to_s).exactly(:once) { "testing" }
|
46
|
-
expect(@double.to_s).to eq "testing"
|
47
|
-
verify @double
|
48
|
-
end
|
49
|
-
|
50
|
-
it "passes mutiple calls with different args" do
|
51
|
-
@double.should_receive(:do_something).once.with(1)
|
52
|
-
@double.should_receive(:do_something).once.with(2)
|
53
|
-
@double.do_something(1)
|
54
|
-
@double.do_something(2)
|
55
|
-
verify @double
|
56
|
-
end
|
57
|
-
|
58
|
-
it "passes multiple calls with different args and counts" do
|
59
|
-
@double.should_receive(:do_something).twice.with(1)
|
60
|
-
@double.should_receive(:do_something).once.with(2)
|
61
|
-
@double.do_something(1)
|
62
|
-
@double.do_something(2)
|
63
|
-
@double.do_something(1)
|
64
|
-
verify @double
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "a mock" do
|
6
|
-
before(:each) do
|
7
|
-
@mock = double("mock").as_null_object
|
8
|
-
end
|
9
|
-
it "answers false for received_message? when no messages received" do
|
10
|
-
expect(@mock.received_message?(:message)).to be_falsey
|
11
|
-
end
|
12
|
-
it "answers true for received_message? when message received" do
|
13
|
-
@mock.message
|
14
|
-
expect(@mock.received_message?(:message)).to be_truthy
|
15
|
-
end
|
16
|
-
it "answers true for received_message? when message received with correct args" do
|
17
|
-
@mock.message 1,2,3
|
18
|
-
expect(@mock.received_message?(:message, 1,2,3)).to be_truthy
|
19
|
-
end
|
20
|
-
it "answers false for received_message? when message received with incorrect args" do
|
21
|
-
@mock.message 1,2,3
|
22
|
-
expect(@mock.received_message?(:message, 1,2)).to be_falsey
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "Serialization of mocked objects" do
|
6
|
-
|
7
|
-
class SerializableObject < Struct.new(:foo, :bar); end
|
8
|
-
|
9
|
-
def self.with_yaml_loaded(&block)
|
10
|
-
context 'with YAML loaded' do
|
11
|
-
module_exec(&block)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.without_yaml_loaded(&block)
|
16
|
-
context 'without YAML loaded' do
|
17
|
-
before do
|
18
|
-
# We can't really unload yaml, but we can fake it here...
|
19
|
-
hide_const("YAML")
|
20
|
-
Struct.class_exec do
|
21
|
-
alias __old_to_yaml to_yaml
|
22
|
-
undef to_yaml
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
module_exec(&block)
|
27
|
-
|
28
|
-
after do
|
29
|
-
Struct.class_exec do
|
30
|
-
alias to_yaml __old_to_yaml
|
31
|
-
undef __old_to_yaml
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:serializable_object) { RSpec::Mocks::SerializableObject.new(7, "something") }
|
38
|
-
|
39
|
-
def set_stub
|
40
|
-
serializable_object.stub(:bazz => 5)
|
41
|
-
end
|
42
|
-
|
43
|
-
shared_examples_for 'normal YAML serialization' do
|
44
|
-
it 'serializes to yaml the same with and without stubbing, using #to_yaml' do
|
45
|
-
expect { set_stub }.to_not change { serializable_object.to_yaml }
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'serializes to yaml the same with and without stubbing, using YAML.dump' do
|
49
|
-
expect { set_stub }.to_not change { ::YAML.dump(serializable_object) }
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
with_yaml_loaded do
|
54
|
-
compiled_with_psych = begin
|
55
|
-
require 'psych'
|
56
|
-
true
|
57
|
-
rescue LoadError
|
58
|
-
false
|
59
|
-
end
|
60
|
-
|
61
|
-
if compiled_with_psych
|
62
|
-
context 'using Syck as the YAML engine' do
|
63
|
-
before(:each) { ::YAML::ENGINE.yamler = 'syck' }
|
64
|
-
around(:each) { |example| with_isolated_stderr(&example) }
|
65
|
-
it_behaves_like 'normal YAML serialization'
|
66
|
-
end
|
67
|
-
|
68
|
-
context 'using Psych as the YAML engine' do
|
69
|
-
before(:each) { ::YAML::ENGINE.yamler = 'psych' }
|
70
|
-
it_behaves_like 'normal YAML serialization'
|
71
|
-
end
|
72
|
-
else
|
73
|
-
it_behaves_like 'normal YAML serialization'
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
without_yaml_loaded do
|
78
|
-
it 'does not add #to_yaml to the stubbed object' do
|
79
|
-
expect(serializable_object).not_to respond_to(:to_yaml)
|
80
|
-
set_stub
|
81
|
-
expect(serializable_object).not_to respond_to(:to_yaml)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'marshals the same with and without stubbing' do
|
86
|
-
expect { set_stub }.to_not change { Marshal.dump(serializable_object) }
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,244 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec::Mocks
|
4
|
-
describe Space do
|
5
|
-
let(:space) { Space.new }
|
6
|
-
let(:dbl_1) { Object.new }
|
7
|
-
let(:dbl_2) { Object.new }
|
8
|
-
|
9
|
-
describe "#verify_all" do
|
10
|
-
it "verifies all mocks within" do
|
11
|
-
verifies = []
|
12
|
-
|
13
|
-
space.proxy_for(dbl_1).stub(:verify) { verifies << :dbl_1 }
|
14
|
-
space.proxy_for(dbl_2).stub(:verify) { verifies << :dbl_2 }
|
15
|
-
|
16
|
-
space.verify_all
|
17
|
-
|
18
|
-
expect(verifies).to match_array([:dbl_1, :dbl_2])
|
19
|
-
end
|
20
|
-
|
21
|
-
def define_singleton_method_on_recorder_for(klass, name, &block)
|
22
|
-
recorder = space.any_instance_recorder_for(klass)
|
23
|
-
(class << recorder; self; end).send(:define_method, name, &block)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'verifies all any_instance recorders within' do
|
27
|
-
klass_1, klass_2 = Class.new, Class.new
|
28
|
-
|
29
|
-
verifies = []
|
30
|
-
|
31
|
-
# We can't `stub` a method on the recorder because it defines its own `stub`...
|
32
|
-
define_singleton_method_on_recorder_for(klass_1, :verify) { verifies << :klass_1 }
|
33
|
-
define_singleton_method_on_recorder_for(klass_2, :verify) { verifies << :klass_2 }
|
34
|
-
|
35
|
-
space.verify_all
|
36
|
-
|
37
|
-
expect(verifies).to match_array([:klass_1, :klass_2])
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#reset_all" do
|
42
|
-
it "resets all mocks within" do
|
43
|
-
resets = []
|
44
|
-
|
45
|
-
space.proxy_for(dbl_1).stub(:reset) { resets << :dbl_1 }
|
46
|
-
space.proxy_for(dbl_2).stub(:reset) { resets << :dbl_2 }
|
47
|
-
|
48
|
-
space.reset_all
|
49
|
-
|
50
|
-
expect(resets).to match_array([:dbl_1, :dbl_2])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#proxies_of(klass)" do
|
55
|
-
it 'returns proxies' do
|
56
|
-
space.proxy_for("")
|
57
|
-
expect(space.proxies_of(String).map(&:class)).to eq([PartialDoubleProxy])
|
58
|
-
end
|
59
|
-
|
60
|
-
def create_generations
|
61
|
-
grandparent_class = Class.new
|
62
|
-
parent_class = Class.new(grandparent_class)
|
63
|
-
child_class = Class.new(parent_class)
|
64
|
-
|
65
|
-
grandparent = grandparent_class.new
|
66
|
-
parent = parent_class.new
|
67
|
-
child = child_class.new
|
68
|
-
|
69
|
-
return grandparent, parent, child
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'returns only the proxies whose object is an instance of the given class' do
|
73
|
-
grandparent, parent, child = create_generations
|
74
|
-
|
75
|
-
space.proxy_for(grandparent)
|
76
|
-
|
77
|
-
parent_proxy = space.proxy_for(parent)
|
78
|
-
child_proxy = space.proxy_for(child)
|
79
|
-
|
80
|
-
expect(space.proxies_of(parent.class)).to contain_exactly(parent_proxy, child_proxy)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'looks in the parent space for matching proxies' do
|
84
|
-
_, parent, child = create_generations
|
85
|
-
|
86
|
-
parent_proxy = space.proxy_for(parent)
|
87
|
-
subspace = space.new_scope
|
88
|
-
child_proxy = subspace.proxy_for(child)
|
89
|
-
|
90
|
-
expect(subspace.proxies_of(parent.class)).to contain_exactly(parent_proxy, child_proxy)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'tracks proxies in parent and child space separately' do
|
95
|
-
proxy1 = space.proxy_for(Object.new)
|
96
|
-
subspace = space.new_scope
|
97
|
-
proxy2 = subspace.proxy_for(Object.new)
|
98
|
-
|
99
|
-
expect(space.proxies.values).to include(proxy1)
|
100
|
-
expect(space.proxies.values).not_to include(proxy2)
|
101
|
-
|
102
|
-
expect(subspace.proxies.values).to include(proxy2)
|
103
|
-
expect(subspace.proxies.values).not_to include(proxy1)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "only adds an instance once" do
|
107
|
-
m1 = double("mock1")
|
108
|
-
|
109
|
-
expect {
|
110
|
-
space.ensure_registered(m1)
|
111
|
-
}.to change { space.proxies }
|
112
|
-
|
113
|
-
expect {
|
114
|
-
space.ensure_registered(m1)
|
115
|
-
}.not_to change { space.proxies }
|
116
|
-
end
|
117
|
-
|
118
|
-
[:ensure_registered, :proxy_for].each do |method|
|
119
|
-
describe "##{method}" do
|
120
|
-
define_method :get_proxy do |space, object|
|
121
|
-
space.__send__(method, object)
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'returns the proxy for the given object' do
|
125
|
-
obj1 = Object.new
|
126
|
-
obj2 = Object.new
|
127
|
-
|
128
|
-
expect(get_proxy(space, obj1)).to equal(get_proxy(space, obj1))
|
129
|
-
expect(get_proxy(space, obj2)).to equal(get_proxy(space, obj2))
|
130
|
-
expect(get_proxy(space, obj1)).not_to equal(get_proxy(space, obj2))
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'can stil return a proxy from a parent context' do
|
134
|
-
proxy = get_proxy(space, Object)
|
135
|
-
subspace = space.new_scope
|
136
|
-
|
137
|
-
expect(get_proxy(subspace, Object)).to equal(proxy)
|
138
|
-
end
|
139
|
-
|
140
|
-
it "does not store a parent's proxy in the child space" do
|
141
|
-
get_proxy(space, Object)
|
142
|
-
subspace = space.new_scope
|
143
|
-
|
144
|
-
expect {
|
145
|
-
get_proxy(subspace, Object)
|
146
|
-
}.not_to change { subspace.proxies }.from({})
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
describe "#registered?" do
|
152
|
-
it 'returns true if registered in this space' do
|
153
|
-
space.ensure_registered(Object)
|
154
|
-
expect(space).to be_registered(Object)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'returns true if registered in a parent space' do
|
158
|
-
space.ensure_registered(Object)
|
159
|
-
expect(space.new_scope).to be_registered(Object)
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'returns false if not registered in this or a parent space' do
|
163
|
-
expect(space.new_scope).not_to be_registered(Object)
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
describe "#constant_mutator_for" do
|
168
|
-
it 'returns the mutator for the given const name' do
|
169
|
-
space = RSpec::Mocks.space
|
170
|
-
stub_const("Foo", 3)
|
171
|
-
stub_const("Bar", 4)
|
172
|
-
|
173
|
-
expect(space.constant_mutator_for("Foo")).to equal(space.constant_mutator_for("Foo"))
|
174
|
-
expect(space.constant_mutator_for("Bar")).to equal(space.constant_mutator_for("Bar"))
|
175
|
-
expect(space.constant_mutator_for("Foo")).not_to equal(space.constant_mutator_for("Bar"))
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'can stil return a mutator from a parent context' do
|
179
|
-
space = RSpec::Mocks.space
|
180
|
-
|
181
|
-
stub_const("Foo", 3)
|
182
|
-
mutator = space.constant_mutator_for("Foo")
|
183
|
-
|
184
|
-
in_new_space_scope do
|
185
|
-
subspace = RSpec::Mocks.space
|
186
|
-
expect(subspace.constant_mutator_for("Foo")).to equal(mutator)
|
187
|
-
end
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe "#any_instance_recorder_for" do
|
192
|
-
it 'returns the recorder for the given class' do
|
193
|
-
expect(space.any_instance_recorder_for(String)).to equal(space.any_instance_recorder_for(String))
|
194
|
-
expect(space.any_instance_recorder_for(Symbol)).to equal(space.any_instance_recorder_for(Symbol))
|
195
|
-
expect(space.any_instance_recorder_for(String)).not_to equal(space.any_instance_recorder_for(Symbol))
|
196
|
-
end
|
197
|
-
|
198
|
-
it 'can stil return a recorder from a parent context' do
|
199
|
-
recorder = space.any_instance_recorder_for(String)
|
200
|
-
subspace = space.new_scope
|
201
|
-
|
202
|
-
expect(subspace.any_instance_recorder_for(String)).to equal(recorder)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "does not store a parent's proxy in the child space" do
|
206
|
-
space.any_instance_recorder_for(String)
|
207
|
-
subspace = space.new_scope
|
208
|
-
|
209
|
-
expect {
|
210
|
-
subspace.any_instance_recorder_for(String)
|
211
|
-
}.not_to change { subspace.any_instance_recorders }.from({})
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'can be diffed in a failure when it has references to an error generator via a proxy' do
|
216
|
-
space1 = Space.new
|
217
|
-
space2 = Space.new
|
218
|
-
|
219
|
-
space1.proxy_for("")
|
220
|
-
space2.proxy_for("")
|
221
|
-
|
222
|
-
expect {
|
223
|
-
expect(space1).to eq(space2)
|
224
|
-
}.to raise_error(RSpec::Expectations::ExpectationNotMetError, /Diff/)
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'removes an any_instance_recorder when requested' do
|
228
|
-
klass = Class.new
|
229
|
-
|
230
|
-
space.any_instance_recorder_for(klass)
|
231
|
-
|
232
|
-
expect {
|
233
|
-
space.remove_any_instance_recorder_for(klass)
|
234
|
-
}.to change { space.any_instance_recorders.size }.by(-1)
|
235
|
-
end
|
236
|
-
|
237
|
-
def in_new_space_scope
|
238
|
-
RSpec::Mocks.setup
|
239
|
-
yield
|
240
|
-
ensure
|
241
|
-
RSpec::Mocks.teardown
|
242
|
-
end
|
243
|
-
end
|
244
|
-
end
|