rspec-mocks 2.9.0 → 2.10.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.
@@ -125,7 +125,7 @@ module RSpec
125
125
 
126
126
  def __mock_proxy
127
127
  @mock_proxy ||= begin
128
- mp = if Mock === self
128
+ mp = if TestDouble === self
129
129
  Proxy.new(self, @name, @options)
130
130
  else
131
131
  Proxy.new(self)
@@ -1,81 +1,7 @@
1
1
  module RSpec
2
2
  module Mocks
3
3
  class Mock
4
- include Methods
5
-
6
- # Creates a new test double with a `name` (that will be used in error
7
- # messages only)
8
- def initialize(name=nil, stubs_and_options={})
9
- if name.is_a?(Hash) && stubs_and_options.empty?
10
- stubs_and_options = name
11
- @name = nil
12
- else
13
- @name = name
14
- end
15
- @options = extract_options(stubs_and_options)
16
- assign_stubs(stubs_and_options)
17
- end
18
-
19
- # This allows for comparing the mock to other objects that proxy such as
20
- # ActiveRecords belongs_to proxy objects. By making the other object run
21
- # the comparison, we're sure the call gets delegated to the proxy
22
- # target.
23
- def ==(other)
24
- other == __mock_proxy
25
- end
26
-
27
- # @private
28
- def inspect
29
- "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
30
- end
31
-
32
- # @private
33
- def to_s
34
- inspect.gsub('<','[').gsub('>',']')
35
- end
36
-
37
- alias_method :to_str, :to_s
38
-
39
- # @private
40
- def respond_to?(message, incl_private=false)
41
- __mock_proxy.null_object? && message != :to_ary ? true : super
42
- end
43
-
44
- private
45
-
46
- def method_missing(message, *args, &block)
47
- raise NoMethodError if message == :to_ary
48
- __mock_proxy.record_message_received(message, *args, &block)
49
- begin
50
- __mock_proxy.null_object? ? self : super
51
- rescue NameError
52
- __mock_proxy.raise_unexpected_message_error(message, *args)
53
- end
54
- end
55
-
56
- def extract_options(stubs_and_options)
57
- if stubs_and_options[:null_object]
58
- @null_object = stubs_and_options.delete(:null_object)
59
- RSpec.deprecate(%Q["double('name', :null_object => true)"], %Q["double('name').as_null_object"])
60
- end
61
- options = {}
62
- extract_option(stubs_and_options, options, :__declared_as, 'Mock')
63
- options
64
- end
65
-
66
- def extract_option(source, target, key, default=nil)
67
- if source[key]
68
- target[key] = source.delete(key)
69
- elsif default
70
- target[key] = default
71
- end
72
- end
73
-
74
- def assign_stubs(stubs)
75
- stubs.each_pair do |message, response|
76
- stub(message).and_return(response)
77
- end
78
- end
4
+ include TestDouble
79
5
  end
80
6
  end
81
7
  end
@@ -149,9 +149,7 @@ module RSpec
149
149
  private
150
150
 
151
151
  def method_double
152
- @method_double ||= Hash.new {|h,k|
153
- h[k] = MethodDouble.new(@object, k, self)
154
- }
152
+ @method_double ||= Hash.new {|h,k| h[k] = MethodDouble.new(@object, k, self) }
155
153
  end
156
154
 
157
155
  def method_doubles
