rspec-mocks 2.12.1 → 2.12.2

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.
Files changed (56) hide show
  1. data/Changelog.md +17 -0
  2. data/lib/rspec/mocks.rb +8 -0
  3. data/lib/rspec/mocks/message_expectation.rb +6 -11
  4. data/lib/rspec/mocks/method_double.rb +19 -2
  5. data/lib/rspec/mocks/mutate_const.rb +1 -1
  6. data/lib/rspec/mocks/proxy.rb +1 -1
  7. data/lib/rspec/mocks/version.rb +1 -1
  8. data/lib/spec/mocks.rb +4 -0
  9. data/spec/rspec/mocks/and_call_original_spec.rb +22 -0
  10. data/spec/rspec/mocks/and_yield_spec.rb +7 -7
  11. data/spec/rspec/mocks/any_instance/message_chains_spec.rb +6 -6
  12. data/spec/rspec/mocks/any_instance_spec.rb +94 -94
  13. data/spec/rspec/mocks/any_number_of_times_spec.rb +2 -2
  14. data/spec/rspec/mocks/argument_expectation_spec.rb +3 -3
  15. data/spec/rspec/mocks/at_least_spec.rb +15 -15
  16. data/spec/rspec/mocks/at_most_spec.rb +7 -7
  17. data/spec/rspec/mocks/block_return_value_spec.rb +6 -6
  18. data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
  19. data/spec/rspec/mocks/bug_report_10263_spec.rb +6 -4
  20. data/spec/rspec/mocks/bug_report_11545_spec.rb +1 -1
  21. data/spec/rspec/mocks/bug_report_600_spec.rb +1 -1
  22. data/spec/rspec/mocks/bug_report_7611_spec.rb +1 -1
  23. data/spec/rspec/mocks/bug_report_8165_spec.rb +4 -4
  24. data/spec/rspec/mocks/bug_report_830_spec.rb +2 -2
  25. data/spec/rspec/mocks/bug_report_957_spec.rb +2 -2
  26. data/spec/rspec/mocks/configuration_spec.rb +4 -4
  27. data/spec/rspec/mocks/double_spec.rb +1 -1
  28. data/spec/rspec/mocks/failing_argument_matchers_spec.rb +1 -1
  29. data/spec/rspec/mocks/hash_excluding_matcher_spec.rb +13 -13
  30. data/spec/rspec/mocks/hash_including_matcher_spec.rb +30 -30
  31. data/spec/rspec/mocks/mock_ordering_spec.rb +8 -8
  32. data/spec/rspec/mocks/mock_space_spec.rb +4 -4
  33. data/spec/rspec/mocks/mock_spec.rb +94 -90
  34. data/spec/rspec/mocks/multiple_return_value_spec.rb +21 -21
  35. data/spec/rspec/mocks/mutate_const_spec.rb +112 -102
  36. data/spec/rspec/mocks/nil_expectation_warning_spec.rb +6 -12
  37. data/spec/rspec/mocks/null_object_mock_spec.rb +12 -12
  38. data/spec/rspec/mocks/once_counts_spec.rb +7 -7
  39. data/spec/rspec/mocks/options_hash_spec.rb +6 -6
  40. data/spec/rspec/mocks/partial_mock_spec.rb +15 -15
  41. data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +17 -17
  42. data/spec/rspec/mocks/passing_argument_matchers_spec.rb +6 -6
  43. data/spec/rspec/mocks/precise_counts_spec.rb +7 -7
  44. data/spec/rspec/mocks/record_messages_spec.rb +4 -4
  45. data/spec/rspec/mocks/serialization_spec.rb +3 -3
  46. data/spec/rspec/mocks/stash_spec.rb +1 -1
  47. data/spec/rspec/mocks/stub_chain_spec.rb +22 -22
  48. data/spec/rspec/mocks/stub_implementation_spec.rb +10 -10
  49. data/spec/rspec/mocks/stub_spec.rb +50 -31
  50. data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +3 -3
  51. data/spec/rspec/mocks/test_double_spec.rb +3 -3
  52. data/spec/rspec/mocks/to_ary_spec.rb +7 -7
  53. data/spec/rspec/mocks/twice_counts_spec.rb +8 -8
  54. data/spec/rspec/mocks_spec.rb +13 -4
  55. data/spec/spec_helper.rb +4 -0
  56. metadata +5 -5
