rspec-mocks 2.99.4 → 3.0.0.beta1
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.
- checksums.yaml +14 -6
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +1 -0
- data/Changelog.md +89 -105
- data/License.txt +1 -0
- data/README.md +77 -57
- data/features/argument_matchers/explicit.feature +5 -5
- data/features/argument_matchers/general_matchers.feature +10 -10
- data/features/argument_matchers/type_matchers.feature +3 -3
- data/features/message_expectations/allow_any_instance_of.feature +1 -1
- data/features/message_expectations/any_instance.feature +27 -5
- data/features/message_expectations/call_original.feature +2 -2
- data/features/message_expectations/expect_message_using_expect.feature +2 -2
- data/features/message_expectations/expect_message_using_should_receive.feature +2 -2
- data/features/message_expectations/receive_counts.feature +7 -7
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
- data/features/method_stubs/README.md +3 -0
- data/features/method_stubs/any_instance.feature +11 -11
- data/features/method_stubs/as_null_object.feature +4 -4
- data/features/method_stubs/simple_return_value_with_stub.feature +7 -7
- data/features/method_stubs/stub_chain.feature +3 -3
- data/features/method_stubs/stub_implementation.feature +2 -2
- data/features/method_stubs/to_ary.feature +2 -2
- data/features/mutating_constants/hiding_defined_constant.feature +2 -2
- data/features/mutating_constants/stub_defined_constant.feature +5 -5
- data/features/mutating_constants/stub_undefined_constant.feature +6 -6
- data/features/outside_rspec/configuration.feature +0 -2
- data/features/outside_rspec/standalone.feature +1 -1
- data/features/spies/spy_partial_mock_method.feature +2 -2
- data/features/spies/spy_pure_mock_method.feature +5 -5
- data/features/spies/spy_unstubbed_method.feature +1 -1
- data/features/support/env.rb +10 -1
- data/features/test_frameworks/test_unit.feature +1 -1
- data/features/verifying_doubles/class_doubles.feature +88 -0
- data/features/verifying_doubles/dynamic_classes.feature +72 -0
- data/features/verifying_doubles/introduction.feature +85 -0
- data/features/verifying_doubles/object_doubles.feature +65 -0
- data/features/verifying_doubles/partial_doubles.feature +34 -0
- data/lib/rspec/mocks.rb +8 -34
- data/lib/rspec/mocks/any_instance/chain.rb +4 -34
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +14 -4
- data/lib/rspec/mocks/any_instance/message_chains.rb +27 -12
- data/lib/rspec/mocks/any_instance/recorder.rb +23 -31
- data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -4
- data/lib/rspec/mocks/argument_list_matcher.rb +8 -1
- data/lib/rspec/mocks/argument_matchers.rb +26 -12
- data/lib/rspec/mocks/arity_calculator.rb +66 -0
- data/lib/rspec/mocks/configuration.rb +42 -14
- data/lib/rspec/mocks/error_generator.rb +34 -10
- data/lib/rspec/mocks/example_methods.rb +64 -19
- data/lib/rspec/mocks/extensions/marshal.rb +0 -15
- data/lib/rspec/mocks/framework.rb +4 -4
- data/lib/rspec/mocks/instance_method_stasher.rb +80 -62
- data/lib/rspec/mocks/matchers/have_received.rb +18 -14
- data/lib/rspec/mocks/matchers/receive.rb +29 -7
- data/lib/rspec/mocks/matchers/receive_messages.rb +72 -0
- data/lib/rspec/mocks/message_expectation.rb +95 -148
- data/lib/rspec/mocks/method_double.rb +77 -139
- data/lib/rspec/mocks/method_reference.rb +95 -0
- data/lib/rspec/mocks/mock.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +12 -9
- data/lib/rspec/mocks/object_reference.rb +90 -0
- data/lib/rspec/mocks/order_group.rb +49 -7
- data/lib/rspec/mocks/proxy.rb +72 -33
- data/lib/rspec/mocks/proxy_for_nil.rb +2 -2
- data/lib/rspec/mocks/space.rb +13 -18
- data/lib/rspec/mocks/stub_chain.rb +2 -2
- data/lib/rspec/mocks/syntax.rb +61 -36
- data/lib/rspec/mocks/targets.rb +40 -19
- data/lib/rspec/mocks/test_double.rb +12 -56
- data/lib/rspec/mocks/verifying_double.rb +77 -0
- data/lib/rspec/mocks/verifying_message_expecation.rb +60 -0
- data/lib/rspec/mocks/verifying_proxy.rb +151 -0
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/and_call_original_spec.rb +34 -30
- data/spec/rspec/mocks/and_yield_spec.rb +2 -2
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +53 -260
- data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
- data/spec/rspec/mocks/arity_calculator_spec.rb +95 -0
- data/spec/rspec/mocks/array_including_matcher_spec.rb +41 -0
- data/spec/rspec/mocks/at_least_spec.rb +4 -32
- data/spec/rspec/mocks/block_return_value_spec.rb +4 -135
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +10 -11
- data/spec/rspec/mocks/configuration_spec.rb +79 -0
- data/spec/rspec/mocks/double_spec.rb +10 -78
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -8
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +49 -4
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +20 -3
- data/spec/rspec/mocks/matchers/have_received_spec.rb +74 -0
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +140 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +82 -42
- data/spec/rspec/mocks/methods_spec.rb +1 -1
- data/spec/rspec/mocks/{bug_report_830_spec.rb → mock_expectation_error_spec.rb} +4 -3
- data/spec/rspec/mocks/mock_ordering_spec.rb +11 -0
- data/spec/rspec/mocks/mock_space_spec.rb +10 -1
- data/spec/rspec/mocks/mock_spec.rb +26 -82
- data/spec/rspec/mocks/multiple_return_value_spec.rb +1 -1
- data/spec/rspec/mocks/mutate_const_spec.rb +18 -5
- data/spec/rspec/mocks/null_object_mock_spec.rb +6 -4
- data/spec/rspec/mocks/options_hash_spec.rb +3 -3
- data/spec/rspec/mocks/order_group_spec.rb +27 -0
- data/spec/rspec/mocks/partial_mock_spec.rb +101 -1
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -20
- data/spec/rspec/mocks/record_messages_spec.rb +4 -4
- data/spec/rspec/mocks/serialization_spec.rb +4 -6
- data/spec/rspec/mocks/space_spec.rb +3 -3
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -12
- data/spec/rspec/mocks/stub_spec.rb +23 -44
- data/spec/rspec/mocks/test_double_spec.rb +3 -22
- data/spec/rspec/mocks/verifying_double_spec.rb +327 -0
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +68 -0
- data/spec/rspec/mocks_spec.rb +16 -39
- data/spec/spec_helper.rb +29 -18
- metadata +131 -86
- metadata.gz.sig +1 -0
- data/features/message_expectations/expect_any_instance_of.feature +0 -27
- data/lib/rspec/mocks/caller_filter.rb +0 -60
- data/lib/rspec/mocks/deprecation.rb +0 -26
- data/lib/rspec/mocks/extensions/instance_exec.rb +0 -34
- data/lib/rspec/mocks/extensions/proc.rb +0 -63
- data/lib/spec/mocks.rb +0 -4
- data/spec/rspec/mocks/and_return_spec.rb +0 -17
- data/spec/rspec/mocks/any_number_of_times_spec.rb +0 -36
- data/spec/rspec/mocks/before_all_spec.rb +0 -74
- data/spec/rspec/mocks/bug_report_10260_spec.rb +0 -8
- data/spec/rspec/mocks/bug_report_10263_spec.rb +0 -27
- data/spec/rspec/mocks/bug_report_11545_spec.rb +0 -32
- data/spec/rspec/mocks/bug_report_496_spec.rb +0 -17
- data/spec/rspec/mocks/bug_report_600_spec.rb +0 -22
- data/spec/rspec/mocks/bug_report_7611_spec.rb +0 -16
- data/spec/rspec/mocks/bug_report_8165_spec.rb +0 -31
- data/spec/rspec/mocks/bug_report_957_spec.rb +0 -22
@@ -21,7 +21,7 @@ Feature: explicit arguments
|
|
21
21
|
|
22
22
|
it "works on doubles and expectations" do
|
23
23
|
object = double('foo')
|
24
|
-
object.
|
24
|
+
expect(object).to receive(:bar).with(:foo)
|
25
25
|
|
26
26
|
object.bar(:foo)
|
27
27
|
end
|
@@ -43,17 +43,17 @@ Feature: explicit arguments
|
|
43
43
|
"got this and that"
|
44
44
|
end
|
45
45
|
|
46
|
-
object.foo(:this).
|
47
|
-
object.foo(:this, :that).
|
46
|
+
expect(object.foo(:this)).to eq("got this")
|
47
|
+
expect(object.foo(:this, :that)).to eq("got this and that")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "works on mocks" do
|
51
51
|
object = double('foo')
|
52
|
-
object.
|
52
|
+
expect(object).to receive(:foo).with(:this, :that)
|
53
53
|
|
54
54
|
object.foo(:this, :that)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
"""
|
58
58
|
When I run `rspec stub_multiple_explicit_args_spec.rb`
|
59
|
-
Then the output should contain "2 examples, 0 failures"
|
59
|
+
Then the output should contain "2 examples, 0 failures"
|
@@ -15,8 +15,8 @@ Feature: General matchers
|
|
15
15
|
"anything"
|
16
16
|
end
|
17
17
|
|
18
|
-
object.foo(1).
|
19
|
-
object.foo(:that).
|
18
|
+
expect(object.foo(1)).to eq("anything")
|
19
|
+
expect(object.foo(:that)).to eq("anything")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
"""
|
@@ -33,9 +33,9 @@ Feature: General matchers
|
|
33
33
|
"anything"
|
34
34
|
end
|
35
35
|
|
36
|
-
object.foo(1).
|
37
|
-
object.foo(:that).
|
38
|
-
object.foo.
|
36
|
+
expect(object.foo(1)).to eq("anything")
|
37
|
+
expect(object.foo(:that)).to eq("anything")
|
38
|
+
expect(object.foo).to eq("anything")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
"""
|
@@ -55,8 +55,8 @@ Feature: General matchers
|
|
55
55
|
"something"
|
56
56
|
end
|
57
57
|
|
58
|
-
object.foo(:that).
|
59
|
-
object.foo.
|
58
|
+
expect(object.foo(:that)).to eq("something")
|
59
|
+
expect(object.foo).to eq("nothing")
|
60
60
|
end
|
61
61
|
end
|
62
62
|
"""
|
@@ -69,17 +69,17 @@ Feature: General matchers
|
|
69
69
|
describe "stubbed no_args() args spec for expectations" do
|
70
70
|
it "works for no args" do
|
71
71
|
object = Object.new
|
72
|
-
object.
|
72
|
+
expect(object).to receive(:foo).with(no_args)
|
73
73
|
|
74
74
|
object.foo
|
75
75
|
end
|
76
76
|
it "fails for args" do
|
77
77
|
object = Object.new
|
78
|
-
object.
|
78
|
+
expect(object).to receive(:foo).with(no_args)
|
79
79
|
|
80
80
|
object.foo(:bar)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
"""
|
84
84
|
When I run `rspec stub_no_args_expectations_spec.rb`
|
85
|
-
Then the output should contain "2 examples, 1 failure"
|
85
|
+
Then the output should contain "2 examples, 1 failure"
|
@@ -17,10 +17,10 @@ Feature: stub with argument constraints
|
|
17
17
|
"string"
|
18
18
|
end
|
19
19
|
|
20
|
-
object.foo("bar").
|
21
|
-
object.foo(:that).
|
20
|
+
expect(object.foo("bar")).to eq("string")
|
21
|
+
expect(object.foo(:that)).to eq("symbol")
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
25
25
|
When I run `rspec stub_an_instance_of_args_spec.rb`
|
26
|
-
Then the output should contain "1 example, 0 failures"
|
26
|
+
Then the output should contain "1 example, 0 failures"
|
@@ -7,7 +7,7 @@ Feature: allow a message on any instance of a class
|
|
7
7
|
Scenario: allowing a message on any instance of a class
|
8
8
|
Given a file named "example_spec.rb" with:
|
9
9
|
"""ruby
|
10
|
-
describe "any_instance.
|
10
|
+
describe "any_instance.to receive" do
|
11
11
|
before do
|
12
12
|
allow_any_instance_of(Object).to receive(:foo).and_return(:return_value)
|
13
13
|
end
|
@@ -1,11 +1,33 @@
|
|
1
1
|
Feature: expect a message on any instance of a class
|
2
2
|
|
3
|
-
Use `
|
4
|
-
one) instance of a class receives a message before the example is
|
3
|
+
Use `expect_any_instance_of(Class).to receive` to set an expectation that one
|
4
|
+
(and only one) instance of a class receives a message before the example is
|
5
|
+
completed.
|
5
6
|
|
6
|
-
The
|
7
|
+
The example will fail if no instance receives the specified message.
|
7
8
|
|
8
9
|
Scenario: expect a message on any instance of a class
|
10
|
+
Given a file named "example_spec.rb" with:
|
11
|
+
"""ruby
|
12
|
+
describe "expect_any_instance_of" do
|
13
|
+
before do
|
14
|
+
expect_any_instance_of(Object).to receive(:foo).and_return(:return_value)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "verifies that one instance of the class receives the message" do
|
18
|
+
o = Object.new
|
19
|
+
expect(o.foo).to eq(:return_value)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "fails unless an instance receives that message" do
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run `rspec example_spec.rb`
|
27
|
+
Then the output should contain "2 examples, 1 failure"
|
28
|
+
And the output should contain "1) expect_any_instance_of fails unless an instance receives that message"
|
29
|
+
|
30
|
+
Scenario: expect a message on any instance of a class (should syntax)
|
9
31
|
Given a file named "example_spec.rb" with:
|
10
32
|
"""ruby
|
11
33
|
describe "any_instance.should_receive" do
|
@@ -13,9 +35,9 @@ Feature: expect a message on any instance of a class
|
|
13
35
|
Object.any_instance.should_receive(:foo).and_return(:return_value)
|
14
36
|
|
15
37
|
o = Object.new
|
16
|
-
o.foo.
|
38
|
+
expect(o.foo).to eq(:return_value)
|
17
39
|
end
|
18
40
|
end
|
19
41
|
"""
|
20
42
|
When I run `rspec example_spec.rb`
|
21
|
-
Then the examples should all pass
|
43
|
+
Then the examples should all pass
|
@@ -14,8 +14,8 @@ Feature: Calling the original method
|
|
14
14
|
|
15
15
|
describe "and_call_original" do
|
16
16
|
it "delegates the message to the original implementation" do
|
17
|
-
Addition.
|
18
|
-
Addition.two_plus_two.
|
17
|
+
expect(Addition).to receive(:two_plus_two).and_call_original
|
18
|
+
expect(Addition.two_plus_two).to eq(4)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
"""
|
@@ -75,7 +75,7 @@ Feature: expect message using `expect`
|
|
75
75
|
it "returns the specified value" do
|
76
76
|
object = double("object")
|
77
77
|
expect(object).to receive(:message) { :return_value }
|
78
|
-
object.message.
|
78
|
+
expect(object.message).to eq(:return_value)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
@@ -83,7 +83,7 @@ Feature: expect message using `expect`
|
|
83
83
|
it "returns the specified value" do
|
84
84
|
object = double("object")
|
85
85
|
expect(object).to receive(:message).and_return(:return_value)
|
86
|
-
object.message.
|
86
|
+
expect(object.message).to eq(:return_value)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
@@ -84,7 +84,7 @@ Feature: expect message using `should_receive`
|
|
84
84
|
it "returns the specified value" do
|
85
85
|
object = double("object")
|
86
86
|
object.should_receive(:message) { :return_value }
|
87
|
-
object.message.
|
87
|
+
expect(object.message).to eq(:return_value)
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,7 +92,7 @@ Feature: expect message using `should_receive`
|
|
92
92
|
it "returns the specified value" do
|
93
93
|
object = double("object")
|
94
94
|
object.should_receive(:message).and_return(:return_value)
|
95
|
-
object.message.
|
95
|
+
expect(object.message).to eq(:return_value)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
@@ -18,7 +18,7 @@ Feature: receive counts
|
|
18
18
|
account = Account.new
|
19
19
|
account.logger = logger
|
20
20
|
|
21
|
-
logger.
|
21
|
+
expect(logger).to receive(:account_opened).once
|
22
22
|
|
23
23
|
account.open
|
24
24
|
end
|
@@ -46,7 +46,7 @@ Feature: receive counts
|
|
46
46
|
account = Account.new
|
47
47
|
account.logger = logger
|
48
48
|
|
49
|
-
logger.
|
49
|
+
expect(logger).to receive(:account_opened).twice
|
50
50
|
|
51
51
|
account.open
|
52
52
|
account.open
|
@@ -75,7 +75,7 @@ Feature: receive counts
|
|
75
75
|
account = Account.new
|
76
76
|
account.logger = logger
|
77
77
|
|
78
|
-
logger.
|
78
|
+
expect(logger).to receive(:account_opened).exactly(3).times
|
79
79
|
|
80
80
|
account.open
|
81
81
|
account.open
|
@@ -105,7 +105,7 @@ Feature: receive counts
|
|
105
105
|
account = Account.new
|
106
106
|
account.logger = logger
|
107
107
|
|
108
|
-
logger.
|
108
|
+
expect(logger).to receive(:account_opened).at_least(:once)
|
109
109
|
|
110
110
|
account.open
|
111
111
|
end
|
@@ -134,7 +134,7 @@ Feature: receive counts
|
|
134
134
|
account = Account.new
|
135
135
|
account.logger = logger
|
136
136
|
|
137
|
-
logger.
|
137
|
+
expect(logger).to receive(:account_opened).at_least(3).times
|
138
138
|
|
139
139
|
# Note that I am calling method under test 4 times
|
140
140
|
# and I specified it to be called at least 3 times
|
@@ -167,7 +167,7 @@ Feature: receive counts
|
|
167
167
|
account = Account.new
|
168
168
|
account.logger = logger
|
169
169
|
|
170
|
-
logger.
|
170
|
+
expect(logger).to receive(:account_opened).at_most(:once)
|
171
171
|
|
172
172
|
account.open
|
173
173
|
account.open
|
@@ -197,7 +197,7 @@ Feature: receive counts
|
|
197
197
|
account = Account.new
|
198
198
|
account.logger = logger
|
199
199
|
|
200
|
-
logger.
|
200
|
+
expect(logger).to receive(:account_opened).at_most(2).times
|
201
201
|
|
202
202
|
account.open
|
203
203
|
account.open
|
@@ -6,7 +6,7 @@ Feature: warn when expectation is set on nil
|
|
6
6
|
RSpec.configure {|c| c.mock_with :rspec}
|
7
7
|
describe "something" do
|
8
8
|
it "does something" do
|
9
|
-
@i_do_not_exist.
|
9
|
+
expect(@i_do_not_exist).to receive(:foo)
|
10
10
|
@i_do_not_exist.foo
|
11
11
|
end
|
12
12
|
end
|
@@ -21,7 +21,7 @@ Feature: warn when expectation is set on nil
|
|
21
21
|
describe "something" do
|
22
22
|
it "does something" do
|
23
23
|
allow_message_expectations_on_nil
|
24
|
-
nil.
|
24
|
+
expect(nil).to receive(:foo)
|
25
25
|
nil.foo
|
26
26
|
end
|
27
27
|
end
|
@@ -40,7 +40,7 @@ Feature: warn when expectation is set on nil
|
|
40
40
|
nil.foo
|
41
41
|
end
|
42
42
|
it "does something (bar)" do
|
43
|
-
nil.
|
43
|
+
expect(nil).to receive(:bar)
|
44
44
|
nil.bar
|
45
45
|
end
|
46
46
|
end
|
@@ -65,6 +65,9 @@ You can also use the block format:
|
|
65
65
|
obj.stub(:message).with(anything()) { ... }
|
66
66
|
obj.stub(:message).with(an_instance_of(Money)) { ... }
|
67
67
|
obj.stub(:message).with(hash_including(:a => 'b')) { ... }
|
68
|
+
obj.stub(:message).with(array_including(1,2,3)) { ... }
|
69
|
+
# or
|
70
|
+
obj.stub(:message).with(array_including([1,2,3])) { ... }
|
68
71
|
|
69
72
|
#### Regular expressions
|
70
73
|
|
@@ -18,7 +18,7 @@ Feature: stub on any instance of a class
|
|
18
18
|
Object.any_instance.stub(:foo).and_return(:return_value)
|
19
19
|
|
20
20
|
o = Object.new
|
21
|
-
o.foo.
|
21
|
+
expect(o.foo).to eq(:return_value)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
"""
|
@@ -34,8 +34,8 @@ Feature: stub on any instance of a class
|
|
34
34
|
Object.any_instance.stub(:foo => 'foo', :bar => 'bar')
|
35
35
|
|
36
36
|
o = Object.new
|
37
|
-
o.foo.
|
38
|
-
o.bar.
|
37
|
+
expect(o.foo).to eq('foo')
|
38
|
+
expect(o.bar).to eq('bar')
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
@@ -53,8 +53,8 @@ Feature: stub on any instance of a class
|
|
53
53
|
Object.any_instance.stub(:foo).with(:param_three, :param_four).and_return(:result_two)
|
54
54
|
|
55
55
|
o = Object.new
|
56
|
-
o.foo(:param_one, :param_two).
|
57
|
-
o.foo(:param_three, :param_four).
|
56
|
+
expect(o.foo(:param_one, :param_two)).to eq(:result_one)
|
57
|
+
expect(o.foo(:param_three, :param_four)).to eq(:result_two)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -76,7 +76,7 @@ Feature: stub on any instance of a class
|
|
76
76
|
Object.any_instance.stub(:foo)
|
77
77
|
Object.any_instance.unstub(:foo)
|
78
78
|
|
79
|
-
Object.new.foo.
|
79
|
+
expect(Object.new.foo).to eq(:foo)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
"""
|
@@ -94,11 +94,11 @@ Feature: stub on any instance of a class
|
|
94
94
|
:foo
|
95
95
|
end
|
96
96
|
end
|
97
|
-
Object.
|
97
|
+
expect_any_instance_of(Object).to receive(:foo).and_return(:bar)
|
98
98
|
Object.any_instance.stub(:foo)
|
99
99
|
Object.any_instance.unstub(:foo)
|
100
100
|
|
101
|
-
Object.new.foo.
|
101
|
+
expect(Object.new.foo).to eq(:bar)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -113,21 +113,21 @@ Feature: stub on any instance of a class
|
|
113
113
|
context "given symbols representing methods" do
|
114
114
|
it "returns the correct value" do
|
115
115
|
Object.any_instance.stub_chain(:one, :two, :three).and_return(:four)
|
116
|
-
Object.new.one.two.three.
|
116
|
+
expect(Object.new.one.two.three).to eq(:four)
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
120
|
context "given a hash at the end" do
|
121
121
|
it "returns the correct value" do
|
122
122
|
Object.any_instance.stub_chain(:one, :two, :three => :four)
|
123
|
-
Object.new.one.two.three.
|
123
|
+
expect(Object.new.one.two.three).to eq(:four)
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
127
|
context "given a string of methods separated by dots" do
|
128
128
|
it "returns the correct value" do
|
129
129
|
Object.any_instance.stub_chain("one.two.three").and_return(:four)
|
130
|
-
Object.new.one.two.three.
|
130
|
+
expect(Object.new.one.two.three).to eq(:four)
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -13,7 +13,7 @@ Feature: as_null_object
|
|
13
13
|
let(:null_object) { double('null object').as_null_object }
|
14
14
|
|
15
15
|
it "responds to any method that is not defined" do
|
16
|
-
null_object.
|
16
|
+
expect(null_object).to respond_to(:an_undefined_method)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "allows explicit stubs using expect syntax" do
|
@@ -23,16 +23,16 @@ Feature: as_null_object
|
|
23
23
|
|
24
24
|
it "allows explicit stubs using should syntax" do
|
25
25
|
null_object.stub(:foo) { "bar" }
|
26
|
-
null_object.foo.
|
26
|
+
expect(null_object.foo).to eq("bar")
|
27
27
|
end
|
28
28
|
|
29
29
|
it "allows explicit expectations" do
|
30
|
-
null_object.
|
30
|
+
expect(null_object).to receive(:something)
|
31
31
|
null_object.something
|
32
32
|
end
|
33
33
|
|
34
34
|
it "supports Array#flatten" do
|
35
|
-
[null_object].flatten.
|
35
|
+
expect([null_object].flatten).to eq([null_object])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
"""
|
@@ -12,7 +12,7 @@ Feature: stub with a simple return value
|
|
12
12
|
|
13
13
|
it "returns nil" do
|
14
14
|
collaborator.stub(:message)
|
15
|
-
collaborator.message.
|
15
|
+
expect(collaborator.message).to be(nil)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
"""
|
@@ -27,7 +27,7 @@ Feature: stub with a simple return value
|
|
27
27
|
it "returns the specified value" do
|
28
28
|
collaborator = double("collaborator")
|
29
29
|
collaborator.stub(:message) { :value }
|
30
|
-
collaborator.message.
|
30
|
+
expect(collaborator.message).to eq(:value)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ Feature: stub with a simple return value
|
|
35
35
|
it "returns the specified value" do
|
36
36
|
collaborator = double("collaborator")
|
37
37
|
collaborator.stub(:message).and_return(:value)
|
38
|
-
collaborator.message.
|
38
|
+
expect(collaborator.message).to eq(:value)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,8 +43,8 @@ Feature: stub with a simple return value
|
|
43
43
|
it "returns the specified value" do
|
44
44
|
collaborator = double("collaborator")
|
45
45
|
collaborator.stub(:message_1 => :value_1, :message_2 => :value_2)
|
46
|
-
collaborator.message_1.
|
47
|
-
collaborator.message_2.
|
46
|
+
expect(collaborator.message_1).to eq(:value_1)
|
47
|
+
expect(collaborator.message_2).to eq(:value_2)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -54,8 +54,8 @@ Feature: stub with a simple return value
|
|
54
54
|
:message_1 => :value_1,
|
55
55
|
:message_2 => :value_2
|
56
56
|
)
|
57
|
-
collaborator.message_1.
|
58
|
-
collaborator.message_2.
|
57
|
+
expect(collaborator.message_1).to eq(:value_1)
|
58
|
+
expect(collaborator.message_2).to eq(:value_2)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|