@@ -0,0 +1,102 @@
1
+ module RSpec
2
+ module Mocks
3
+ # Implements the methods needed for a pure test double. RSpec::Mocks::Mock
4
+ # includes this module, and it is provided for cases where you want a
5
+ # pure test double without subclassing RSpec::Mocks::Mock.
6
+ module TestDouble
7
+ include Methods
8
+
9
+ # Extends the TestDouble module onto the given object and
10
+ # initializes it as a test double.
11
+ #
12
+ # @example
13
+ #
14
+ # module = Module.new
15
+ # RSpec::Mocks::TestDouble.extend_onto(module, "MyMixin", :foo => "bar")
16
+ # module.foo #=> "bar"
17
+ def self.extend_onto(object, name=nil, stubs_and_options={})
18
+ object.extend self
19
+ object.send(:__initialize_as_test_double, name, stubs_and_options)
20
+ end
21
+
22
+ # Creates a new test double with a `name` (that will be used in error
23
+ # messages only)
24
+ def initialize(name=nil, stubs_and_options={})
25
+ __initialize_as_test_double(name, stubs_and_options)
26
+ end
27
+
28
+ # This allows for comparing the mock to other objects that proxy such as
29
+ # ActiveRecords belongs_to proxy objects. By making the other object run
30
+ # the comparison, we're sure the call gets delegated to the proxy
31
+ # target.
32
+ def ==(other)
33
+ other == __mock_proxy
34
+ end
35
+
36
+ # @private
37
+ def inspect
38
+ "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
39
+ end
40
+
41
+ # @private
42
+ def to_s
43
+ inspect.gsub('<','[').gsub('>',']')
44
+ end
45
+
46
+ alias_method :to_str, :to_s
47
+
48
+ # @private
49
+ def respond_to?(message, incl_private=false)
50
+ __mock_proxy.null_object? && message != :to_ary ? true : super
51
+ end
52
+
53
+ private
54
+
55
+ def __initialize_as_test_double(name=nil, stubs_and_options={})
56
+ if name.is_a?(Hash) && stubs_and_options.empty?
57
+ stubs_and_options = name
58
+ @name = nil
59
+ else
60
+ @name = name
61
+ end
62
+ @options = extract_options(stubs_and_options)
63
+ assign_stubs(stubs_and_options)
64
+ end
65
+
66
+ def method_missing(message, *args, &block)
67
+ raise NoMethodError if message == :to_ary
68
+ __mock_proxy.record_message_received(message, *args, &block)
69
+ begin
70
+ __mock_proxy.null_object? ? self : super
71
+ rescue NameError
72
+ __mock_proxy.raise_unexpected_message_error(message, *args)
73
+ end
74
+ end
75
+
76
+ def extract_options(stubs_and_options)
77
+ if stubs_and_options[:null_object]
78
+ @null_object = stubs_and_options.delete(:null_object)
79
+ RSpec.deprecate(%Q["double('name', :null_object => true)"], %Q["double('name').as_null_object"])
80
+ end
81
+ options = {}
82
+ extract_option(stubs_and_options, options, :__declared_as, 'Mock')
83
+ options
84
+ end
85
+
86
+ def extract_option(source, target, key, default=nil)
87
+ if source[key]
88
+ target[key] = source.delete(key)
89
+ elsif default
90
+ target[key] = default
91
+ end
92
+ end
93
+
94
+ def assign_stubs(stubs)
95
+ stubs.each_pair do |message, response|
96
+ stub(message).and_return(response)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Mocks
3
3
  module Version
4
- STRING = '2.9.0'
4
+ STRING = '2.10.0'
5
5
  end
6
6
  end
7
7
  end
@@ -4,95 +4,86 @@ module RSpec
4
4
  module Mocks
5
5
  describe "at_most" do
6
6
  before(:each) do
7
- @mock = RSpec::Mocks::Mock.new("test mock")
7
+ @double = double
8
8
  end
9
9
 
10
- it "fails when at most n times method is called n plus 1 times" do
11
- @mock.should_receive(:random_call).at_most(4).times
12
- @mock.random_call
13
- @mock.random_call
14
- @mock.random_call
15
- @mock.random_call
16
- @mock.random_call
17
- lambda do
18
- @mock.rspec_verify
19
- end.should raise_error(RSpec::Mocks::MockExpectationError)
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
+ @double.rspec_verify
20
15
  end
21
16
 
22
- it "fails when at most once method is called twice" do
23
- @mock.should_receive(:random_call).at_most(:once)
24
- @mock.random_call
25
- @mock.random_call
26
- lambda do
27
- @mock.rspec_verify
28
- end.should raise_error(RSpec::Mocks::MockExpectationError)
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
+ @double.rspec_verify
29
21
  end
30
22
 
