rspec-mocks 2.0.0.beta.19 → 2.0.0.beta.20
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/.gitignore +1 -0
- data/Rakefile +0 -7
- data/VERSION +1 -1
- data/lib/rspec/mocks/argument_expectation.rb +7 -10
- data/lib/rspec/mocks/extensions/instance_exec.rb +3 -3
- data/lib/rspec/mocks/message_expectation.rb +26 -26
- data/lib/rspec/mocks/methods.rb +22 -6
- data/lib/rspec/mocks/mock.rb +3 -3
- data/lib/rspec/mocks/proxy.rb +10 -10
- data/rspec-mocks.gemspec +9 -15
- data/spec/rspec/mocks/any_number_of_times_spec.rb +4 -4
- data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
- data/spec/rspec/mocks/at_least_spec.rb +11 -11
- data/spec/rspec/mocks/at_most_spec.rb +11 -11
- data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_11545_spec.rb +3 -3
- data/spec/rspec/mocks/bug_report_15719_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_600_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_7611_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_8165_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_957_spec.rb +2 -2
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +12 -12
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +18 -18
- data/spec/rspec/mocks/hash_not_including_matcher_spec.rb +13 -13
- data/spec/rspec/mocks/mock_ordering_spec.rb +7 -7
- data/spec/rspec/mocks/mock_space_spec.rb +4 -4
- data/spec/rspec/mocks/mock_spec.rb +65 -65
- data/spec/rspec/mocks/multiple_return_value_spec.rb +11 -11
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +4 -4
- data/spec/rspec/mocks/null_object_mock_spec.rb +7 -7
- data/spec/rspec/mocks/once_counts_spec.rb +6 -6
- data/spec/rspec/mocks/options_hash_spec.rb +3 -3
- data/spec/rspec/mocks/partial_mock_spec.rb +17 -17
- data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +1 -1
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +20 -20
- data/spec/rspec/mocks/precise_counts_spec.rb +5 -5
- data/spec/rspec/mocks/record_messages_spec.rb +4 -4
- data/spec/rspec/mocks/stash_spec.rb +1 -1
- data/spec/rspec/mocks/stub_chain_spec.rb +13 -0
- data/spec/rspec/mocks/stub_implementation_spec.rb +4 -4
- data/spec/rspec/mocks/stub_spec.rb +26 -26
- data/spec/spec_helper.rb +2 -2
- data/spec/support/macros.rb +2 -2
- metadata +17 -27
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -19,13 +19,6 @@ begin
|
|
19
19
|
gem.rubyforge_project = "rspec"
|
20
20
|
gem.add_development_dependency 'rspec-core', RSpec::Mocks::Version::STRING
|
21
21
|
gem.add_development_dependency 'rspec-expectations', RSpec::Mocks::Version::STRING
|
22
|
-
gem.post_install_message = <<-EOM
|
23
|
-
#{"*"*50}
|
24
|
-
|
25
|
-
Thank you for installing #{gem.summary}
|
26
|
-
|
27
|
-
#{"*"*50}
|
28
|
-
EOM
|
29
22
|
end
|
30
23
|
rescue LoadError
|
31
24
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.0.beta.
|
1
|
+
2.0.0.beta.20
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module RSpec
|
2
2
|
module Mocks
|
3
|
-
|
4
3
|
class ArgumentExpectation
|
5
4
|
attr_reader :args
|
6
5
|
|
7
|
-
def initialize(args, &block)
|
6
|
+
def initialize(*args, &block)
|
8
7
|
@args = args
|
9
8
|
@matchers_block = block if args.empty?
|
10
9
|
@match_any_args = false
|
@@ -29,23 +28,21 @@ module RSpec
|
|
29
28
|
return obj.respond_to?(:matches?) & obj.respond_to?(:description)
|
30
29
|
end
|
31
30
|
|
32
|
-
def args_match?(
|
33
|
-
match_any_args? || matchers_block_matches?(
|
31
|
+
def args_match?(*args)
|
32
|
+
match_any_args? || matchers_block_matches?(*args) || matchers_match?(*args)
|
34
33
|
end
|
35
34
|
|
36
|
-
def matchers_block_matches?(
|
37
|
-
@matchers_block ? @matchers_block.call(*
|
35
|
+
def matchers_block_matches?(*args)
|
36
|
+
@matchers_block ? @matchers_block.call(*args) : nil
|
38
37
|
end
|
39
38
|
|
40
|
-
def matchers_match?(
|
41
|
-
@matchers ==
|
39
|
+
def matchers_match?(*args)
|
40
|
+
@matchers == args
|
42
41
|
end
|
43
42
|
|
44
43
|
def match_any_args?
|
45
44
|
@match_any_args
|
46
45
|
end
|
47
|
-
|
48
46
|
end
|
49
|
-
|
50
47
|
end
|
51
48
|
end
|
@@ -15,14 +15,14 @@ module RSpec
|
|
15
15
|
orig_critical, Thread.critical = Thread.critical, true
|
16
16
|
n = 0
|
17
17
|
n += 1 while respond_to?(method_name="__instance_exec#{n}")
|
18
|
-
singleton_class.module_eval{ define_method(
|
18
|
+
singleton_class.module_eval{ define_method(method_name, &block) }
|
19
19
|
ensure
|
20
20
|
Thread.critical = orig_critical
|
21
21
|
end
|
22
22
|
begin
|
23
|
-
return send(
|
23
|
+
return send(method_name, *args)
|
24
24
|
ensure
|
25
|
-
singleton_class.module_eval{ remove_method(
|
25
|
+
singleton_class.module_eval{ remove_method(method_name) } rescue nil
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -17,7 +17,7 @@ module RSpec
|
|
17
17
|
@return_block = nil
|
18
18
|
@actual_received_count = 0
|
19
19
|
@expected_received_count = expected_received_count
|
20
|
-
@args_expectation = ArgumentExpectation.new(
|
20
|
+
@args_expectation = ArgumentExpectation.new(ArgumentMatchers::AnyArgsMatcher.new)
|
21
21
|
@consecutive = false
|
22
22
|
@exception_to_raise = nil
|
23
23
|
@symbol_to_throw = nil
|
@@ -40,7 +40,7 @@ module RSpec
|
|
40
40
|
new_gen = error_generator.clone
|
41
41
|
new_gen.opts = opts
|
42
42
|
child.error_generator = new_gen
|
43
|
-
child.clone_args_to_yield
|
43
|
+
child.clone_args_to_yield *@args_to_yield
|
44
44
|
child
|
45
45
|
end
|
46
46
|
|
@@ -97,15 +97,15 @@ module RSpec
|
|
97
97
|
self
|
98
98
|
end
|
99
99
|
|
100
|
-
def matches(sym, args)
|
101
|
-
@sym == sym and @args_expectation.args_match?(args)
|
100
|
+
def matches?(sym, *args)
|
101
|
+
@sym == sym and @args_expectation.args_match?(*args)
|
102
102
|
end
|
103
103
|
|
104
|
-
def invoke(args, block)
|
104
|
+
def invoke(*args, &block)
|
105
105
|
if @expected_received_count == 0
|
106
106
|
@failed_fast = true
|
107
107
|
@actual_received_count += 1
|
108
|
-
@error_generator.raise_expectation_error
|
108
|
+
@error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *args)
|
109
109
|
end
|
110
110
|
|
111
111
|
@order_group.handle_order_constraint self
|
@@ -114,20 +114,20 @@ module RSpec
|
|
114
114
|
Kernel::raise @exception_to_raise unless @exception_to_raise.nil?
|
115
115
|
Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
|
116
116
|
|
117
|
-
if !@method_block.nil?
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
117
|
+
default_return_val = if !@method_block.nil?
|
118
|
+
invoke_method_block(*args)
|
119
|
+
elsif !@args_to_yield.empty? || @eval_context
|
120
|
+
invoke_with_yield(&block)
|
121
|
+
else
|
122
|
+
nil
|
123
|
+
end
|
124
124
|
|
125
125
|
if @consecutive
|
126
|
-
|
126
|
+
invoke_consecutive_return_block(*args, &block)
|
127
127
|
elsif @return_block
|
128
|
-
|
128
|
+
invoke_return_block(*args, &block)
|
129
129
|
else
|
130
|
-
|
130
|
+
default_return_val
|
131
131
|
end
|
132
132
|
ensure
|
133
133
|
@actual_received_count += 1
|
@@ -141,11 +141,11 @@ module RSpec
|
|
141
141
|
|
142
142
|
protected
|
143
143
|
|
144
|
-
def invoke_method_block(args)
|
144
|
+
def invoke_method_block(*args)
|
145
145
|
begin
|
146
146
|
@method_block.call(*args)
|
147
147
|
rescue => detail
|
148
|
-
@error_generator.raise_block_failed_error
|
148
|
+
@error_generator.raise_block_failed_error(@sym, detail.message)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -171,13 +171,13 @@ module RSpec
|
|
171
171
|
end
|
172
172
|
end
|
173
173
|
|
174
|
-
def invoke_consecutive_return_block(args, block)
|
175
|
-
value = invoke_return_block(args, block)
|
174
|
+
def invoke_consecutive_return_block(*args, &block)
|
175
|
+
value = invoke_return_block(*args, &block)
|
176
176
|
index = [@actual_received_count, value.size-1].min
|
177
177
|
value[index]
|
178
178
|
end
|
179
179
|
|
180
|
-
def invoke_return_block(args, block)
|
180
|
+
def invoke_return_block(*args, &block)
|
181
181
|
args << block unless block.nil?
|
182
182
|
# Ruby 1.9 - when we set @return_block to return values
|
183
183
|
# regardless of arguments, any arguments will result in
|
@@ -185,7 +185,7 @@ module RSpec
|
|
185
185
|
@return_block.arity == 0 ? @return_block.call : @return_block.call(*args)
|
186
186
|
end
|
187
187
|
|
188
|
-
def clone_args_to_yield(args)
|
188
|
+
def clone_args_to_yield(*args)
|
189
189
|
@args_to_yield = args.clone
|
190
190
|
@args_to_yield_were_cloned = true
|
191
191
|
end
|
@@ -197,8 +197,8 @@ module RSpec
|
|
197
197
|
|
198
198
|
class MessageExpectation < BaseExpectation
|
199
199
|
|
200
|
-
def matches_name_but_not_args(sym, args)
|
201
|
-
@sym == sym and not @args_expectation.args_match?(args)
|
200
|
+
def matches_name_but_not_args(sym, *args)
|
201
|
+
@sym == sym and not @args_expectation.args_match?(*args)
|
202
202
|
end
|
203
203
|
|
204
204
|
def verify_messages_received
|
@@ -235,7 +235,7 @@ module RSpec
|
|
235
235
|
@similar_messages ||= []
|
236
236
|
end
|
237
237
|
|
238
|
-
def advise(args
|
238
|
+
def advise(*args)
|
239
239
|
similar_messages << args
|
240
240
|
end
|
241
241
|
|
@@ -249,7 +249,7 @@ module RSpec
|
|
249
249
|
|
250
250
|
def with(*args, &block)
|
251
251
|
@return_block = block if block_given?
|
252
|
-
@args_expectation = ArgumentExpectation.new(args, &block)
|
252
|
+
@args_expectation = ArgumentExpectation.new(*args, &block)
|
253
253
|
self
|
254
254
|
end
|
255
255
|
|
data/lib/rspec/mocks/methods.rb
CHANGED
@@ -23,14 +23,30 @@ module RSpec
|
|
23
23
|
|
24
24
|
alias_method :stub!, :stub
|
25
25
|
alias_method :unstub!, :unstub
|
26
|
-
|
27
|
-
|
26
|
+
|
27
|
+
# :call-seq:
|
28
|
+
# double.stub_chain("foo.bar") { :baz }
|
29
|
+
# double.stub_chain(:foo, :bar) { :baz }
|
30
|
+
#
|
31
|
+
# Stubs a chain of methods. Especially useful with fluent and/or
|
32
|
+
# composable interfaces.
|
33
|
+
#
|
34
|
+
# == Examples
|
35
|
+
#
|
36
|
+
# Article.stub_chain("recent.published") { [Article.new] }
|
37
|
+
def stub_chain(*chain)
|
38
|
+
methods = chain.join('.').split('.')
|
28
39
|
if methods.length > 1
|
29
|
-
|
30
|
-
|
31
|
-
|
40
|
+
if matching_stub = __mock_proxy.__send__(:find_matching_method_stub, methods[0].to_sym)
|
41
|
+
methods.shift
|
42
|
+
matching_stub.invoke.stub_chain(*methods)
|
43
|
+
else
|
44
|
+
next_in_chain = Object.new
|
45
|
+
stub(methods.shift) { next_in_chain }
|
46
|
+
next_in_chain.stub_chain(*methods)
|
47
|
+
end
|
32
48
|
else
|
33
|
-
stub
|
49
|
+
stub(methods.shift)
|
34
50
|
end
|
35
51
|
end
|
36
52
|
|
data/lib/rspec/mocks/mock.rb
CHANGED
@@ -37,12 +37,12 @@ module RSpec
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def method_missing(sym, *args, &block)
|
40
|
-
__mock_proxy.record_message_received(sym, args, block)
|
40
|
+
__mock_proxy.record_message_received(sym, *args, &block)
|
41
41
|
begin
|
42
42
|
return self if __mock_proxy.null_object?
|
43
|
-
super
|
43
|
+
super
|
44
44
|
rescue NameError
|
45
|
-
__mock_proxy.raise_unexpected_message_error
|
45
|
+
__mock_proxy.raise_unexpected_message_error(sym, *args)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -87,7 +87,7 @@ module RSpec
|
|
87
87
|
method_double[method_name].expectations.detect {|expectation| expectation.negative_expectation_for?(method_name)}
|
88
88
|
end
|
89
89
|
|
90
|
-
def record_message_received(method_name, args, block)
|
90
|
+
def record_message_received(method_name, *args, &block)
|
91
91
|
@messages_received << [method_name, args, block]
|
92
92
|
end
|
93
93
|
|
@@ -97,18 +97,18 @@ module RSpec
|
|
97
97
|
|
98
98
|
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
|
99
99
|
if expectation = find_almost_matching_expectation(method_name, *args)
|
100
|
-
expectation.advise(args
|
100
|
+
expectation.advise(*args) unless expectation.expected_messages_received?
|
101
101
|
end
|
102
|
-
stub.invoke(args, block)
|
102
|
+
stub.invoke(*args, &block)
|
103
103
|
elsif expectation
|
104
|
-
expectation.invoke(args, block)
|
104
|
+
expectation.invoke(*args, &block)
|
105
105
|
elsif expectation = find_almost_matching_expectation(method_name, *args)
|
106
|
-
expectation.advise(args
|
106
|
+
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
|
107
107
|
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(method_name) or null_object?)
|
108
108
|
elsif @object.is_a?(Class)
|
109
109
|
@object.superclass.send(method_name, *args, &block)
|
110
110
|
else
|
111
|
-
@object.__send__
|
111
|
+
@object.__send__(:method_missing, method_name, *args, &block)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -133,16 +133,16 @@ module RSpec
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def find_matching_expectation(method_name, *args)
|
136
|
-
method_double[method_name].expectations.find {|expectation| expectation.matches(method_name, args) && !expectation.called_max_times?} ||
|
137
|
-
method_double[method_name].expectations.find {|expectation| expectation.matches(method_name, args)}
|
136
|
+
method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args) && !expectation.called_max_times?} ||
|
137
|
+
method_double[method_name].expectations.find {|expectation| expectation.matches?(method_name, *args)}
|
138
138
|
end
|
139
139
|
|
140
140
|
def find_almost_matching_expectation(method_name, *args)
|
141
|
-
method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, args)}
|
141
|
+
method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args)}
|
142
142
|
end
|
143
143
|
|
144
144
|
def find_matching_method_stub(method_name, *args)
|
145
|
-
method_double[method_name].stubs.find {|stub| stub.matches(method_name, args)}
|
145
|
+
method_double[method_name].stubs.find {|stub| stub.matches?(method_name, *args)}
|
146
146
|
end
|
147
147
|
|
148
148
|
end
|
data/rspec-mocks.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rspec-mocks}
|
8
|
-
s.version = "2.0.0.beta.
|
8
|
+
s.version = "2.0.0.beta.20"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["David Chelimsky", "Chad Humphries"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-24}
|
13
13
|
s.description = %q{RSpec's 'test double' framework, with support for stubbing and mocking}
|
14
14
|
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -99,17 +99,11 @@ Gem::Specification.new do |s|
|
|
99
99
|
"specs.watchr"
|
100
100
|
]
|
101
101
|
s.homepage = %q{http://github.com/rspec/mocks}
|
102
|
-
s.post_install_message = %q{**************************************************
|
103
|
-
|
104
|
-
Thank you for installing rspec-mocks-2.0.0.beta.19
|
105
|
-
|
106
|
-
**************************************************
|
107
|
-
}
|
108
102
|
s.rdoc_options = ["--charset=UTF-8"]
|
109
103
|
s.require_paths = ["lib"]
|
110
104
|
s.rubyforge_project = %q{rspec}
|
111
105
|
s.rubygems_version = %q{1.3.7}
|
112
|
-
s.summary = %q{rspec-mocks-2.0.0.beta.
|
106
|
+
s.summary = %q{rspec-mocks-2.0.0.beta.20}
|
113
107
|
s.test_files = [
|
114
108
|
"spec/rspec/mocks/and_yield_spec.rb",
|
115
109
|
"spec/rspec/mocks/any_number_of_times_spec.rb",
|
@@ -162,15 +156,15 @@ Gem::Specification.new do |s|
|
|
162
156
|
s.specification_version = 3
|
163
157
|
|
164
158
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
165
|
-
s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.
|
166
|
-
s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.
|
159
|
+
s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
|
160
|
+
s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
|
167
161
|
else
|
168
|
-
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.
|
169
|
-
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.
|
162
|
+
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
|
163
|
+
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
|
170
164
|
end
|
171
165
|
else
|
172
|
-
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.
|
173
|
-
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.
|
166
|
+
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.20"])
|
167
|
+
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.20"])
|
174
168
|
end
|
175
169
|
end
|
176
170
|
|
@@ -8,23 +8,23 @@ module RSpec
|
|
8
8
|
@mock = RSpec::Mocks::Mock.new("test mock")
|
9
9
|
end
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "passes if any number of times method is called many times" do
|
12
12
|
@mock.should_receive(:random_call).any_number_of_times
|
13
13
|
(1..10).each do
|
14
14
|
@mock.random_call
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
it "
|
18
|
+
it "passes if any number of times method is called once" do
|
19
19
|
@mock.should_receive(:random_call).any_number_of_times
|
20
20
|
@mock.random_call
|
21
21
|
end
|
22
22
|
|
23
|
-
it "
|
23
|
+
it "passes if any number of times method is not called" do
|
24
24
|
@mock.should_receive(:random_call).any_number_of_times
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "returns the mocked value when called after a similar stub" do
|
28
28
|
@mock.stub(:message).and_return :stub_value
|
29
29
|
@mock.should_receive(:message).any_number_of_times.and_return(:mock_value)
|
30
30
|
@mock.message.should == :mock_value
|
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe ArgumentExpectation do
|
6
|
-
it "
|
7
|
-
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
6
|
+
it "considers an object that responds to #matches? and #description to be a matcher" do
|
7
|
+
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
8
8
|
obj = double("matcher")
|
9
9
|
obj.should_receive(:respond_to?).with(:matches?).and_return(true)
|
10
10
|
obj.should_receive(:respond_to?).with(:description).and_return(true)
|
11
11
|
argument_expecatation.is_matcher?(obj).should be_true
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
15
|
-
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
14
|
+
it "does NOT consider an object that only responds to #matches? to be a matcher" do
|
15
|
+
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
16
16
|
obj = double("matcher")
|
17
17
|
obj.should_receive(:respond_to?).with(:matches?).and_return(true)
|
18
18
|
obj.should_receive(:respond_to?).with(:description).and_return(false)
|
@@ -7,14 +7,14 @@ module RSpec
|
|
7
7
|
@mock = RSpec::Mocks::Mock.new("test mock")
|
8
8
|
end
|
9
9
|
|
10
|
-
it "
|
10
|
+
it "fails if method is never called" do
|
11
11
|
@mock.should_receive(:random_call).at_least(4).times
|
12
12
|
lambda do
|
13
13
|
@mock.rspec_verify
|
14
14
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
15
15
|
end
|
16
16
|
|
17
|
-
it "
|
17
|
+
it "fails when called less than n times" do
|
18
18
|
@mock.should_receive(:random_call).at_least(4).times
|
19
19
|
@mock.random_call
|
20
20
|
@mock.random_call
|
@@ -24,14 +24,14 @@ module RSpec
|
|
24
24
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
25
25
|
end
|
26
26
|
|
27
|
-
it "
|
27
|
+
it "fails when at least once method is never called" do
|
28
28
|
@mock.should_receive(:random_call).at_least(:once)
|
29
29
|
lambda do
|
30
30
|
@mock.rspec_verify
|
31
31
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "fails when at least twice method is called once" do
|
35
35
|
@mock.should_receive(:random_call).at_least(:twice)
|
36
36
|
@mock.random_call
|
37
37
|
lambda do
|
@@ -39,14 +39,14 @@ module RSpec
|
|
39
39
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "fails when at least twice method is never called" do
|
43
43
|
@mock.should_receive(:random_call).at_least(:twice)
|
44
44
|
lambda do
|
45
45
|
@mock.rspec_verify
|
46
46
|
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "passes when at least n times method is called exactly n times" do
|
50
50
|
@mock.should_receive(:random_call).at_least(4).times
|
51
51
|
@mock.random_call
|
52
52
|
@mock.random_call
|
@@ -55,7 +55,7 @@ module RSpec
|
|
55
55
|
@mock.rspec_verify
|
56
56
|
end
|
57
57
|
|
58
|
-
it "
|
58
|
+
it "passes when at least n times method is called n plus 1 times" do
|
59
59
|
@mock.should_receive(:random_call).at_least(4).times
|
60
60
|
@mock.random_call
|
61
61
|
@mock.random_call
|
@@ -65,20 +65,20 @@ module RSpec
|
|
65
65
|
@mock.rspec_verify
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "passes when at least once method is called once" do
|
69
69
|
@mock.should_receive(:random_call).at_least(:once)
|
70
70
|
@mock.random_call
|
71
71
|
@mock.rspec_verify
|
72
72
|
end
|
73
73
|
|
74
|
-
it "
|
74
|
+
it "passes when at least once method is called twice" do
|
75
75
|
@mock.should_receive(:random_call).at_least(:once)
|
76
76
|
@mock.random_call
|
77
77
|
@mock.random_call
|
78
78
|
@mock.rspec_verify
|
79
79
|
end
|
80
80
|
|
81
|
-
it "
|
81
|
+
it "passes when at least twice method is called three times" do
|
82
82
|
@mock.should_receive(:random_call).at_least(:twice)
|
83
83
|
@mock.random_call
|
84
84
|
@mock.random_call
|
@@ -86,7 +86,7 @@ module RSpec
|
|
86
86
|
@mock.rspec_verify
|
87
87
|
end
|
88
88
|
|
89
|
-
it "
|
89
|
+
it "passes when at least twice method is called twice" do
|
90
90
|
@mock.should_receive(:random_call).at_least(:twice)
|
91
91
|
@mock.random_call
|
92
92
|
@mock.random_call
|