@@ -87,9 +87,9 @@ module RSpec
87
87
 
88
88
  without_yaml_loaded do
89
89
  it 'does not add #to_yaml to the stubbed object' do
90
- serializable_object.should_not respond_to(:to_yaml)
90
+ expect(serializable_object).not_to respond_to(:to_yaml)
91
91
  set_stub
92
- serializable_object.should_not respond_to(:to_yaml)
92
+ expect(serializable_object).not_to respond_to(:to_yaml)
93
93
  end
94
94
  end
95
95
 
@@ -102,7 +102,7 @@ module RSpec
102
102
 
103
103
  it 'does not interfere with its marshalling' do
104
104
  marshalled_copy = Marshal.load(Marshal.dump(serializable_object))
105
- marshalled_copy.should eq serializable_object
105
+ expect(marshalled_copy).to eq serializable_object
106
106
  end
107
107
  end
108
108
  end
@@ -21,7 +21,7 @@ module RSpec
21
21
  klass.rspec_verify
22
22
 
23
23
  klass.rspec_reset
24
- klass.foo(:yeah).should equal(:original_value)
24
+ expect(klass.foo(:yeah)).to equal(:original_value)
25
25
  end
26
26
  end
27
27
 
@@ -9,21 +9,21 @@ module RSpec
9
9
  context "using and_return" do
10
10
  it "returns expected value from chaining only one method call" do
11
11
  object.stub_chain(:msg1).and_return(:return_value)
12
- object.msg1.should equal(:return_value)
12
+ expect(object.msg1).to equal(:return_value)
13
13
  end
14
14
  end
15
15
 
16
16
  context "using a block" do
17
17
  it "returns the correct value" do
18
18
  object.stub_chain(:msg1) { :return_value }
19
- object.msg1.should equal(:return_value)
19
+ expect(object.msg1).to equal(:return_value)
20
20
  end
21
21
  end
22
22
 
23
23
  context "using a hash" do
24
24
  it "returns the value of the key/value pair" do
25
25
  object.stub_chain(:msg1 => :return_value)
26
- object.msg1.should equal(:return_value)
26
+ expect(object.msg1).to equal(:return_value)
27
27
  end
28
28
  end
29
29
  end
@@ -32,21 +32,21 @@ module RSpec
32
32
  context "using and_return" do
33
33
  it "returns expected value from chaining two method calls" do
34
34
  object.stub_chain(:msg1, :msg2).and_return(:return_value)
35
- object.msg1.msg2.should equal(:return_value)
35
+ expect(object.msg1.msg2).to equal(:return_value)
36
36
  end
37
37
  end
38
38
 
39
39
  context "using a block" do
40
40
  it "returns the correct value" do
41
41
  object.stub_chain(:msg1, :msg2) { :return_value }
42
- object.msg1.msg2.should equal(:return_value)
42
+ expect(object.msg1.msg2).to equal(:return_value)
43
43
  end
44
44
  end
45
45
 
46
46
  context "using a hash" do
47
47
  it "returns the value of the key/value pair" do
48
48
  object.stub_chain(:msg1, :msg2 => :return_value)
49
- object.msg1.msg2.should equal(:return_value)
49
+ expect(object.msg1.msg2).to equal(:return_value)
50
50
  end
51
51
  end
52
52
  end
@@ -55,35 +55,35 @@ module RSpec
55
55
  context "using and_return" do
56
56
  it "returns expected value from chaining two method calls" do
57
57
  object.stub_chain(:msg1, :msg2, :msg3, :msg4).and_return(:return_value)
58
- object.msg1.msg2.msg3.msg4.should equal(:return_value)
58
+ expect(object.msg1.msg2.msg3.msg4).to equal(:return_value)
59
59
  end
60
60
  end
61
61
 
62
62
  context "using a block" do
63
63
  it "returns the correct value" do
64
64
  object.stub_chain(:msg1, :msg2, :msg3, :msg4) { :return_value }
65
- object.msg1.msg2.msg3.msg4.should equal(:return_value)
65
+ expect(object.msg1.msg2.msg3.msg4).to equal(:return_value)
66
66
  end
