rspec-mocks 2.10.0 → 2.11.0
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.md +36 -1
- data/README.md +14 -2
- data/features/stubbing_constants/README.md +62 -0
- data/features/stubbing_constants/stub_defined_constant.feature +79 -0
- data/features/stubbing_constants/stub_undefined_constant.feature +50 -0
- data/lib/rspec/mocks/any_instance/chain.rb +0 -81
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +57 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +6 -1
- data/lib/rspec/mocks/any_instance/stub_chain.rb +37 -0
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +25 -0
- data/lib/rspec/mocks/any_instance.rb +37 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +93 -0
- data/lib/rspec/mocks/argument_matchers.rb +39 -31
- data/lib/rspec/mocks/error_generator.rb +7 -0
- data/lib/rspec/mocks/example_methods.rb +41 -0
- data/lib/rspec/mocks/framework.rb +2 -1
- data/lib/rspec/mocks/message_expectation.rb +27 -15
- data/lib/rspec/mocks/methods.rb +4 -0
- data/lib/rspec/mocks/proxy.rb +10 -4
- data/lib/rspec/mocks/stub_const.rb +280 -0
- data/lib/rspec/mocks/test_double.rb +3 -2
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +66 -26
- data/spec/rspec/mocks/argument_expectation_spec.rb +7 -7
- data/spec/rspec/mocks/at_least_spec.rb +89 -50
- data/spec/rspec/mocks/block_return_value_spec.rb +8 -0
- data/spec/rspec/mocks/mock_spec.rb +261 -246
- data/spec/rspec/mocks/multiple_return_value_spec.rb +2 -2
- data/spec/rspec/mocks/null_object_mock_spec.rb +22 -0
- data/spec/rspec/mocks/stub_chain_spec.rb +47 -47
- data/spec/rspec/mocks/stub_const_spec.rb +309 -0
- data/spec/rspec/mocks/stub_spec.rb +2 -2
- data/spec/spec_helper.rb +3 -41
- metadata +18 -6
- data/lib/rspec/mocks/argument_expectation.rb +0 -52
|
@@ -3,100 +3,139 @@ require 'spec_helper'
|
|
|
3
3
|
module RSpec
|
|
4
4
|
module Mocks
|
|
5
5
|
describe "at_least" do
|
|
6
|
-
before(:each)
|
|
7
|
-
@mock = RSpec::Mocks::Mock.new("test mock")
|
|
8
|
-
end
|
|
6
|
+
before(:each) { @double = double }
|
|
9
7
|
|
|
10
8
|
it "fails if method is never called" do
|
|
11
|
-
@
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
@double.should_receive(:do_something).at_least(4).times
|
|
10
|
+
lambda do
|
|
11
|
+
@double.rspec_verify
|
|
14
12
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
|
15
13
|
end
|
|
16
14
|
|
|
17
15
|
it "fails when called less than n times" do
|
|
18
|
-
@
|
|
19
|
-
@
|
|
20
|
-
@
|
|
21
|
-
@
|
|
16
|
+
@double.should_receive(:do_something).at_least(4).times
|
|
17
|
+
@double.do_something
|
|
18
|
+
@double.do_something
|
|
19
|
+
@double.do_something
|
|
22
20
|
lambda do
|
|
23
|
-
@
|
|
21
|
+
@double.rspec_verify
|
|
24
22
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
|
25
23
|
end
|
|
26
24
|
|
|
27
25
|
it "fails when at least once method is never called" do
|
|
28
|
-
@
|
|
26
|
+
@double.should_receive(:do_something).at_least(:once)
|
|
29
27
|
lambda do
|
|
30
|
-
@
|
|
28
|
+
@double.rspec_verify
|
|
31
29
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
|
32
30
|
end
|
|
33
31
|
|
|
34
32
|
it "fails when at least twice method is called once" do
|
|
35
|
-
@
|
|
36
|
-
@
|
|
33
|
+
@double.should_receive(:do_something).at_least(:twice)
|
|
34
|
+
@double.do_something
|
|
37
35
|
lambda do
|
|
38
|
-
@
|
|
36
|
+
@double.rspec_verify
|
|
39
37
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
it "fails when at least twice method is never called" do
|
|
43
|
-
@
|
|
41
|
+
@double.should_receive(:do_something).at_least(:twice)
|
|
44
42
|
lambda do
|
|
45
|
-
@
|
|
43
|
+
@double.rspec_verify
|
|
46
44
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
|
47
45
|
end
|
|
48
46
|
|
|
49
47
|
it "passes when at least n times method is called exactly n times" do
|
|
50
|
-
@
|
|
51
|
-
@
|
|
52
|
-
@
|
|
53
|
-
@
|
|
54
|
-
@
|
|
55
|
-
@
|
|
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
|
+
@double.rspec_verify
|
|
56
54
|
end
|
|
57
55
|
|
|
58
56
|
it "passes when at least n times method is called n plus 1 times" do
|
|
59
|
-
@
|
|
60
|
-
@
|
|
61
|
-
@
|
|
62
|
-
@
|
|
63
|
-
@
|
|
64
|
-
@
|
|
65
|
-
@
|
|
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
|
+
@double.rspec_verify
|
|
66
64
|
end
|
|
67
65
|
|
|
68
66
|
it "passes when at least once method is called once" do
|
|
69
|
-
@
|
|
70
|
-
@
|
|
71
|
-
@
|
|
67
|
+
@double.should_receive(:do_something).at_least(:once)
|
|
68
|
+
@double.do_something
|
|
69
|
+
@double.rspec_verify
|
|
72
70
|
end
|
|
73
71
|
|
|
74
72
|
it "passes when at least once method is called twice" do
|
|
75
|
-
@
|
|
76
|
-
@
|
|
77
|
-
@
|
|
78
|
-
@
|
|
73
|
+
@double.should_receive(:do_something).at_least(:once)
|
|
74
|
+
@double.do_something
|
|
75
|
+
@double.do_something
|
|
76
|
+
@double.rspec_verify
|
|
79
77
|
end
|
|
80
78
|
|
|
81
79
|
it "passes when at least twice method is called three times" do
|
|
82
|
-
@
|
|
83
|
-
@
|
|
84
|
-
@
|
|
85
|
-
@
|
|
86
|
-
@
|
|
80
|
+
@double.should_receive(:do_something).at_least(:twice)
|
|
81
|
+
@double.do_something
|
|
82
|
+
@double.do_something
|
|
83
|
+
@double.do_something
|
|
84
|
+
@double.rspec_verify
|
|
87
85
|
end
|
|
88
86
|
|
|
89
87
|
it "passes when at least twice method is called twice" do
|
|
90
|
-
@
|
|
91
|
-
@
|
|
92
|
-
@
|
|
93
|
-
@
|
|
88
|
+
@double.should_receive(:do_something).at_least(:twice)
|
|
89
|
+
@double.do_something
|
|
90
|
+
@double.do_something
|
|
91
|
+
@double.rspec_verify
|
|
94
92
|
end
|
|
95
93
|
|
|
96
94
|
it "returns the value given by a block when the at least once method is called" do
|
|
97
|
-
@
|
|
98
|
-
@
|
|
99
|
-
@
|
|
95
|
+
@double.should_receive(:to_s).at_least(:once) { "testing" }
|
|
96
|
+
@double.to_s.should eq "testing"
|
|
97
|
+
@double.rspec_verify
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "passes with at_least(0) with no return if called once" do
|
|
101
|
+
@double.should_receive(:do_something).at_least(0).times
|
|
102
|
+
@double.do_something
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it "passes with at_least(0) with return block if called once" do
|
|
106
|
+
@double.should_receive(:do_something).at_least(0).times { true }
|
|
107
|
+
@double.do_something
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "passes with at_least(0) with and_return if called once" do
|
|
111
|
+
@double.should_receive(:do_something).at_least(0).times.and_return true
|
|
112
|
+
@double.do_something
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it "passes with at_least(0) with no return if never called" do
|
|
116
|
+
@double.should_receive(:do_something).at_least(0).times
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it "passes with at_least(0) with return block if never called" do
|
|
120
|
+
@double.should_receive(:do_something).at_least(0).times { true }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it "passes with at_least(0) with and_return if never called" do
|
|
124
|
+
@double.should_receive(:do_something).at_least(0).times.and_return true
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "uses a stub value if no value set" do
|
|
128
|
+
@double.stub(:do_something => 'foo')
|
|
129
|
+
@double.should_receive(:do_something).at_least(:once)
|
|
130
|
+
@double.do_something.should eq 'foo'
|
|
131
|
+
@double.do_something.should eq 'foo'
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
it "prefers its own return value over a stub" do
|
|
135
|
+
@double.stub(:do_something => 'foo')
|
|
136
|
+
@double.should_receive(:do_something).at_least(:once).and_return('bar')
|
|
137
|
+
@double.do_something.should eq 'bar'
|
|
138
|
+
@double.do_something.should eq 'bar'
|
|
100
139
|
end
|
|
101
140
|
end
|
|
102
141
|
end
|
|
@@ -7,6 +7,14 @@ describe "a double declaration with a block handed to:" do
|
|
|
7
7
|
obj.should_receive(:foo) { 'bar' }
|
|
8
8
|
obj.foo.should eq('bar')
|
|
9
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
|
+
obj.foo.should be(return_value)
|
|
17
|
+
end
|
|
10
18
|
end
|
|
11
19
|
|
|
12
20
|
describe "stub" do
|