31
- it "fails when at most twice method is called three times" do
32
- @mock.should_receive(:random_call).at_most(:twice)
33
- @mock.random_call
34
- @mock.random_call
35
- @mock.random_call
36
- lambda do
37
- @mock.rspec_verify
38
- end.should raise_error(RSpec::Mocks::MockExpectationError)
23
+ it "passes when at_most(n) is never called" do
24
+ @double.should_receive(:do_something).at_most(2).times
25
+ @double.rspec_verify
39
26
  end
40
27
 
41
- it "passes when at most n times method is called exactly n times" do
42
- @mock.should_receive(:random_call).at_most(4).times
43
- @mock.random_call
44
- @mock.random_call
45
- @mock.random_call
46
- @mock.random_call
47
- @mock.rspec_verify
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
+ @double.rspec_verify
48
32
  end
49
33
 
50
- it "passes when at most n times method is called less than n times" do
51
- @mock.should_receive(:random_call).at_most(4).times
52
- @mock.random_call
53
- @mock.random_call
54
- @mock.random_call
55
- @mock.rspec_verify
34
+ it "passes when at_most(:once) is never called" do
35
+ @double.should_receive(:do_something).at_most(:once)
36
+ @double.rspec_verify
56
37
  end
57
38
 
58
- it "passes when at most n times method is never called" do
59
- @mock.should_receive(:random_call).at_most(4).times
60
- @mock.rspec_verify
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
+ @double.rspec_verify
61
43
  end
62
44
 
63
- it "passes when at most once method is called once" do
64
- @mock.should_receive(:random_call).at_most(:once)
65
- @mock.random_call
66
- @mock.rspec_verify
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
+ @double.rspec_verify
67
50
  end
68
51
 
69
- it "passes when at most once method is never called" do
70
- @mock.should_receive(:random_call).at_most(:once)
71
- @mock.rspec_verify
52
+ it "passes when at_most(:twice) is never called" do
53
+ @double.should_receive(:do_something).at_most(:twice)
54
+ @double.rspec_verify
72
55
  end
73
56
 
74
- it "passes when at most twice method is called once" do
75
- @mock.should_receive(:random_call).at_most(:twice)
76
- @mock.random_call
77
- @mock.rspec_verify
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
+ @double.to_s.should eq "testing"
60
+ @double.rspec_verify
78
61
  end
79
62
 
80
- it "passes when at most twice method is called twice" do
81
- @mock.should_receive(:random_call).at_most(:twice)
82
- @mock.random_call
83
- @mock.random_call
84
- @mock.rspec_verify
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
+ lambda do
68
+ @double.do_something
69
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
85
70
  end
86
71
 
87
- it "passes when at most twice method is never called" do
88
- @mock.should_receive(:random_call).at_most(:twice)
89
- @mock.rspec_verify
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
+ lambda do
76
+ @double.do_something
77
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
90
78
  end
91
79
 
92
- it "returns the value given by a block when the at most once method is called" do
93
- @mock.should_receive(:to_s).at_most(:once) { "testing" }
94
- @mock.to_s.should eq "testing"
95
- @mock.rspec_verify
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
+ lambda do
85
+ @double.do_something
86
+ end.should raise_error(RSpec::Mocks::MockExpectationError)
96
87
  end
97
88
  end
98
89
  end
@@ -171,7 +171,7 @@ module RSpec
171
171
  @mock.should_receive(:something) {| bool | bool.should be_true}
172
172
  expect {
173
173
  @mock.something false
174
- }.to raise_error(RSpec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
174
+ }.to raise_error(RSpec::Expectations::ExpectationNotMetError)
175
175
  end
176
176
 
177
177
  it "passes proc to expectation block without an argument", :ruby => '> 1.8.6' do
@@ -217,6 +217,14 @@ module RSpec
217
217
  }.should raise_error(RuntimeError, "error message")
218
218
  end
219
219
 