67
67
  end
68
68
 
69
69
  context "using a hash" do
70
70
  it "returns the value of the key/value pair" do
71
71
  object.stub_chain(:msg1, :msg2, :msg3, :msg4 => :return_value)
72
- object.msg1.msg2.msg3.msg4.should equal(:return_value)
72
+ expect(object.msg1.msg2.msg3.msg4).to equal(:return_value)
73
73
  end
74
74
  end
75
75
 
76
76
  context "using a hash with a string key" do
77
77
  it "returns the value of the key/value pair" do
78
78
  object.stub_chain("msg1.msg2.msg3.msg4" => :return_value)
79
- object.msg1.msg2.msg3.msg4.should equal(:return_value)
79
+ expect(object.msg1.msg2.msg3.msg4).to equal(:return_value)
80
80
  end
81
81
  end
82
82
  end
83
83
 
84
84
  it "returns expected value from chaining four method calls" do
85
85
  object.stub_chain(:msg1, :msg2, :msg3, :msg4).and_return(:return_value)
86
- object.msg1.msg2.msg3.msg4.should equal(:return_value)
86
+ expect(object.msg1.msg2.msg3.msg4).to equal(:return_value)
87
87
  end
88
88
 
89
89
  context "with messages shared across multiple chains" do
@@ -93,8 +93,8 @@ module RSpec
93
93
  object.stub_chain(:msg1, :msg2, :msg3).and_return(:first)
94
94
  object.stub_chain(:msg1, :msg2, :msg4).and_return(:second)
95
95
 
96
- object.msg1.msg2.msg3.should equal(:first)
97
- object.msg1.msg2.msg4.should equal(:second)
96
+ expect(object.msg1.msg2.msg3).to equal(:first)
97
+ expect(object.msg1.msg2.msg4).to equal(:second)
98
98
  end
99
99
  end
100
100
 
@@ -103,8 +103,8 @@ module RSpec
103
103
  object.stub_chain(:msg1, :msg2, :msg3).and_return(:first)
104
104
  object.stub_chain(:msg4, :msg2, :msg3).and_return(:second)
105
105
 
106
- object.msg1.msg2.msg3.should equal(:first)
107
- object.msg4.msg2.msg3.should equal(:second)
106
+ expect(object.msg1.msg2.msg3).to equal(:first)
107
+ expect(object.msg4.msg2.msg3).to equal(:second)
108
108
  end
109
109
  end
110
110
  end
@@ -115,8 +115,8 @@ module RSpec
115
115
  object.stub_chain(:msg1, :msg2, :msg3 => :first)
116
116
  object.stub_chain(:msg1, :msg2, :msg4 => :second)
117
117
 
118
- object.msg1.msg2.msg3.should equal(:first)
119
- object.msg1.msg2.msg4.should equal(:second)
118
+ expect(object.msg1.msg2.msg3).to equal(:first)
119
+ expect(object.msg1.msg2.msg4).to equal(:second)
120
120
  end
121
121
  end
122
122
 
@@ -125,8 +125,8 @@ module RSpec
125
125
  object.stub_chain(:msg1, :msg2, :msg3 => :first)
126
126
  object.stub_chain(:msg4, :msg2, :msg3 => :second)
127
127
 
128
- object.msg1.msg2.msg3.should equal(:first)
129
- object.msg4.msg2.msg3.should equal(:second)
128
+ expect(object.msg1.msg2.msg3).to equal(:first)
129
+ expect(object.msg4.msg2.msg3).to equal(:second)
130
130
  end
131
131
  end
132
132
  end
@@ -134,15 +134,15 @@ module RSpec
134
134
 
135
135
  it "returns expected value when chain is a dot separated string, like stub_chain('msg1.msg2.msg3')" do
136
136
  object.stub_chain("msg1.msg2.msg3").and_return(:return_value)
137
- object.msg1.msg2.msg3.should equal(:return_value)
137
+ expect(object.msg1.msg2.msg3).to equal(:return_value)
138
138
  end
139
139
 
140
140
  it "returns expected value from two chains with shared messages at the beginning" do
141
141
  object.stub_chain(:msg1, :msg2, :msg3, :msg4).and_return(:first)
