redinger-rr 0.10.3
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/CHANGES +221 -0
- data/README.rdoc +343 -0
- data/Rakefile +88 -0
- data/VERSION.yml +4 -0
- data/lib/rr.rb +88 -0
- data/lib/rr/adapters/rr_methods.rb +122 -0
- data/lib/rr/adapters/rspec.rb +59 -0
- data/lib/rr/adapters/test_unit.rb +29 -0
- data/lib/rr/double.rb +152 -0
- data/lib/rr/double_definitions/child_double_definition_creator.rb +27 -0
- data/lib/rr/double_definitions/double_definition.rb +348 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +167 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +37 -0
- data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
- data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
- data/lib/rr/double_definitions/strategies/implementation/strongly_typed_reimplementation.rb +17 -0
- data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +50 -0
- data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
- data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
- data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
- data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
- data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
- data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
- data/lib/rr/double_injection.rb +180 -0
- data/lib/rr/double_matches.rb +51 -0
- data/lib/rr/errors/argument_equality_error.rb +6 -0
- data/lib/rr/errors/double_definition_error.rb +6 -0
- data/lib/rr/errors/double_not_found_error.rb +6 -0
- data/lib/rr/errors/double_order_error.rb +6 -0
- data/lib/rr/errors/rr_error.rb +20 -0
- data/lib/rr/errors/spy_verification_errors/double_injection_not_found_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/invocation_count_error.rb +8 -0
- data/lib/rr/errors/spy_verification_errors/spy_verification_error.rb +8 -0
- data/lib/rr/errors/subject_does_not_implement_method_error.rb +6 -0
- data/lib/rr/errors/subject_has_different_arity_error.rb +6 -0
- data/lib/rr/errors/times_called_error.rb +6 -0
- data/lib/rr/expectations/any_argument_expectation.rb +21 -0
- data/lib/rr/expectations/argument_equality_expectation.rb +41 -0
- data/lib/rr/expectations/times_called_expectation.rb +57 -0
- data/lib/rr/hash_with_object_id_key.rb +44 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +108 -0
- data/lib/rr/method_dispatches/method_dispatch.rb +61 -0
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +49 -0
- data/lib/rr/proc_from_block.rb +7 -0
- data/lib/rr/recorded_calls.rb +103 -0
- data/lib/rr/space.rb +123 -0
- data/lib/rr/spy_verification.rb +48 -0
- data/lib/rr/spy_verification_proxy.rb +18 -0
- data/lib/rr/times_called_matchers/any_times_matcher.rb +18 -0
- data/lib/rr/times_called_matchers/at_least_matcher.rb +15 -0
- data/lib/rr/times_called_matchers/at_most_matcher.rb +23 -0
- data/lib/rr/times_called_matchers/integer_matcher.rb +19 -0
- data/lib/rr/times_called_matchers/non_terminal.rb +27 -0
- data/lib/rr/times_called_matchers/proc_matcher.rb +11 -0
- data/lib/rr/times_called_matchers/range_matcher.rb +21 -0
- data/lib/rr/times_called_matchers/terminal.rb +20 -0
- data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
- data/lib/rr/wildcard_matchers.rb +158 -0
- data/lib/rr/wildcard_matchers/anything.rb +18 -0
- data/lib/rr/wildcard_matchers/boolean.rb +23 -0
- data/lib/rr/wildcard_matchers/duck_type.rb +32 -0
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/is_a.rb +25 -0
- data/lib/rr/wildcard_matchers/numeric.rb +13 -0
- data/lib/rr/wildcard_matchers/range.rb +7 -0
- data/lib/rr/wildcard_matchers/regexp.rb +7 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/core_spec_suite.rb +19 -0
- data/spec/environment_fixture_setup.rb +7 -0
- data/spec/high_level_spec.rb +398 -0
- data/spec/proc_from_block_spec.rb +14 -0
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +149 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +115 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +17 -0
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +112 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +155 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +502 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1165 -0
- data/spec/rr/double_injection/double_injection_spec.rb +339 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +352 -0
- data/spec/rr/errors/rr_error_spec.rb +67 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +34 -0
- data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/rr/expectations/hash_including_spec.rb +17 -0
- data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/satisfy_spec.rb +14 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +46 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +69 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +23 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +104 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +83 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +38 -0
- data/spec/rr/rspec/invocation_matcher_spec.rb +279 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +66 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +31 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec_fixture.rb +11 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +86 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_spec.rb +550 -0
- data/spec/rr/test_unit/test_helper.rb +7 -0
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +36 -0
- data/spec/rr/test_unit/test_unit_integration_test.rb +57 -0
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
- data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
- data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
- data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
- data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
- data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
- data/spec/rr_spec.rb +28 -0
- data/spec/rspec_spec_suite.rb +17 -0
- data/spec/spec_helper.rb +109 -0
- data/spec/spec_suite.rb +31 -0
- data/spec/spy_verification_spec.rb +129 -0
- data/spec/test_unit_spec_suite.rb +21 -0
- metadata +193 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
describe ProcFromBlock do
|
5
|
+
describe "#==" do
|
6
|
+
it "acts the same as #== on a Proc" do
|
7
|
+
original_proc = lambda {}
|
8
|
+
Proc.new(&original_proc).should == original_proc
|
9
|
+
|
10
|
+
ProcFromBlock.new(&original_proc).should == original_proc
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe RRMethods do
|
6
|
+
describe "#anything" do
|
7
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
8
|
+
|
9
|
+
it "returns an Anything matcher" do
|
10
|
+
anything.should == WildcardMatchers::Anything.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "rr_anything returns an Anything matcher" do
|
14
|
+
rr_anything.should == WildcardMatchers::Anything.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#is_a" do
|
19
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
20
|
+
|
21
|
+
it "returns an IsA matcher" do
|
22
|
+
is_a(Integer).should == WildcardMatchers::IsA.new(Integer)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "rr_is_a returns an IsA matcher" do
|
26
|
+
rr_is_a(Integer).should == WildcardMatchers::IsA.new(Integer)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#numeric" do
|
31
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
32
|
+
|
33
|
+
it "returns an Numeric matcher" do
|
34
|
+
numeric.should == WildcardMatchers::Numeric.new
|
35
|
+
end
|
36
|
+
|
37
|
+
it "rr_numeric returns an Numeric matcher" do
|
38
|
+
rr_numeric.should == WildcardMatchers::Numeric.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#boolean" do
|
43
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
44
|
+
|
45
|
+
it "returns an Boolean matcher" do
|
46
|
+
boolean.should == WildcardMatchers::Boolean.new
|
47
|
+
end
|
48
|
+
|
49
|
+
it "rr_boolean returns an Boolean matcher" do
|
50
|
+
rr_boolean.should == WildcardMatchers::Boolean.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#duck_type" do
|
55
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
56
|
+
|
57
|
+
it "returns a DuckType matcher" do
|
58
|
+
duck_type(:one, :two).should == WildcardMatchers::DuckType.new(:one, :two)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "rr_duck_type returns a DuckType matcher" do
|
62
|
+
rr_duck_type(:one, :two).should == WildcardMatchers::DuckType.new(:one, :two)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe RRMethods do
|
6
|
+
attr_reader :subject
|
7
|
+
before(:each) do
|
8
|
+
@subject = Object.new
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:each) do
|
12
|
+
RR.reset
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "normal strategy definitions" do
|
16
|
+
attr_reader :strategy_method_name
|
17
|
+
def call_strategy(*args, &block)
|
18
|
+
__send__(strategy_method_name, *args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#mock" do
|
22
|
+
before do
|
23
|
+
@strategy_method_name = :mock
|
24
|
+
end
|
25
|
+
|
26
|
+
send("normal strategy definition")
|
27
|
+
|
28
|
+
context "when passing no args" do
|
29
|
+
it "returns a DoubleDefinitionCreator" do
|
30
|
+
call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when passed a method_name argument" do
|
35
|
+
it "creates a mock Double for method" do
|
36
|
+
double_definition = mock(subject, :foobar).returns {:baz}
|
37
|
+
double_definition.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
|
38
|
+
double_definition.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
|
39
|
+
double_definition.argument_expectation.expected_arguments.should == []
|
40
|
+
subject.foobar.should == :baz
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#stub" do
|
46
|
+
before do
|
47
|
+
@strategy_method_name = :stub
|
48
|
+
end
|
49
|
+
|
50
|
+
send("normal strategy definition")
|
51
|
+
|
52
|
+
context "when passing no args" do
|
53
|
+
it "returns a DoubleDefinitionCreator" do
|
54
|
+
call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when passed a method_name argument" do
|
59
|
+
it "creates a stub Double for method when passed a method_name argument" do
|
60
|
+
double_definition = stub(subject, :foobar).returns {:baz}
|
61
|
+
double_definition.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
|
62
|
+
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
63
|
+
subject.foobar.should == :baz
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#dont_allow" do
|
69
|
+
before do
|
70
|
+
@strategy_method_name = :dont_allow
|
71
|
+
end
|
72
|
+
|
73
|
+
send("normal strategy definition")
|
74
|
+
|
75
|
+
context "when passing no args" do
|
76
|
+
it "returns a DoubleDefinitionCreator" do
|
77
|
+
call_strategy.class.should == DoubleDefinitions::DoubleDefinitionCreator
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "when passed a method_name argument_expectation" do
|
82
|
+
it "creates a mock Double for method" do
|
83
|
+
double_definition = dont_allow(subject, :foobar)
|
84
|
+
double_definition.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
|
85
|
+
double_definition.argument_expectation.class.should == RR::Expectations::AnyArgumentExpectation
|
86
|
+
|
87
|
+
lambda do
|
88
|
+
subject.foobar
|
89
|
+
end.should raise_error(Errors::TimesCalledError)
|
90
|
+
RR.reset
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "! strategy definitions" do
|
97
|
+
attr_reader :strategy_method_name
|
98
|
+
def call_strategy(*args, &definition_eval_block)
|
99
|
+
__send__(strategy_method_name, *args, &definition_eval_block)
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#mock!" do
|
103
|
+
before do
|
104
|
+
@strategy_method_name = :mock!
|
105
|
+
end
|
106
|
+
|
107
|
+
send("! strategy definition")
|
108
|
+
|
109
|
+
context "when passed a method_name argument" do
|
110
|
+
it "sets #verification_strategy to Mock" do
|
111
|
+
proxy = mock!(:foobar)
|
112
|
+
proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Mock
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#stub!" do
|
118
|
+
before do
|
119
|
+
@strategy_method_name = :stub!
|
120
|
+
end
|
121
|
+
|
122
|
+
send("! strategy definition")
|
123
|
+
|
124
|
+
context "when passed a method_name argument" do
|
125
|
+
it "sets #verification_strategy to Stub" do
|
126
|
+
proxy = stub!(:foobar)
|
127
|
+
proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::Stub
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#dont_allow!" do
|
133
|
+
before do
|
134
|
+
@strategy_method_name = :dont_allow!
|
135
|
+
end
|
136
|
+
|
137
|
+
send("! strategy definition")
|
138
|
+
|
139
|
+
context "when passed a method_name argument" do
|
140
|
+
it "sets #verification_strategy to DontAllow" do
|
141
|
+
proxy = dont_allow!(:foobar)
|
142
|
+
proxy.double_definition_creator.verification_strategy.class.should == RR::DoubleDefinitions::Strategies::Verification::DontAllow
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe RRMethods do
|
6
|
+
attr_reader :space, :subject_1, :subject_2, :method_name
|
7
|
+
it_should_behave_like "Swapped Space"
|
8
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
9
|
+
before do
|
10
|
+
@subject_1 = Object.new
|
11
|
+
@subject_2 = Object.new
|
12
|
+
@method_name = :foobar
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#verify" do
|
16
|
+
it "aliases #rr_verify" do
|
17
|
+
RRMethods.instance_method("verify").should == RRMethods.instance_method("rr_verify")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#rr_verify" do
|
22
|
+
it "verifies and deletes the double_injections" do
|
23
|
+
double_1 = space.double_injection(subject_1, method_name)
|
24
|
+
double_1_verify_calls = 0
|
25
|
+
double_1_reset_calls = 0
|
26
|
+
(
|
27
|
+
class << double_1;
|
28
|
+
self;
|
29
|
+
end).class_eval do
|
30
|
+
define_method(:verify) do ||
|
31
|
+
double_1_verify_calls += 1
|
32
|
+
end
|
33
|
+
define_method(:reset) do ||
|
34
|
+
double_1_reset_calls += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
double_2 = space.double_injection(subject_2, method_name)
|
38
|
+
double_2_verify_calls = 0
|
39
|
+
double_2_reset_calls = 0
|
40
|
+
(
|
41
|
+
class << double_2;
|
42
|
+
self;
|
43
|
+
end).class_eval do
|
44
|
+
define_method(:verify) do ||
|
45
|
+
double_2_verify_calls += 1
|
46
|
+
end
|
47
|
+
define_method(:reset) do ||
|
48
|
+
double_2_reset_calls += 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
rr_verify
|
53
|
+
double_1_verify_calls.should == 1
|
54
|
+
double_2_verify_calls.should == 1
|
55
|
+
double_1_reset_calls.should == 1
|
56
|
+
double_1_reset_calls.should == 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#reset" do
|
61
|
+
it "aliases #rr_reset" do
|
62
|
+
RRMethods.instance_method("reset").should == RRMethods.instance_method("rr_reset")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#rr_reset" do
|
67
|
+
it "removes the ordered doubles" do
|
68
|
+
double_1 = new_double(
|
69
|
+
space.double_injection(subject_1, :foobar1),
|
70
|
+
RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject_1)
|
71
|
+
)
|
72
|
+
double_2 = new_double(
|
73
|
+
space.double_injection(subject_2, :foobar2),
|
74
|
+
RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject_2)
|
75
|
+
)
|
76
|
+
|
77
|
+
double_1.definition.ordered
|
78
|
+
double_2.definition.ordered
|
79
|
+
|
80
|
+
space.ordered_doubles.should_not be_empty
|
81
|
+
|
82
|
+
rr_reset
|
83
|
+
space.ordered_doubles.should be_empty
|
84
|
+
end
|
85
|
+
|
86
|
+
it "resets all double_injections" do
|
87
|
+
double_1 = space.double_injection(subject_1, method_name)
|
88
|
+
double_1_reset_calls = 0
|
89
|
+
(
|
90
|
+
class << double_1;
|
91
|
+
self;
|
92
|
+
end).class_eval do
|
93
|
+
define_method(:reset) do ||
|
94
|
+
double_1_reset_calls += 1
|
95
|
+
end
|
96
|
+
end
|
97
|
+
double_2 = space.double_injection(subject_2, method_name)
|
98
|
+
double_2_reset_calls = 0
|
99
|
+
(
|
100
|
+
class << double_2;
|
101
|
+
self;
|
102
|
+
end).class_eval do
|
103
|
+
define_method(:reset) do ||
|
104
|
+
double_2_reset_calls += 1
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
rr_reset
|
109
|
+
double_1_reset_calls.should == 1
|
110
|
+
double_2_reset_calls.should == 1
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Adapters
|
5
|
+
describe RRMethods, "#any_times" do
|
6
|
+
it_should_behave_like "RR::Adapters::RRMethods"
|
7
|
+
|
8
|
+
it "returns an AnyTimesMatcher" do
|
9
|
+
any_times.should == TimesCalledMatchers::AnyTimesMatcher.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "rr_any_times returns an AnyTimesMatcher" do
|
13
|
+
rr_any_times.should == TimesCalledMatchers::AnyTimesMatcher.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module DoubleDefinitions
|
5
|
+
describe ChildDoubleDefinitionCreator do
|
6
|
+
attr_reader :parent_subject, :parent_double_definition_creator, :parent_double_definition, :child_double_definition_creator
|
7
|
+
it_should_behave_like "Swapped Space"
|
8
|
+
before(:each) do
|
9
|
+
@parent_subject = Object.new
|
10
|
+
@parent_double_definition_creator = DoubleDefinitionCreator.new
|
11
|
+
@parent_double_definition = DoubleDefinition.new(parent_double_definition_creator, parent_subject)
|
12
|
+
@child_double_definition_creator = ChildDoubleDefinitionCreator.new(parent_double_definition)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#root_subject" do
|
16
|
+
it "returns the #parent_double_definition.root_subject" do
|
17
|
+
child_subject = Object.new
|
18
|
+
parent_double_definition_creator.stub(parent_subject)
|
19
|
+
child_double_definition_creator.stub(child_subject)
|
20
|
+
child_double_definition_creator.root_subject.should == parent_subject
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Strategies::Verification definitions" do
|
25
|
+
describe "methods without !" do
|
26
|
+
attr_reader :child_subject
|
27
|
+
before do
|
28
|
+
@child_subject = Object.new
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#mock" do
|
32
|
+
context "when passed a subject" do
|
33
|
+
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
34
|
+
parent_double_definition.implementation.should be_nil
|
35
|
+
child_double_definition_creator.mock(child_subject)
|
36
|
+
parent_double_definition.implementation.call.should == child_subject
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#stub" do
|
42
|
+
context "when passed a subject" do
|
43
|
+
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
44
|
+
parent_double_definition.implementation.should be_nil
|
45
|
+
child_double_definition_creator.stub(child_subject)
|
46
|
+
parent_double_definition.implementation.call.should == child_subject
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#dont_allow" do
|
52
|
+
context "when passed a subject" do
|
53
|
+
it "sets #parent_double_definition.implementation to a Proc returning the passed-in subject" do
|
54
|
+
parent_double_definition.implementation.should be_nil
|
55
|
+
child_double_definition_creator.dont_allow(child_subject)
|
56
|
+
parent_double_definition.implementation.call.should == child_subject
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "methods with !" do
|
63
|
+
describe "#mock!" do
|
64
|
+
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
65
|
+
parent_double_definition.implementation.should be_nil
|
66
|
+
child_subject = child_double_definition_creator.mock!.__creator__.subject
|
67
|
+
parent_double_definition.implementation.call.should == child_subject
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#stub!" do
|
72
|
+
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
73
|
+
parent_double_definition.implementation.should be_nil
|
74
|
+
child_subject = child_double_definition_creator.stub!.__creator__.subject
|
75
|
+
parent_double_definition.implementation.call.should == child_subject
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "#dont_allow!" do
|
80
|
+
it "sets #parent_double_definition.implementation to a Proc returning the #subject" do
|
81
|
+
parent_double_definition.implementation.should be_nil
|
82
|
+
child_subject = child_double_definition_creator.dont_allow!.__creator__.subject
|
83
|
+
parent_double_definition.implementation.call.should == child_subject
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "Strategies::Scope definitions" do
|
90
|
+
describe "methods without !" do
|
91
|
+
describe "#instance_of" do
|
92
|
+
it "raises a NoMethodError" do
|
93
|
+
lambda do
|
94
|
+
child_double_definition_creator.instance_of
|
95
|
+
end.should raise_error(NoMethodError)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "methods with !" do
|
101
|
+
describe "#instance_of!" do
|
102
|
+
it "raises a NoMethodError" do
|
103
|
+
lambda do
|
104
|
+
child_double_definition_creator.instance_of!
|
105
|
+
end.should raise_error(NoMethodError)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|