220
+ it "raises instance of submitted ArgumentError" do
221
+ error = ArgumentError.new("error message")
222
+ @mock.should_receive(:something).and_raise(error)
223
+ lambda {
224
+ @mock.something
225
+ }.should raise_error(ArgumentError, "error message")
226
+ end
227
+
220
228
  it "fails with helpful message if submitted Exception requires constructor arguments" do
221
229
  class ErrorWithNonZeroArgConstructor < RuntimeError
222
230
  def initialize(i_take_an_argument)
@@ -250,14 +258,6 @@ module RSpec
250
258
  }.should throw_symbol(:blech)
251
259
  end
252
260
 
253
- it "raises when explicit return and block constrained" do
254
- lambda {
255
- @mock.should_receive(:fruit) do |colour|
256
- :strawberry
257
- end.and_return :apple
258
- }.should raise_error(RSpec::Mocks::AmbiguousReturnError)
259
- end
260
-
261
261
  it "ignores args on any args" do
262
262
  @mock.should_receive(:something).at_least(:once).with(any_args)
263
263
  @mock.something
@@ -484,8 +484,8 @@ module RSpec
484
484
 
485
485
  it "raises an error when a previously stubbed method has a negative expectation" do
486
486
  @mock.stub(:msg).and_return(:stub_value)
487
- @mock.should_not_receive(:msg).and_return(:mock_value)
488
- lambda {@mock.msg(:arg)}.should raise_error(RSpec::Mocks::MockExpectationError)
487
+ @mock.should_not_receive(:msg)
488
+ expect { @mock.msg(:arg) }.to raise_error(RSpec::Mocks::MockExpectationError)
489
489
  end
490
490
 
491
491
  it "temporarily replaces a method stub on a non-mock" do
@@ -2,187 +2,118 @@ require 'spec_helper'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
- describe "a Mock expectation with multiple return values and no specified count" do
5
+ describe "a message expectation with multiple return values and no specified count" do
6
6
  before(:each) do
7
- @mock = RSpec::Mocks::Mock.new("mock")
8
- @return_values = ["1",2,Object.new]
9
- @mock.should_receive(:message).and_return(@return_values[0],@return_values[1],@return_values[2])
7
+ @double = double
8
+ @return_values = [1,2,3]
9
+ @double.should_receive(:do_something).and_return(@return_values[0],@return_values[1],@return_values[2])
10
10
  end
11
11
 
12
- it "returns values in order to consecutive calls" do
13
- @mock.message.should eq @return_values[0]
14
- @mock.message.should eq @return_values[1]
15
- @mock.message.should eq @return_values[2]
16
- @mock.rspec_verify
12
+ it "returns values in order" do
13
+ @double.do_something.should eq @return_values[0]
14
+ @double.do_something.should eq @return_values[1]
15
+ @double.do_something.should eq @return_values[2]
16
+ @double.rspec_verify
17
17
  end
18
18
 
19
- it "complains when there are too few calls" do
20
- @mock.message.should eq @return_values[0]
21
- @mock.message.should eq @return_values[1]
22
- expect { @mock.rspec_verify }.to raise_error(
23
- RSpec::Mocks::MockExpectationError,
24
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
25
- )
19
+ it "falls back to a previously stubbed value" do
20
+ @double.stub :do_something => :stub_result
21
+ @double.do_something.should eq @return_values[0]
22
+ @double.do_something.should eq @return_values[1]
23
+ @double.do_something.should eq @return_values[2]
24
+ @double.do_something.should eq :stub_result
26
25
  end
27
26
 
28
- it "complains when there are too many calls" do
29
- @mock.message.should eq @return_values[0]
30
- @mock.message.should eq @return_values[1]
31
- @mock.message.should eq @return_values[2]
32
- @mock.message.should eq @return_values[2]
33
- expect { @mock.rspec_verify }.to raise_error(
34
- RSpec::Mocks::MockExpectationError,
35
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
36
- )
27
+ it "fails when there are too few calls (if there is no stub)" do
28
+ @double.do_something
29
+ @double.do_something
30
+ expect { @double.rspec_verify }.to raise_error
37
31
  end
38
32
 