142
142
  object.stub_chain(:msg1, :msg2, :msg3, :msg5).and_return(:second)
143
143
 
144
- object.msg1.msg2.msg3.msg4.should equal(:first)
145
- object.msg1.msg2.msg3.msg5.should equal(:second)
144
+ expect(object.msg1.msg2.msg3.msg4).to equal(:first)
145
+ expect(object.msg1.msg2.msg3.msg5).to equal(:second)
146
146
  end
147
147
 
148
148
  it "handles private instance methods (like Object#select) in the middle of a chain" do
@@ -7,7 +7,7 @@ module RSpec
7
7
  it "execs the block when called" do
8
8
  obj = stub()
9
9
  obj.stub(:foo) { :bar }
10
- obj.foo.should eq :bar
10
+ expect(obj.foo).to eq :bar
11
11
  end
12
12
  end
13
13
 
@@ -15,7 +15,7 @@ module RSpec
15
15
  it "execs the block with that arg when called" do
16
16
  obj = stub()
17
17
  obj.stub(:foo) {|given| given}
18
- obj.foo(:bar).should eq :bar
18
+ expect(obj.foo(:bar)).to eq :bar
19
19
  end
20
20
  end
21
21
 
@@ -23,7 +23,7 @@ module RSpec
23
23
  it "execs the block when called" do
24
24
  obj = stub()
25
25
  obj.stub(:foo) {|*given| given.first}
26
- obj.foo(:bar).should eq :bar
26
+ expect(obj.foo(:bar)).to eq :bar
27
27
  end
28
28
  end
29
29
  end
@@ -35,7 +35,7 @@ module RSpec
35
35
  def obj.foo; :original; end
36
36
  obj.stub(:foo)
37
37
  obj.unstub(:foo)
38
- obj.foo.should eq :original
38
+ expect(obj.foo).to eq :original
39
39
  end
40
40
 
41
41
  it "removes all stubs with the supplied method name" do
@@ -44,7 +44,7 @@ module RSpec
44
44
  obj.stub(:foo).with(1)
45
45
  obj.stub(:foo).with(2)
46
46
  obj.unstub(:foo)
47
- obj.foo.should eq :original
47
+ expect(obj.foo).to eq :original
48
48
  end
49
49
 
50
50
  it "does not remove any expectations with the same method name" do
@@ -54,7 +54,7 @@ module RSpec
54
54
  obj.stub(:foo).with(1)
55
55
  obj.stub(:foo).with(2)
56
56
  obj.unstub(:foo)
57
- obj.foo(3).should eq :three
57
+ expect(obj.foo(3)).to eq :three
58
58
  end
59
59
 
60
60
  it "restores the correct implementations when stubbed and unstubbed on a parent and child class" do
@@ -66,15 +66,15 @@ module RSpec
66
66
  parent.unstub(:new)
67
67
  child.unstub(:new)
68
68
 
69
- parent.new.should be_an_instance_of parent
70
- child.new.should be_an_instance_of child
69
+ expect(parent.new).to be_an_instance_of parent
70
+ expect(child.new).to be_an_instance_of child
71
71
  end
72
72
 
73
73
  it "raises a MockExpectationError if the method has not been stubbed" do
74
74
  obj = Object.new
75
- lambda do
75
+ expect {
76
76
  obj.unstub(:foo)
77
- end.should raise_error(RSpec::Mocks::MockExpectationError)
77
+ }.to raise_error(RSpec::Mocks::MockExpectationError)
78
78
  end
79
79
  end
80
80
  end
@@ -33,7 +33,7 @@ module RSpec
33
33
  describe "using #{method}" do
34
34
  it "returns declared value when message is received" do
35
35
  @instance.send(method, :msg).and_return(:return_value)
36
- @instance.msg.should equal(:return_value)
36
+ expect(@instance.msg).to equal(:return_value)
37
37
  @instance.rspec_verify
38
38
  end
39
39
  end
@@ -41,12 +41,12 @@ module RSpec
41
41
 
42
42
  it "instructs an instance to respond_to the message" do
43
43
  @instance.stub(:msg)
44
- @instance.should respond_to(:msg)
44
+ expect(@instance).to respond_to(:msg)
45
45
  end
46
46
 
47
47
  it "instructs a class object to respond_to the message" do
