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,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
module ArgumentMatchers
|
6
|
-
describe ArrayIncludingMatcher do
|
7
|
-
it "describes itself properly" do
|
8
|
-
expect(ArrayIncludingMatcher.new([1, 2, 3]).description).to eq "array_including(1,2,3)"
|
9
|
-
end
|
10
|
-
|
11
|
-
context "passing" do
|
12
|
-
it "matches the same array" do
|
13
|
-
expect(array_including(1, 2, 3)).to be === [1, 2, 3]
|
14
|
-
end
|
15
|
-
|
16
|
-
it "matches the same array, specified without square brackets" do
|
17
|
-
expect(array_including(1, 2, 3)).to be === [1, 2, 3]
|
18
|
-
end
|
19
|
-
|
20
|
-
it "matches the same array, which includes nested arrays" do
|
21
|
-
expect(array_including([1, 2], 3, 4)).to be === [[1, 2], 3, 4]
|
22
|
-
end
|
23
|
-
|
24
|
-
it "works with duplicates in expected" do
|
25
|
-
expect(array_including(1, 1, 2, 3)).to be === [1, 2, 3]
|
26
|
-
end
|
27
|
-
|
28
|
-
it "works with duplicates in actual" do
|
29
|
-
expect(array_including(1, 2, 3)).to be === [1, 1, 2, 3]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
context "failing" do
|
34
|
-
it "fails when not all the entries in the expected are present" do
|
35
|
-
expect(array_including(1,2,3,4,5)).not_to be === [1,2]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,123 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "at_least" do
|
6
|
-
before(:each) { @double = double }
|
7
|
-
|
8
|
-
it "fails if method is never called" do
|
9
|
-
@double.should_receive(:do_something).at_least(4).times
|
10
|
-
expect {
|
11
|
-
verify @double
|
12
|
-
}.to raise_error(/expected: at least 4 times.*received: 0 times/m)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "fails when called less than n times" do
|
16
|
-
@double.should_receive(:do_something).at_least(4).times
|
17
|
-
@double.do_something
|
18
|
-
@double.do_something
|
19
|
-
@double.do_something
|
20
|
-
expect {
|
21
|
-
verify @double
|
22
|
-
}.to raise_error(/expected: at least 4 times.*received: 3 times/m)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "fails when at least once method is never called" do
|
26
|
-
@double.should_receive(:do_something).at_least(:once)
|
27
|
-
expect {
|
28
|
-
verify @double
|
29
|
-
}.to raise_error(/expected: at least 1 time.*received: 0 times/m)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "fails when at least twice method is called once" do
|
33
|
-
@double.should_receive(:do_something).at_least(:twice)
|
34
|
-
@double.do_something
|
35
|
-
expect {
|
36
|
-
verify @double
|
37
|
-
}.to raise_error(/expected: at least 2 times.*received: 1 time/m)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "fails when at least twice method is never called" do
|
41
|
-
@double.should_receive(:do_something).at_least(:twice)
|
42
|
-
expect {
|
43
|
-
verify @double
|
44
|
-
}.to raise_error(/expected: at least 2 times.*received: 0 times/m)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "passes when at least n times method is called exactly n times" do
|
48
|
-
@double.should_receive(:do_something).at_least(4).times
|
49
|
-
@double.do_something
|
50
|
-
@double.do_something
|
51
|
-
@double.do_something
|
52
|
-
@double.do_something
|
53
|
-
verify @double
|
54
|
-
end
|
55
|
-
|
56
|
-
it "passes when at least n times method is called n plus 1 times" do
|
57
|
-
@double.should_receive(:do_something).at_least(4).times
|
58
|
-
@double.do_something
|
59
|
-
@double.do_something
|
60
|
-
@double.do_something
|
61
|
-
@double.do_something
|
62
|
-
@double.do_something
|
63
|
-
verify @double
|
64
|
-
end
|
65
|
-
|
66
|
-
it "passes when at least once method is called once" do
|
67
|
-
@double.should_receive(:do_something).at_least(:once)
|
68
|
-
@double.do_something
|
69
|
-
verify @double
|
70
|
-
end
|
71
|
-
|
72
|
-
it "passes when at least once method is called twice" do
|
73
|
-
@double.should_receive(:do_something).at_least(:once)
|
74
|
-
@double.do_something
|
75
|
-
@double.do_something
|
76
|
-
verify @double
|
77
|
-
end
|
78
|
-
|
79
|
-
it "passes when at least twice method is called three times" do
|
80
|
-
@double.should_receive(:do_something).at_least(:twice)
|
81
|
-
@double.do_something
|
82
|
-
@double.do_something
|
83
|
-
@double.do_something
|
84
|
-
verify @double
|
85
|
-
end
|
86
|
-
|
87
|
-
it "passes when at least twice method is called twice" do
|
88
|
-
@double.should_receive(:do_something).at_least(:twice)
|
89
|
-
@double.do_something
|
90
|
-
@double.do_something
|
91
|
-
verify @double
|
92
|
-
end
|
93
|
-
|
94
|
-
it "returns the value given by a block when the at least once method is called" do
|
95
|
-
@double.should_receive(:to_s).at_least(:once) { "testing" }
|
96
|
-
expect(@double.to_s).to eq "testing"
|
97
|
-
verify @double
|
98
|
-
end
|
99
|
-
|
100
|
-
context "when sent with 0" do
|
101
|
-
it "outputs a removal message" do
|
102
|
-
expect {
|
103
|
-
expect(@double).to receive(:do_something).at_least(0).times
|
104
|
-
}.to raise_error(/has been removed/)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it "uses a stub value if no value set" do
|
109
|
-
@double.stub(:do_something => 'foo')
|
110
|
-
@double.should_receive(:do_something).at_least(:once)
|
111
|
-
expect(@double.do_something).to eq 'foo'
|
112
|
-
expect(@double.do_something).to eq 'foo'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "prefers its own return value over a stub" do
|
116
|
-
@double.stub(:do_something => 'foo')
|
117
|
-
@double.should_receive(:do_something).at_least(:once).and_return('bar')
|
118
|
-
expect(@double.do_something).to eq 'bar'
|
119
|
-
expect(@double.do_something).to eq 'bar'
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module RSpec
|
4
|
-
module Mocks
|
5
|
-
describe "at_most" do
|
6
|
-
before(:each) do
|
7
|
-
@double = double
|
8
|
-
end
|
9
|
-
|
10
|
-
it "passes when at_most(n) is called exactly n times" do
|
11
|
-
@double.should_receive(:do_something).at_most(2).times
|
12
|
-
@double.do_something
|
13
|
-
@double.do_something
|
14
|
-
verify @double
|
15
|
-
end
|
16
|
-
|
17
|
-
it "passes when at_most(n) is called less than n times" do
|
18
|
-
@double.should_receive(:do_something).at_most(2).times
|
19
|
-
@double.do_something
|
20
|
-
verify @double
|
21
|
-
end
|
22
|
-
|
23
|
-
it "passes when at_most(n) is never called" do
|
24
|
-
@double.should_receive(:do_something).at_most(2).times
|
25
|
-
verify @double
|
26
|
-
end
|
27
|
-
|
28
|
-
it "passes when at_most(:once) is called once" do
|
29
|
-
@double.should_receive(:do_something).at_most(:once)
|
30
|
-
@double.do_something
|
31
|
-
verify @double
|
32
|
-
end
|
33
|
-
|
34
|
-
it "passes when at_most(:once) is never called" do
|
35
|
-
@double.should_receive(:do_something).at_most(:once)
|
36
|
-
verify @double
|
37
|
-
end
|
38
|
-
|
39
|
-
it "passes when at_most(:twice) is called once" do
|
40
|
-
@double.should_receive(:do_something).at_most(:twice)
|
41
|
-
@double.do_something
|
42
|
-
verify @double
|
43
|
-
end
|
44
|
-
|
45
|
-
it "passes when at_most(:twice) is called twice" do
|
46
|
-
@double.should_receive(:do_something).at_most(:twice)
|
47
|
-
@double.do_something
|
48
|
-
@double.do_something
|
49
|
-
verify @double
|
50
|
-
end
|
51
|
-
|
52
|
-
it "passes when at_most(:twice) is never called" do
|
53
|
-
@double.should_receive(:do_something).at_most(:twice)
|
54
|
-
verify @double
|
55
|
-
end
|
56
|
-
|
57
|
-
it "returns the value given by a block when at_most(:once) method is called" do
|
58
|
-
@double.should_receive(:to_s).at_most(:once) { "testing" }
|
59
|
-
expect(@double.to_s).to eq "testing"
|
60
|
-
verify @double
|
61
|
-
end
|
62
|
-
|
63
|
-
it "fails fast when at_most(n) times method is called n plus 1 times" do
|
64
|
-
@double.should_receive(:do_something).at_most(2).times
|
65
|
-
@double.do_something
|
66
|
-
@double.do_something
|
67
|
-
expect {
|
68
|
-
@double.do_something
|
69
|
-
}.to raise_error(/expected: at most 2 times.*received: 3 times/m)
|
70
|
-
end
|
71
|
-
|
72
|
-
it "fails fast when at_most(:once) and is called twice" do
|
73
|
-
@double.should_receive(:do_something).at_most(:once)
|
74
|
-
@double.do_something
|
75
|
-
expect {
|
76
|
-
@double.do_something
|
77
|
-
}.to raise_error(/expected: at most 1 time.*received: 2 times/m)
|
78
|
-
end
|
79
|
-
|
80
|
-
it "fails fast when at_most(:twice) and is called three times" do
|
81
|
-
@double.should_receive(:do_something).at_most(:twice)
|
82
|
-
@double.do_something
|
83
|
-
@double.do_something
|
84
|
-
expect {
|
85
|
-
@double.do_something
|
86
|
-
}.to raise_error(/expected: at most 2 times.*received: 3 times/m)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "Using rspec-mocks features in before(:all) blocks" do
|
4
|
-
shared_examples_for "fails in a before(:all) block" do
|
5
|
-
the_error = nil
|
6
|
-
before(:all) do
|
7
|
-
begin
|
8
|
-
use_rspec_mocks
|
9
|
-
rescue
|
10
|
-
the_error = $!
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
it "raises an error with a useful message" do
|
15
|
-
expect(the_error).to be_a_kind_of(RSpec::Mocks::OutsideOfExampleError)
|
16
|
-
|
17
|
-
expect(the_error.message).to match(/The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported./)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#stub_const" do
|
22
|
-
include_examples "fails in a before(:all) block" do
|
23
|
-
def use_rspec_mocks
|
24
|
-
stub_const("SomeNewConst", Class.new)
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'does not stub the const' do
|
28
|
-
expect(defined?(SomeNewConst)).to be_falsey
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#hide_const(for an undefined const)" do
|
34
|
-
include_examples "fails in a before(:all) block" do
|
35
|
-
def use_rspec_mocks
|
36
|
-
hide_const("Foo")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#hide_const(for a defined const)" do
|
42
|
-
include_examples "fails in a before(:all) block" do
|
43
|
-
def use_rspec_mocks
|
44
|
-
hide_const("Float")
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'does not hide the const' do
|
48
|
-
expect(defined?(Float)).to be_truthy
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#stub" do
|
54
|
-
include_examples "fails in a before(:all) block" do
|
55
|
-
def use_rspec_mocks
|
56
|
-
Object.stub(:foo)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "#unstub" do
|
62
|
-
include_examples "fails in a before(:all) block" do
|
63
|
-
def use_rspec_mocks
|
64
|
-
Object.unstub(:foo)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe "#should_receive" do
|
70
|
-
include_examples "fails in a before(:all) block" do
|
71
|
-
def use_rspec_mocks
|
72
|
-
Object.should_receive(:foo)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#should_not_receive" do
|
78
|
-
include_examples "fails in a before(:all) block" do
|
79
|
-
def use_rspec_mocks
|
80
|
-
Object.should_not_receive(:foo)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#any_instance" do
|
86
|
-
include_examples "fails in a before(:all) block" do
|
87
|
-
def use_rspec_mocks
|
88
|
-
Object.any_instance.should_receive(:foo)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
describe "#stub_chain" do
|
94
|
-
include_examples "fails in a before(:all) block" do
|
95
|
-
def use_rspec_mocks
|
96
|
-
Object.stub_chain(:foo)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "#expect(...).to receive" do
|
102
|
-
include_examples "fails in a before(:all) block" do
|
103
|
-
def use_rspec_mocks
|
104
|
-
expect(Object).to receive(:foo)
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "#allow(...).to receive" do
|
110
|
-
include_examples "fails in a before(:all) block" do
|
111
|
-
def use_rspec_mocks
|
112
|
-
allow(Object).to receive(:foo)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#expect_any_instance_of(...).to receive" do
|
118
|
-
include_examples "fails in a before(:all) block" do
|
119
|
-
def use_rspec_mocks
|
120
|
-
expect_any_instance_of(Object).to receive(:foo)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe "#allow_any_instance_of(...).to receive" do
|
126
|
-
include_examples "fails in a before(:all) block" do
|
127
|
-
def use_rspec_mocks
|
128
|
-
allow_any_instance_of(Object).to receive(:foo)
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe "a double declaration with a block handed to:" do
|
4
|
-
describe "should_receive" do
|
5
|
-
it "returns the value of executing the block" do
|
6
|
-
obj = Object.new
|
7
|
-
obj.should_receive(:foo) { 'bar' }
|
8
|
-
expect(obj.foo).to eq('bar')
|
9
|
-
end
|
10
|
-
|
11
|
-
it "works when a multi-return stub has already been set" do
|
12
|
-
obj = Object.new
|
13
|
-
return_value = Object.new
|
14
|
-
obj.stub(:foo).and_return(return_value, nil)
|
15
|
-
obj.should_receive(:foo) { return_value }
|
16
|
-
expect(obj.foo).to be(return_value)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe "stub" do
|
21
|
-
it "returns the value of executing the block" do
|
22
|
-
obj = Object.new
|
23
|
-
obj.stub(:foo) { 'bar' }
|
24
|
-
expect(obj.foo).to eq('bar')
|
25
|
-
end
|
26
|
-
|
27
|
-
# The "receives a block" part is important: 1.8.7 has a bug that reports the
|
28
|
-
# wrong arity when a block receives a block.
|
29
|
-
it 'forwards all given args to the block, even when it receives a block' do
|
30
|
-
obj = Object.new
|
31
|
-
yielded_args = []
|
32
|
-
eval("obj.stub(:foo) { |*args, &bl| yielded_args << args }")
|
33
|
-
obj.foo(1, 2, 3)
|
34
|
-
|
35
|
-
expect(yielded_args).to eq([[1, 2, 3]])
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe "with" do
|
40
|
-
it "returns the value of executing the block" do
|
41
|
-
obj = Object.new
|
42
|
-
obj.stub(:foo).with('baz') { 'bar' }
|
43
|
-
expect(obj.foo('baz')).to eq('bar')
|
44
|
-
end
|
45
|
-
|
46
|
-
it "returns the value of executing the block with given argument" do
|
47
|
-
obj = Object.new
|
48
|
-
obj.stub(:foo).with('baz') {|x| 'bar' + x }
|
49
|
-
expect(obj.foo('baz')).to eq('barbaz')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
%w[once twice ordered].each do |method|
|
54
|
-
describe method do
|
55
|
-
it "returns the value of executing the block" do
|
56
|
-
obj = Object.new
|
57
|
-
obj.stub(:foo).send(method) { 'bar' }
|
58
|
-
expect(obj.foo).to eq('bar')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe "times" do
|
64
|
-
it "returns the value of executing the block" do
|
65
|
-
obj = Object.new
|
66
|
-
obj.stub(:foo).at_least(1).times { 'bar' }
|
67
|
-
expect(obj.foo('baz')).to eq('bar')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|