39
- it "doesn't complain when there are too many calls but method is stubbed too" do
40
- @mock.stub(:message).and_return :stub_result
41
- @mock.message.should eq @return_values[0]
42
- @mock.message.should eq @return_values[1]
43
- @mock.message.should eq @return_values[2]
44
- @mock.message.should eq :stub_result
45
- expect { @mock.rspec_verify }.to_not raise_error(RSpec::Mocks::MockExpectationError)
33
+ it "fails when there are too many calls (if there is no stub)" do
34
+ @double.do_something
35
+ @double.do_something
36
+ @double.do_something
37
+ @double.do_something
38
+ expect { @double.rspec_verify }.to raise_error
46
39
  end
47
40
  end
48
41
 
49
- describe "a Mock expectation with multiple return values with a specified count equal to the number of values" do
42
+ describe "a message expectation with multiple return values with a specified count equal to the number of values" do
50
43
  before(:each) do
51
- @mock = RSpec::Mocks::Mock.new("mock")
52
- @return_values = ["1",2,Object.new]
53
- @mock.should_receive(:message).exactly(3).times.and_return(@return_values[0],@return_values[1],@return_values[2])
44
+ @double = double
45
+ @return_values = [1,2,3]
46
+ @double.should_receive(:do_something).exactly(3).times.and_return(@return_values[0],@return_values[1],@return_values[2])
54
47
  end
55
48
 
56
49
  it "returns values in order to consecutive calls" do
57
- @mock.message.should eq @return_values[0]
58
- @mock.message.should eq @return_values[1]
59
- @mock.message.should eq @return_values[2]
60
- @mock.rspec_verify
61
- end
62
-
63
- it "complains when there are too few calls" do
64
- @mock.message.should eq @return_values[0]
65
- @mock.message.should eq @return_values[1]
66
- expect { @mock.rspec_verify }.to raise_error(
67
- RSpec::Mocks::MockExpectationError,
68
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
69
- )
70
- end
71
-
72
- it "complains when there are too many calls" do
73
- @mock.message.should eq @return_values[0]
74
- @mock.message.should eq @return_values[1]
75
- @mock.message.should eq @return_values[2]
76
- @mock.message.should eq @return_values[2]
77
- expect { @mock.rspec_verify }.to raise_error(
78
- RSpec::Mocks::MockExpectationError,
79
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
80
- )
81
- end
82
-
83
- it "complains when there are too many calls and method is stubbed too" do
84
- @mock.stub(:message).and_return :stub_result
85
- @mock.message.should eq @return_values[0]
86
- @mock.message.should eq @return_values[1]
87
- @mock.message.should eq @return_values[2]
88
- @mock.message.should eq :stub_result
89
- expect { @mock.rspec_verify }.to raise_error(
90
- RSpec::Mocks::MockExpectationError,
91
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
92
- )
50
+ @double.do_something.should eq @return_values[0]
51
+ @double.do_something.should eq @return_values[1]
52
+ @double.do_something.should eq @return_values[2]
53
+ @double.rspec_verify
93
54
  end
94
55
  end
95
56
 
96
- describe "a Mock expectation with multiple return values specifying at_least less than the number of values" do
57
+ describe "a message expectation with multiple return values specifying at_least less than the number of values" do
97
58
  before(:each) do
98
- @mock = RSpec::Mocks::Mock.new("mock")
99
- @mock.should_receive(:message).at_least(:twice).with(no_args).and_return(11, 22)
59
+ @double = double
60
+ @double.should_receive(:do_something).at_least(:twice).with(no_args).and_return(11, 22)
100
61
  end
101
62
 
102
63
  it "uses the last return value for subsequent calls" do
103
- @mock.message.should equal(11)
104
- @mock.message.should equal(22)
105
- @mock.message.should equal(22)
106
- @mock.rspec_verify
64
+ @double.do_something.should equal(11)
65
+ @double.do_something.should equal(22)
66
+ @double.do_something.should equal(22)
67
+ @double.rspec_verify
107
68
  end
108
69
 
109
70
  it "fails when called less than the specified number" do