48
48
  @class.stub(:msg)
49
- @class.should respond_to(:msg)
49
+ expect(@class).to respond_to(:msg)
50
50
  end
51
51
 
52
52
  it "ignores when expected message is received with no args" do
@@ -74,43 +74,43 @@ module RSpec
74
74
 
75
75
  it "handles multiple stubbed methods" do
76
76
  @instance.stub(:msg1 => 1, :msg2 => 2)
77
- @instance.msg1.should eq(1)
78
- @instance.msg2.should eq(2)
77
+ expect(@instance.msg1).to eq(1)
78
+ expect(@instance.msg2).to eq(2)
79
79
  end
80
80
 
81
81
  describe "#rspec_reset" do
82
82
  it "removes stubbed methods that didn't exist" do
83
83
  @instance.stub(:non_existent_method)
84
84
  @instance.rspec_reset
85
- @instance.should_not respond_to(:non_existent_method)
85
+ expect(@instance).not_to respond_to(:non_existent_method)
86
86
  end
87
87
 
88
88
  it "restores existing instance methods" do
89
89
  # See bug reports 8302 adn 7805
90
90
  @instance.stub(:existing_instance_method) { :stub_value }
91
91
  @instance.rspec_reset
92
- @instance.existing_instance_method.should eq(:original_value)
92
+ expect(@instance.existing_instance_method).to eq(:original_value)
93
93
  end
94
94
 
95
95
  it "restores existing private instance methods" do
96
96
  # See bug reports 8302 adn 7805
97
97
  @instance.stub(:existing_private_instance_method) { :stub_value }
98
98
  @instance.rspec_reset
99
- @instance.send(:existing_private_instance_method).should eq(:original_value)
99
+ expect(@instance.send(:existing_private_instance_method)).to eq(:original_value)
100
100
  end
101
101
 
102
102
  it "restores existing class methods" do
103
103
  # See bug reports 8302 adn 7805
104
104
  @class.stub(:existing_class_method) { :stub_value }
105
105
  @class.rspec_reset
106
- @class.existing_class_method.should eq(:original_value)
106
+ expect(@class.existing_class_method).to eq(:original_value)
107
107
  end
108
108
 
109
109
  it "restores existing private class methods" do
110
110
  # See bug reports 8302 adn 7805
111
111
  @class.stub(:existing_private_class_method) { :stub_value }
112
112
  @class.rspec_reset
113
- @class.send(:existing_private_class_method).should eq(:original_value)
113
+ expect(@class.send(:existing_private_class_method)).to eq(:original_value)
114
114
  end
115
115
 
116
116
  it "does not remove existing methods that have been stubbed twice" do
@@ -119,31 +119,50 @@ module RSpec
119
119
 
120
120
  @instance.rspec_reset
121
121
 
122
- @instance.existing_instance_method.should eq(:original_value)
122
+ expect(@instance.existing_instance_method).to eq(:original_value)
123
+ end
124
+
125
+ it "correctly restores the visibility of methods whose visibility has been tweaked on the singleton class" do
126
+ # hello is a private method when mixed in, but public on the module
127
+ # itself
128
+ mod = Module.new {
129
+ extend self
130
+ def hello; :hello; end
131
+
132
+ private :hello
133
+ class << self; public :hello; end;
134
+ }
135
+
136
+ expect(mod.hello).to eq(:hello)
137
+
138
+ mod.stub(:hello) { :stub }
139
+ mod.rspec_reset
140
+
141
+ expect(mod.hello).to eq(:hello)
123
142
  end
124
143
  end
125
144
 
126
145
  it "returns values in order to consecutive calls" do
127
146
  @instance.stub(:msg).and_return("1",2,:three)
128
- @instance.msg.should eq("1")
129
- @instance.msg.should eq(2)
130
- @instance.msg.should eq(:three)
147
+ expect(@instance.msg).to eq("1")
148
+ expect(@instance.msg).to eq(2)
149
+ expect(@instance.msg).to eq(:three)
131
150
  end
132
151
 
133
152
  it "keeps returning last value in consecutive calls" do
134
153
  @instance.stub(:msg).and_return("1",2,:three)
