rspec-mocks 2.0.0.beta.8 → 2.0.0.beta.9
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/README.markdown +1 -1
- data/Rakefile +10 -10
- data/VERSION +1 -1
- data/features/mocks/block_local_expectations.feature +5 -5
- data/features/mocks/mix_stubs_and_mocks.feature +2 -2
- data/features/mocks/warn_when_expectation_is_set_on_nil.feature +6 -6
- data/features/stubs/stub_implementation.feature +2 -2
- data/lib/rspec/mocks.rb +112 -137
- data/lib/rspec/mocks/argument_expectation.rb +1 -1
- data/lib/rspec/mocks/argument_matchers.rb +1 -1
- data/lib/rspec/mocks/error_generator.rb +2 -2
- data/lib/rspec/mocks/errors.rb +1 -1
- data/lib/rspec/mocks/extensions/instance_exec.rb +2 -2
- data/lib/rspec/mocks/extensions/object.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +3 -3
- data/lib/rspec/mocks/method_double.rb +3 -3
- data/lib/rspec/mocks/methods.rb +1 -1
- data/lib/rspec/mocks/mock.rb +9 -6
- data/lib/rspec/mocks/order_group.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +9 -8
- data/lib/rspec/mocks/space.rb +1 -1
- data/lib/rspec/mocks/spec_methods.rb +13 -15
- data/lib/rspec/mocks/version.rb +1 -1
- data/rspec-mocks.gemspec +11 -11
- data/spec/rspec/mocks/and_yield_spec.rb +4 -4
- data/spec/rspec/mocks/any_number_of_times_spec.rb +2 -2
- data/spec/rspec/mocks/argument_expectation_spec.rb +3 -3
- data/spec/rspec/mocks/at_least_spec.rb +7 -7
- data/spec/rspec/mocks/at_most_spec.rb +5 -5
- data/spec/rspec/mocks/bug_report_10260_spec.rb +1 -1
- data/spec/rspec/mocks/bug_report_15719_spec.rb +3 -3
- data/spec/rspec/mocks/bug_report_830_spec.rb +2 -2
- data/spec/rspec/mocks/double_spec.rb +1 -1
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +14 -14
- data/spec/rspec/mocks/hash_including_matcher_spec.rb +1 -1
- data/spec/rspec/mocks/hash_not_including_matcher_spec.rb +1 -1
- data/spec/rspec/mocks/mock_ordering_spec.rb +4 -4
- data/spec/rspec/mocks/mock_space_spec.rb +2 -2
- data/spec/rspec/mocks/mock_spec.rb +32 -25
- data/spec/rspec/mocks/multiple_return_value_spec.rb +12 -12
- data/spec/rspec/mocks/nil_expectation_warning_spec.rb +3 -3
- data/spec/rspec/mocks/null_object_mock_spec.rb +3 -3
- data/spec/rspec/mocks/once_counts_spec.rb +4 -4
- data/spec/rspec/mocks/options_hash_spec.rb +4 -4
- data/spec/rspec/mocks/partial_mock_spec.rb +9 -9
- data/spec/rspec/mocks/partial_mock_using_mocks_directly_spec.rb +3 -3
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -3
- data/spec/rspec/mocks/precise_counts_spec.rb +3 -3
- data/spec/rspec/mocks/record_messages_spec.rb +2 -2
- data/spec/rspec/mocks/stash_spec.rb +1 -1
- data/spec/rspec/mocks/stub_chain_spec.rb +1 -1
- data/spec/rspec/mocks/stub_implementation_spec.rb +1 -1
- data/spec/rspec/mocks/stub_spec.rb +1 -1
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +2 -2
- data/spec/rspec/mocks/twice_counts_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -4
- metadata +10 -10
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
class ErrorGenerator
|
4
4
|
attr_writer :opts
|
@@ -67,7 +67,7 @@ module Rspec
|
|
67
67
|
|
68
68
|
def __raise(message)
|
69
69
|
message = opts[:message] unless opts[:message].nil?
|
70
|
-
Kernel::raise(
|
70
|
+
Kernel::raise(RSpec::Mocks::MockExpectationError, message)
|
71
71
|
end
|
72
72
|
|
73
73
|
def arg_message(*args)
|
data/lib/rspec/mocks/errors.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
|
4
4
|
class BaseExpectation
|
@@ -90,7 +90,7 @@ module Rspec
|
|
90
90
|
if block
|
91
91
|
require 'rspec/mocks/extensions/instance_exec'
|
92
92
|
@eval_context = Object.new
|
93
|
-
@eval_context.extend
|
93
|
+
@eval_context.extend RSpec::Mocks::InstanceExec
|
94
94
|
yield @eval_context
|
95
95
|
end
|
96
96
|
|
@@ -206,7 +206,7 @@ module Rspec
|
|
206
206
|
return if expected_messages_received? || failed_fast?
|
207
207
|
|
208
208
|
generate_error
|
209
|
-
rescue
|
209
|
+
rescue RSpec::Mocks::MockExpectationError => error
|
210
210
|
error.backtrace.insert(0, @expected_from)
|
211
211
|
Kernel::raise error
|
212
212
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
class MethodDouble < Hash
|
4
4
|
attr_reader :method_name
|
@@ -145,13 +145,13 @@ module Rspec
|
|
145
145
|
end
|
146
146
|
|
147
147
|
def warn_if_nil_class
|
148
|
-
if proxy_for_nil_class? &
|
148
|
+
if proxy_for_nil_class? & RSpec::Mocks::Proxy.warn_about_expectations_on_nil
|
149
149
|
Kernel.warn("An expectation of :#{@method_name} was set on nil. Called from #{caller[4]}. Use allow_message_expectations_on_nil to disable warnings.")
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
def reset_nil_expectations_warning
|
154
|
-
|
154
|
+
RSpec::Mocks::Proxy.warn_about_expectations_on_nil = true if proxy_for_nil_class?
|
155
155
|
end
|
156
156
|
end
|
157
157
|
end
|
data/lib/rspec/mocks/methods.rb
CHANGED
data/lib/rspec/mocks/mock.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
class Mock
|
4
4
|
include Methods
|
5
5
|
|
6
|
-
# Creates a new
|
7
|
-
# only)
|
8
|
-
# * <tt>:null_object</tt> - if true, the mock object acts as a forgiving
|
9
|
-
# null object allowing any message to be sent to it.
|
6
|
+
# Creates a new test double with a +name+ (that will be used in error messages
|
7
|
+
# only)
|
10
8
|
def initialize(name=nil, stubs_and_options={})
|
11
9
|
if name.is_a?(Hash) && stubs_and_options.empty?
|
12
10
|
stubs_and_options = name
|
@@ -34,6 +32,8 @@ module Rspec
|
|
34
32
|
inspect.gsub('<','[').gsub('>',']')
|
35
33
|
end
|
36
34
|
|
35
|
+
alias_method :to_str, :to_s
|
36
|
+
|
37
37
|
private
|
38
38
|
|
39
39
|
def method_missing(sym, *args, &block)
|
@@ -47,8 +47,11 @@ module Rspec
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def extract_options(stubs_and_options)
|
50
|
+
if stubs_and_options[:null_object]
|
51
|
+
@null_object = stubs_and_options.delete(:null_object)
|
52
|
+
RSpec.deprecate(%Q["double('name', :null_object => true)"], %Q["double('name').as_null_object"])
|
53
|
+
end
|
50
54
|
options = {}
|
51
|
-
extract_option(stubs_and_options, options, :null_object)
|
52
55
|
extract_option(stubs_and_options, options, :__declared_as, 'Mock')
|
53
56
|
options
|
54
57
|
end
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
class Proxy
|
4
|
-
DEFAULT_OPTIONS = { :null_object => false }
|
5
|
-
|
6
4
|
class << self
|
7
5
|
def warn_about_expectations_on_nil
|
8
6
|
defined?(@warn_about_expectations_on_nil) ? @warn_about_expectations_on_nil : true
|
@@ -31,24 +29,27 @@ module Rspec
|
|
31
29
|
@error_generator = ErrorGenerator.new object, name, options
|
32
30
|
@expectation_ordering = OrderGroup.new @error_generator
|
33
31
|
@messages_received = []
|
34
|
-
@options = options
|
32
|
+
@options = options
|
35
33
|
@already_proxied_respond_to = false
|
34
|
+
@null_object = false
|
36
35
|
end
|
37
36
|
|
38
37
|
def null_object?
|
39
|
-
@
|
38
|
+
@null_object
|
40
39
|
end
|
41
40
|
|
41
|
+
# Tells the object to ignore any messages that aren't explicitly set as
|
42
|
+
# stubs or message expectations.
|
42
43
|
def as_null_object
|
43
|
-
@
|
44
|
+
@null_object = true
|
44
45
|
@object
|
45
46
|
end
|
46
47
|
|
47
|
-
def already_proxied_respond_to
|
48
|
+
def already_proxied_respond_to # :nodoc:
|
48
49
|
@already_proxied_respond_to = true
|
49
50
|
end
|
50
51
|
|
51
|
-
def already_proxied_respond_to?
|
52
|
+
def already_proxied_respond_to? # :nodoc:
|
52
53
|
@already_proxied_respond_to
|
53
54
|
end
|
54
55
|
|
data/lib/rspec/mocks/space.rb
CHANGED
@@ -1,25 +1,23 @@
|
|
1
|
-
module
|
1
|
+
module RSpec
|
2
2
|
module Mocks
|
3
3
|
module ExampleMethods
|
4
|
-
include
|
4
|
+
include RSpec::Mocks::ArgumentMatchers
|
5
5
|
|
6
|
-
#
|
6
|
+
# Creates an instance of RSpec::Mocks::Mock.
|
7
7
|
#
|
8
|
-
# +name+ is used for failure reporting, so you should use the
|
9
|
-
#
|
8
|
+
# +name+ is used for failure reporting, so you should use the role that
|
9
|
+
# the mock is playing in the example.
|
10
10
|
#
|
11
|
-
# +
|
12
|
-
# at the same time. The only option available is :null_object.
|
13
|
-
# Anything else is treated as a stub value.
|
11
|
+
# Use +stubs+ to declare one or more method stubs in one statement.
|
14
12
|
#
|
15
13
|
# == Examples
|
16
14
|
#
|
17
|
-
#
|
18
|
-
#
|
15
|
+
# book = double("book", :title => "The RSpec Book")
|
16
|
+
# book.title => "The RSpec Book"
|
19
17
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
18
|
+
# card = double("card", :suit => "Spades", :rank => "A"
|
19
|
+
# card.suit => "Spades"
|
20
|
+
# card.rank => "A"
|
23
21
|
def double(*args)
|
24
22
|
declare_double('Double', *args)
|
25
23
|
end
|
@@ -44,10 +42,10 @@ module Rspec
|
|
44
42
|
|
45
43
|
private
|
46
44
|
|
47
|
-
def declare_double(declared_as, *args)
|
45
|
+
def declare_double(declared_as, *args)
|
48
46
|
args << {} unless Hash === args.last
|
49
47
|
args.last[:__declared_as] = declared_as
|
50
|
-
|
48
|
+
RSpec::Mocks::Mock.new(*args)
|
51
49
|
end
|
52
50
|
|
53
51
|
end
|
data/lib/rspec/mocks/version.rb
CHANGED
data/rspec-mocks.gemspec
CHANGED
@@ -5,12 +5,12 @@
|
|
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.9"
|
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-
|
13
|
-
s.description = %q{
|
12
|
+
s.date = %q{2010-05-27}
|
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 = [
|
16
16
|
"README.markdown"
|
@@ -98,7 +98,7 @@ Gem::Specification.new do |s|
|
|
98
98
|
s.homepage = %q{http://github.com/rspec/mocks}
|
99
99
|
s.post_install_message = %q{**************************************************
|
100
100
|
|
101
|
-
Thank you for installing rspec-mocks-2.0.0.beta.
|
101
|
+
Thank you for installing rspec-mocks-2.0.0.beta.9
|
102
102
|
|
103
103
|
This is beta software. If you are looking
|
104
104
|
for a supported production release, please
|
@@ -110,7 +110,7 @@ Gem::Specification.new do |s|
|
|
110
110
|
s.require_paths = ["lib"]
|
111
111
|
s.rubyforge_project = %q{rspec}
|
112
112
|
s.rubygems_version = %q{1.3.6}
|
113
|
-
s.summary = %q{rspec-mocks-2.0.0.beta.
|
113
|
+
s.summary = %q{rspec-mocks-2.0.0.beta.9}
|
114
114
|
s.test_files = [
|
115
115
|
"spec/rspec/mocks/and_yield_spec.rb",
|
116
116
|
"spec/rspec/mocks/any_number_of_times_spec.rb",
|
@@ -162,15 +162,15 @@ Gem::Specification.new do |s|
|
|
162
162
|
s.specification_version = 3
|
163
163
|
|
164
164
|
if Gem::Version.new(Gem::RubyGemsVersion) >= 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.
|
165
|
+
s.add_development_dependency(%q<rspec-core>, ["= 2.0.0.beta.9"])
|
166
|
+
s.add_development_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.9"])
|
167
167
|
else
|
168
|
-
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.
|
169
|
-
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.
|
168
|
+
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.9"])
|
169
|
+
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.9"])
|
170
170
|
end
|
171
171
|
else
|
172
|
-
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.
|
173
|
-
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.
|
172
|
+
s.add_dependency(%q<rspec-core>, ["= 2.0.0.beta.9"])
|
173
|
+
s.add_dependency(%q<rspec-expectations>, ["= 2.0.0.beta.9"])
|
174
174
|
end
|
175
175
|
end
|
176
176
|
|
@@ -3,7 +3,7 @@ def obj
|
|
3
3
|
@obj ||= mock
|
4
4
|
end
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe RSpec::Mocks::Mock do
|
7
7
|
describe "#and_yield" do
|
8
8
|
context "with eval context as block argument" do
|
9
9
|
|
@@ -63,7 +63,7 @@ describe Rspec::Mocks::Mock do
|
|
63
63
|
# foo is not called here
|
64
64
|
end
|
65
65
|
|
66
|
-
lambda {configured_eval_context.rspec_verify}.should raise_error(
|
66
|
+
lambda {configured_eval_context.rspec_verify}.should raise_error(RSpec::Mocks::MockExpectationError)
|
67
67
|
end
|
68
68
|
|
69
69
|
end
|
@@ -102,8 +102,8 @@ describe Rspec::Mocks::Mock do
|
|
102
102
|
# foo is not called here
|
103
103
|
end
|
104
104
|
|
105
|
-
lambda {configured_eval_context.rspec_verify}.should raise_error(
|
106
|
-
lambda {yielded_arg.rspec_verify}.should raise_error(
|
105
|
+
lambda {configured_eval_context.rspec_verify}.should raise_error(RSpec::Mocks::MockExpectationError)
|
106
|
+
lambda {yielded_arg.rspec_verify}.should raise_error(RSpec::Mocks::MockExpectationError)
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RSpec
|
4
4
|
module Mocks
|
5
5
|
|
6
6
|
describe "AnyNumberOfTimes" do
|
7
7
|
before(:each) do
|
8
|
-
@mock =
|
8
|
+
@mock = RSpec::Mocks::Mock.new("test mock")
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should pass if any number of times method is called many times" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe ArgumentExpectation do
|
6
6
|
it "should consider an object that responds to #matches? and #description to be a matcher" do
|
7
|
-
argument_expecatation =
|
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)
|
@@ -12,7 +12,7 @@ module Rspec
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should NOT consider an object that only responds to #matches? to be a matcher" do
|
15
|
-
argument_expecatation =
|
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)
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe "at_least" do
|
6
6
|
before(:each) do
|
7
|
-
@mock =
|
7
|
+
@mock = RSpec::Mocks::Mock.new("test mock")
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should fail 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
|
-
end.should raise_error(
|
14
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should fail when called less than n times" do
|
@@ -21,14 +21,14 @@ module Rspec
|
|
21
21
|
@mock.random_call
|
22
22
|
lambda do
|
23
23
|
@mock.rspec_verify
|
24
|
-
end.should raise_error(
|
24
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should fail 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
|
-
end.should raise_error(
|
31
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should fail when at least twice method is called once" do
|
@@ -36,14 +36,14 @@ module Rspec
|
|
36
36
|
@mock.random_call
|
37
37
|
lambda do
|
38
38
|
@mock.rspec_verify
|
39
|
-
end.should raise_error(
|
39
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should fail 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
|
-
end.should raise_error(
|
46
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should pass when at least n times method is called exactly n times" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
module
|
3
|
+
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe "at_most" do
|
6
6
|
before(:each) do
|
7
|
-
@mock =
|
7
|
+
@mock = RSpec::Mocks::Mock.new("test mock")
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should fail when at most n times method is called n plus 1 times" do
|
@@ -16,7 +16,7 @@ module Rspec
|
|
16
16
|
@mock.random_call
|
17
17
|
lambda do
|
18
18
|
@mock.rspec_verify
|
19
|
-
end.should raise_error(
|
19
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should fail when at most once method is called twice" do
|
@@ -25,7 +25,7 @@ module Rspec
|
|
25
25
|
@mock.random_call
|
26
26
|
lambda do
|
27
27
|
@mock.rspec_verify
|
28
|
-
end.should raise_error(
|
28
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should fail when at most twice method is called three times" do
|
@@ -35,7 +35,7 @@ module Rspec
|
|
35
35
|
@mock.random_call
|
36
36
|
lambda do
|
37
37
|
@mock.rspec_verify
|
38
|
-
end.should raise_error(
|
38
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError)
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should pass when at most n times method is called exactly n times" do
|