110
- @mock.message.should equal(11)
111
- expect { @mock.rspec_verify }.to raise_error(
112
- RSpec::Mocks::MockExpectationError,
113
- %Q|(Mock "mock").message(no args)\n expected: 2 times\n received: 1 time|
114
- )
71
+ @double.do_something.should equal(11)
72
+ expect { @double.rspec_verify }.to raise_error(RSpec::Mocks::MockExpectationError)
115
73
  end
116
74
 
117
75
  context "when method is stubbed too" do
118
- before { @mock.stub(:message).and_return :stub_result }
76
+ before { @double.stub(:do_something).and_return :stub_result }
119
77
 
120
78
  it "uses the stub return value for subsequent calls" do
121
- @mock.message.should equal(11)
122
- @mock.message.should equal(22)
123
- @mock.message.should equal(:stub_result)
124
- @mock.rspec_verify
79
+ @double.do_something.should equal(11)
80
+ @double.do_something.should equal(22)
81
+ @double.do_something.should equal(:stub_result)
82
+ @double.rspec_verify
125
83
  end
126
84
 
127
85
  it "fails when called less than the specified number" do
128
- @mock.message.should equal(11)
129
- expect { @mock.rspec_verify }.to raise_error(
130
- RSpec::Mocks::MockExpectationError,
131
- %Q|(Mock "mock").message(no args)\n expected: 2 times\n received: 1 time|
132
- )
86
+ @double.do_something.should equal(11)
87
+ expect { @double.rspec_verify }.to raise_error(RSpec::Mocks::MockExpectationError)
133
88
  end
134
89
  end
135
-
136
90
  end
137
91
 
138
- describe "a Mock expectation with multiple return values with a specified count larger than the number of values" do
92
+ describe "a message expectation with multiple return values with a specified count larger than the number of values" do
139
93
  before(:each) do
140
- @mock = RSpec::Mocks::Mock.new("mock")
141
- @mock.should_receive(:message).exactly(3).times.and_return(11, 22)
94
+ @double = RSpec::Mocks::Mock.new("double")
95
+ @double.should_receive(:do_something).exactly(3).times.and_return(11, 22)
142
96
  end
143
97
 
144
98
  it "uses the last return value for subsequent calls" do
145
- @mock.message.should equal(11)
146
- @mock.message.should equal(22)
147
- @mock.message.should equal(22)
148
- @mock.rspec_verify
99
+ @double.do_something.should equal(11)
100
+ @double.do_something.should equal(22)
101
+ @double.do_something.should equal(22)
102
+ @double.rspec_verify
149
103
  end
150
104
 
151
105
  it "fails when called less than the specified number" do
152
- @mock.message.should equal(11)
153
- expect { @mock.rspec_verify }.to raise_error(
154
- RSpec::Mocks::MockExpectationError,
155
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 1 time|
156
- )
106
+ @double.do_something
107
+ @double.do_something
108
+ expect { @double.rspec_verify }.to raise_error
157
109
  end
158
110
 
159
- it "fails when called greater than the specified number" do
160
- @mock.message.should equal(11)
161
- @mock.message.should equal(22)
162
- @mock.message.should equal(22)
163
- @mock.message.should equal(22)
164
- expect { @mock.rspec_verify }.to raise_error(
165
- RSpec::Mocks::MockExpectationError,
166
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
167
- )
168
- end
169
-
170
- context "when method is stubbed too" do
171
- before { @mock.stub(:message).and_return :stub_result }
172
-
173
- it "fails when called greater than the specified number" do
174
- @mock.message.should equal(11)
175
- @mock.message.should equal(22)
176
- @mock.message.should equal(22)
177
- @mock.message.should equal(:stub_result)
178
- expect { @mock.rspec_verify }.to raise_error(
179
- RSpec::Mocks::MockExpectationError,
180
- %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
181
- )
182
- end
183
-
111
+ it "fails fast when called greater than the specified number" do
112
+ @double.do_something
113
+ @double.do_something
114
+ @double.do_something
115
+ expect { @double.do_something }.to raise_error
184
116
  end
185
117
  end
186
118
  end
187
119
  end
188
-