135
- @instance.msg.should eq("1")
136
- @instance.msg.should eq(2)
137
- @instance.msg.should eq(:three)
138
- @instance.msg.should eq(:three)
139
- @instance.msg.should eq(:three)
154
+ expect(@instance.msg).to eq("1")
155
+ expect(@instance.msg).to eq(2)
156
+ expect(@instance.msg).to eq(:three)
157
+ expect(@instance.msg).to eq(:three)
158
+ expect(@instance.msg).to eq(:three)
140
159
  end
141
160
 
142
161
  it "yields a specified object" do
143
162
  @instance.stub(:method_that_yields).and_yield(:yielded_obj)
144
163
  current_value = :value_before
145
164
  @instance.method_that_yields {|val| current_value = val}
146
- current_value.should eq :yielded_obj
165
+ expect(current_value).to eq :yielded_obj
147
166
  @instance.rspec_verify
148
167
  end
149
168
 
@@ -152,7 +171,7 @@ module RSpec
152
171
  and_yield(:another_value)
153
172
  current_value = []
154
173
  @instance.method_that_yields_multiple_times {|val| current_value << val}
155
- current_value.should eq [:yielded_value, :another_value]
174
+ expect(current_value).to eq [:yielded_value, :another_value]
156
175
  @instance.rspec_verify
157
176
  end
158
177
 
@@ -160,7 +179,7 @@ module RSpec
160
179
  yielded_obj = double("my mock")
161
180
  yielded_obj.should_receive(:foo).with(:bar)
162
181
  @instance.stub(:method_that_yields_and_returns).and_yield(yielded_obj).and_return(:baz)
163
- @instance.method_that_yields_and_returns { |o| o.foo :bar }.should eq :baz
182
+ expect(@instance.method_that_yields_and_returns { |o| o.foo :bar }).to eq :baz
164
183
  end
165
184
 
166
185
  it "throws when told to" do
@@ -175,13 +194,13 @@ module RSpec
175
194
 
176
195
  it "overrides a pre-existing method" do
177
196
  @stub.stub(:existing_instance_method).and_return(:updated_stub_value)
178
- @stub.existing_instance_method.should eq :updated_stub_value
197
+ expect(@stub.existing_instance_method).to eq :updated_stub_value
179
198
  end
180
199
 
181
200
  it "overrides a pre-existing stub" do
182
201
  @stub.stub(:foo) { 'bar' }
183
202
  @stub.stub(:foo) { 'baz' }
184
- @stub.foo.should eq 'baz'
203
+ expect(@stub.foo).to eq 'baz'
185
204
  end
186
205
 
187
206
  it "allows a stub and an expectation" do
@@ -193,7 +212,7 @@ module RSpec
193
212
 
194
213
  it "calculates return value by executing block passed to #and_return" do
195
214
  @stub.stub(:something).with("a","b","c").and_return { |a,b,c| c+b+a }
196
- @stub.something("a","b","c").should eq "cba"
215
+ expect(@stub.something("a","b","c")).to eq "cba"
197
216
  @stub.rspec_verify
198
217
  end
199
218
  end
@@ -212,15 +231,15 @@ module RSpec
212
231
  end
213
232
 
214
233
  it "complains if called with no arg" do
215
- lambda do
234
+ expect {
216
235
  @stub.foo
217
- end.should raise_error(/received :foo with unexpected arguments/)
236
+ }.to raise_error(/received :foo with unexpected arguments/)
218
237
  end
219
238
 
220
239
  it "complains if called with other arg", :github_issue => [123,147] do
221
- lambda do
240
+ expect {
222
241
  @stub.foo("other")
223
- end.should raise_error(/received :foo with unexpected arguments.*Please stub a default value/m)
242
+ }.to raise_error(/received :foo with unexpected arguments.*Please stub a default value/m)
224
243
  end
225
244
 
226
245
  it "does not complain if also mocked w/ different args" do
@@ -233,9 +252,9 @@ module RSpec
233
252
  @stub.should_receive(:foo).with("baz")
234
253
  @stub.foo("bar")
235
254
  @stub.foo("baz")
236
- lambda do
255
+ expect {
237
256
  @stub.foo("other")
238
- end.should raise_error
257
+ }.to raise_error
239
258
  end
240
259
 
241
260
  it "supports options" do