rr 0.4.10 → 0.6.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.
- data/CHANGES +14 -0
- data/README.rdoc +67 -13
- data/Rakefile +1 -1
- data/lib/rr.rb +29 -9
- data/lib/rr/adapters/rr_methods.rb +38 -158
- data/lib/rr/double.rb +46 -41
- data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
- data/lib/rr/double_definitions/double_definition.rb +212 -0
- data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
- data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -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/scope/instance.rb +15 -0
- data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -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 +21 -15
- data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
- data/lib/rr/space.rb +23 -22
- data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
- data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
- data/spec/high_level_spec.rb +111 -64
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
- data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
- data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
- data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
- data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
- data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
- data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
- data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
- data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
- data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
- data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
- data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
- data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
- data/spec/rr/double_injection/double_injection_spec.rb +77 -0
- data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
- data/spec/rr/double_spec.rb +156 -136
- data/spec/rr/errors/rr_error_spec.rb +1 -1
- data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
- 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 +30 -28
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
- data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
- data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
- data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
- data/spec/rr/space/space_spec.rb +330 -192
- data/spec/rr/test_unit/test_helper.rb +1 -2
- data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
- data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
- 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/spec_helper.rb +84 -0
- metadata +43 -29
- data/lib/rr/double_creator.rb +0 -271
- data/lib/rr/double_definition.rb +0 -179
- data/lib/rr/double_definition_builder.rb +0 -44
- data/lib/rr/double_definition_creator.rb +0 -156
- data/lib/rr/double_definition_creator_proxy.rb +0 -20
- data/spec/rr/double/double_injection_bind_spec.rb +0 -105
- data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
- data/spec/rr/double/double_injection_reset_spec.rb +0 -86
- data/spec/rr/double/double_injection_spec.rb +0 -72
- data/spec/rr/double/double_injection_verify_spec.rb +0 -24
- data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
- data/spec/rr/double_definition_creator_spec.rb +0 -496
- data/spec/rr/double_definition_spec.rb +0 -815
- data/spec/rr/expectations/anything_spec.rb +0 -14
- data/spec/rr/expectations/boolean_spec.rb +0 -14
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
- data/spec/rr/expectations/duck_type_spec.rb +0 -14
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
- data/spec/rr/expectations/is_a_spec.rb +0 -14
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
- data/spec/rr/expectations/numeric_spec.rb +0 -14
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
- data/spec/rr/expectations/range_spec.rb +0 -10
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
- data/spec/rr/expectations/regexp_spec.rb +0 -10
@@ -12,6 +12,7 @@ module RR
|
|
12
12
|
arguments.each_with_index do |arg, index|
|
13
13
|
return false unless equality_match(@expected_arguments[index], arg)
|
14
14
|
end
|
15
|
+
true
|
15
16
|
end
|
16
17
|
|
17
18
|
def wildcard_match?(*arguments)
|
@@ -24,7 +25,7 @@ module RR
|
|
24
25
|
return false unless equality_match(expected_argument, arg)
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
+
true
|
28
29
|
end
|
29
30
|
|
30
31
|
def ==(other)
|
data/lib/rr/space.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module RR
|
2
|
-
# RR::Space.instance is the global state
|
2
|
+
# RR::Space.instance is the global state subject for the RR framework.
|
3
3
|
class Space
|
4
4
|
module Reader
|
5
5
|
def space
|
@@ -28,22 +28,22 @@ module RR
|
|
28
28
|
end
|
29
29
|
|
30
30
|
# Reuses or creates, if none exists, a DoubleInjection for the passed
|
31
|
-
# in
|
31
|
+
# in subject and method_name.
|
32
32
|
# When a DoubleInjection is created, it binds the dispatcher to the
|
33
|
-
#
|
34
|
-
def double_injection(
|
35
|
-
double_injection = @double_injections[
|
33
|
+
# subject.
|
34
|
+
def double_injection(subject, method_name)
|
35
|
+
double_injection = @double_injections[subject][method_name.to_sym]
|
36
36
|
return double_injection if double_injection
|
37
37
|
|
38
|
-
double_injection = DoubleInjection.new(
|
39
|
-
@double_injections[
|
38
|
+
double_injection = DoubleInjection.new(subject, method_name.to_sym)
|
39
|
+
@double_injections[subject][method_name.to_sym] = double_injection
|
40
40
|
double_injection.bind
|
41
41
|
double_injection
|
42
42
|
end
|
43
43
|
|
44
44
|
# Registers the ordered Double to be verified.
|
45
45
|
def register_ordered_double(double)
|
46
|
-
@ordered_doubles << double
|
46
|
+
@ordered_doubles << double unless ordered_doubles.include?(double)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Verifies that the passed in ordered Double is being called
|
@@ -65,10 +65,11 @@ module RR
|
|
65
65
|
|
66
66
|
# Verifies all the DoubleInjection objects have met their
|
67
67
|
# TimesCalledExpectations.
|
68
|
-
def verify_doubles
|
69
|
-
@double_injections.
|
70
|
-
|
71
|
-
|
68
|
+
def verify_doubles(*objects)
|
69
|
+
objects = @double_injections.keys if objects.empty?
|
70
|
+
objects.each do |subject|
|
71
|
+
@double_injections[subject].keys.each do |method_name|
|
72
|
+
verify_double(subject, method_name)
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
@@ -80,17 +81,17 @@ module RR
|
|
80
81
|
reset_double_injections
|
81
82
|
end
|
82
83
|
|
83
|
-
# Verifies the DoubleInjection for the passed in
|
84
|
-
def verify_double(
|
85
|
-
@double_injections[
|
84
|
+
# Verifies the DoubleInjection for the passed in subject and method_name.
|
85
|
+
def verify_double(subject, method_name)
|
86
|
+
@double_injections[subject][method_name].verify
|
86
87
|
ensure
|
87
|
-
reset_double
|
88
|
+
reset_double subject, method_name
|
88
89
|
end
|
89
90
|
|
90
|
-
# Resets the DoubleInjection for the passed in
|
91
|
-
def reset_double(
|
92
|
-
double_injection = @double_injections[
|
93
|
-
@double_injections.delete(
|
91
|
+
# Resets the DoubleInjection for the passed in subject and method_name.
|
92
|
+
def reset_double(subject, method_name)
|
93
|
+
double_injection = @double_injections[subject].delete(method_name)
|
94
|
+
@double_injections.delete(subject) if @double_injections[subject].empty?
|
94
95
|
double_injection.reset
|
95
96
|
end
|
96
97
|
|
@@ -102,9 +103,9 @@ module RR
|
|
102
103
|
|
103
104
|
# Resets the registered Doubles for the next test run.
|
104
105
|
def reset_double_injections
|
105
|
-
@double_injections.each do |
|
106
|
+
@double_injections.each do |subject, method_double_map|
|
106
107
|
method_double_map.keys.each do |method_name|
|
107
|
-
reset_double(
|
108
|
+
reset_double(subject, method_name)
|
108
109
|
end
|
109
110
|
end
|
110
111
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RR
|
2
|
+
module WildcardMatchers
|
3
|
+
class HashIncluding
|
4
|
+
attr_reader :expected_hash
|
5
|
+
|
6
|
+
def initialize(expected_hash)
|
7
|
+
@expected_hash = expected_hash.clone
|
8
|
+
end
|
9
|
+
|
10
|
+
def wildcard_match?(other)
|
11
|
+
return true if self == other
|
12
|
+
expected_hash.each_pair do |key, value|
|
13
|
+
return false unless other.has_key?(key) && other[key] == expected_hash[key]
|
14
|
+
end
|
15
|
+
return true
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
"hash_including(#{expected_hash.inspect})"
|
20
|
+
end
|
21
|
+
|
22
|
+
def ==(other)
|
23
|
+
return false unless other.is_a?(self.class)
|
24
|
+
self.expected_hash == other.expected_hash
|
25
|
+
end
|
26
|
+
alias_method :eql?, :==
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RR
|
2
|
+
module WildcardMatchers
|
3
|
+
class Satisfy
|
4
|
+
attr_reader :expectation_proc
|
5
|
+
|
6
|
+
def initialize(expectation_proc)
|
7
|
+
@expectation_proc = expectation_proc
|
8
|
+
end
|
9
|
+
|
10
|
+
def wildcard_match?(other)
|
11
|
+
return true if self == other
|
12
|
+
!!expectation_proc.call(other)
|
13
|
+
end
|
14
|
+
|
15
|
+
def inspect
|
16
|
+
"satisfy {block}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
return false unless other.is_a?(self.class)
|
21
|
+
self.expectation_proc == other.expectation_proc
|
22
|
+
end
|
23
|
+
alias_method :eql?, :==
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/spec/high_level_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
|
2
|
-
require "#{dir}/spec_helper"
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
|
3
2
|
|
4
3
|
class HighLevelSpec
|
5
4
|
end
|
6
5
|
|
7
6
|
describe "RR" do
|
7
|
+
attr_reader :subject
|
8
8
|
before(:each) do
|
9
|
-
@
|
9
|
+
@subject = Object.new
|
10
10
|
extend RR::Adapters::RRMethods
|
11
11
|
end
|
12
12
|
|
@@ -16,31 +16,78 @@ describe "RR" do
|
|
16
16
|
|
17
17
|
describe "RR mock:" do
|
18
18
|
it "mocks via inline call" do
|
19
|
-
mock(
|
20
|
-
|
21
|
-
lambda {
|
19
|
+
mock(subject).to_s {"a value"}
|
20
|
+
subject.to_s.should == "a value"
|
21
|
+
lambda {subject.to_s}.should raise_error(RR::Errors::TimesCalledError)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "allows ordering" do
|
25
|
-
mock(
|
26
|
-
mock(
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
lambda {
|
25
|
+
mock(subject).to_s {"value 1"}.ordered
|
26
|
+
mock(subject).to_s {"value 2"}.twice
|
27
|
+
subject.to_s.should == "value 1"
|
28
|
+
subject.to_s.should == "value 2"
|
29
|
+
subject.to_s.should == "value 2"
|
30
|
+
lambda {subject.to_s}.should raise_error(RR::Errors::TimesCalledError)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'allows terse chaining' do
|
34
|
+
mock(subject).first(1) {mock(Object.new).second(2) {mock(Object.new).third(3) {4}}}
|
35
|
+
subject.first(1).second(2).third(3).should == 4
|
36
|
+
|
37
|
+
mock(subject).first(1) {mock!.second(2) {mock!.third(3) {4}}}
|
38
|
+
subject.first(1).second(2).third(3).should == 4
|
39
|
+
|
40
|
+
mock(subject).first(1).mock!.second(2).mock!.third(3) {4}
|
41
|
+
subject.first(1).second(2).third(3).should == 4
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'allows chaining with proxy' do
|
45
|
+
find_return_value = Object.new
|
46
|
+
def find_return_value.child
|
47
|
+
:the_child
|
48
|
+
end
|
49
|
+
(class << subject; self; end).class_eval do
|
50
|
+
define_method(:find) do |id|
|
51
|
+
id == '1' ? find_return_value : raise(ArgumentError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
mock.proxy(subject).find('1').mock.proxy!.child
|
56
|
+
subject.find('1').child.should == :the_child
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'allows branched chaining' do
|
60
|
+
mock(subject).first do
|
61
|
+
mock! do |expect|
|
62
|
+
expect.branch1 {mock!.branch11 {11}}
|
63
|
+
expect.branch2 {mock!.branch22 {22}}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
o = subject.first
|
67
|
+
o.branch1.branch11.should == 11
|
68
|
+
o.branch2.branch22.should == 22
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'allows chained ordering' do
|
72
|
+
mock(subject).to_s {"value 1"}.then.to_s {"value 2"}.twice.then.to_s {"value 3"}.once
|
73
|
+
subject.to_s.should == "value 1"
|
74
|
+
subject.to_s.should == "value 2"
|
75
|
+
subject.to_s.should == "value 2"
|
76
|
+
subject.to_s.should == "value 3"
|
77
|
+
lambda {subject.to_s}.should raise_error(RR::Errors::TimesCalledError)
|
31
78
|
end
|
32
79
|
|
33
80
|
it "mocks via block" do
|
34
|
-
mock
|
81
|
+
mock subject do |c|
|
35
82
|
c.to_s {"a value"}
|
36
83
|
c.to_sym {:crazy}
|
37
84
|
end
|
38
|
-
|
39
|
-
|
85
|
+
subject.to_s.should == "a value"
|
86
|
+
subject.to_sym.should == :crazy
|
40
87
|
end
|
41
88
|
|
42
89
|
it "has wildcard matchers" do
|
43
|
-
mock(
|
90
|
+
mock(subject).foobar(
|
44
91
|
is_a(String),
|
45
92
|
anything,
|
46
93
|
numeric,
|
@@ -48,7 +95,7 @@ describe "RR" do
|
|
48
95
|
duck_type(:to_s),
|
49
96
|
/abc/
|
50
97
|
) {"value 1"}.twice
|
51
|
-
|
98
|
+
subject.foobar(
|
52
99
|
'hello',
|
53
100
|
Object.new,
|
54
101
|
99,
|
@@ -57,116 +104,116 @@ describe "RR" do
|
|
57
104
|
"Tabcola"
|
58
105
|
).should == "value 1"
|
59
106
|
lambda do
|
60
|
-
|
107
|
+
subject.foobar(:failure)
|
61
108
|
end.should raise_error( RR::Errors::DoubleNotFoundError )
|
62
109
|
end
|
63
110
|
|
64
111
|
it "mocks methods without letters" do
|
65
|
-
mock(
|
112
|
+
mock(subject) == 55
|
66
113
|
|
67
|
-
|
114
|
+
subject == 55
|
68
115
|
lambda do
|
69
|
-
|
116
|
+
subject == 99
|
70
117
|
end.should raise_error(RR::Errors::DoubleNotFoundError)
|
71
118
|
end
|
72
119
|
end
|
73
120
|
|
74
121
|
describe "RR proxy:" do
|
75
122
|
it "proxies via inline call" do
|
76
|
-
expected_to_s_value =
|
77
|
-
mock.proxy(
|
78
|
-
|
79
|
-
lambda {
|
123
|
+
expected_to_s_value = subject.to_s
|
124
|
+
mock.proxy(subject).to_s
|
125
|
+
subject.to_s.should == expected_to_s_value
|
126
|
+
lambda {subject.to_s}.should raise_error
|
80
127
|
end
|
81
128
|
|
82
129
|
it "proxy allows ordering" do
|
83
|
-
def
|
130
|
+
def subject.to_s(arg)
|
84
131
|
"Original to_s with arg #{arg}"
|
85
132
|
end
|
86
|
-
mock.proxy(
|
87
|
-
mock.proxy(
|
133
|
+
mock.proxy(subject).to_s(:foo).ordered
|
134
|
+
mock.proxy(subject).to_s(:bar).twice.ordered
|
88
135
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
lambda {
|
136
|
+
subject.to_s(:foo).should == "Original to_s with arg foo"
|
137
|
+
subject.to_s(:bar).should == "Original to_s with arg bar"
|
138
|
+
subject.to_s(:bar).should == "Original to_s with arg bar"
|
139
|
+
lambda {subject.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
|
93
140
|
end
|
94
141
|
|
95
142
|
it "proxy allows ordering" do
|
96
|
-
def
|
143
|
+
def subject.to_s(arg)
|
97
144
|
"Original to_s with arg #{arg}"
|
98
145
|
end
|
99
|
-
mock.proxy(
|
100
|
-
mock.proxy(
|
146
|
+
mock.proxy(subject).to_s(:foo).ordered
|
147
|
+
mock.proxy(subject).to_s(:bar).twice.ordered
|
101
148
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
lambda {
|
149
|
+
subject.to_s(:foo).should == "Original to_s with arg foo"
|
150
|
+
subject.to_s(:bar).should == "Original to_s with arg bar"
|
151
|
+
subject.to_s(:bar).should == "Original to_s with arg bar"
|
152
|
+
lambda {subject.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
|
106
153
|
end
|
107
154
|
|
108
155
|
it "proxies via block" do
|
109
|
-
def
|
156
|
+
def subject.foobar_1(*args)
|
110
157
|
:original_value_1
|
111
158
|
end
|
112
159
|
|
113
|
-
def
|
160
|
+
def subject.foobar_2
|
114
161
|
:original_value_2
|
115
162
|
end
|
116
163
|
|
117
|
-
mock.proxy
|
164
|
+
mock.proxy subject do |c|
|
118
165
|
c.foobar_1(1)
|
119
166
|
c.foobar_2
|
120
167
|
end
|
121
|
-
|
122
|
-
lambda {
|
168
|
+
subject.foobar_1(1).should == :original_value_1
|
169
|
+
lambda {subject.foobar_1(:blah)}.should raise_error
|
123
170
|
|
124
|
-
|
125
|
-
lambda {
|
171
|
+
subject.foobar_2.should == :original_value_2
|
172
|
+
lambda {subject.foobar_2(:blah)}.should raise_error
|
126
173
|
end
|
127
174
|
|
128
175
|
it "proxies via block" do
|
129
|
-
def
|
176
|
+
def subject.foobar_1(*args)
|
130
177
|
:original_value_1
|
131
178
|
end
|
132
179
|
|
133
|
-
def
|
180
|
+
def subject.foobar_2
|
134
181
|
:original_value_2
|
135
182
|
end
|
136
183
|
|
137
|
-
mock.proxy
|
184
|
+
mock.proxy subject do |c|
|
138
185
|
c.foobar_1(1)
|
139
186
|
c.foobar_2
|
140
187
|
end
|
141
|
-
|
142
|
-
lambda {
|
188
|
+
subject.foobar_1(1).should == :original_value_1
|
189
|
+
lambda {subject.foobar_1(:blah)}.should raise_error
|
143
190
|
|
144
|
-
|
145
|
-
lambda {
|
191
|
+
subject.foobar_2.should == :original_value_2
|
192
|
+
lambda {subject.foobar_2(:blah)}.should raise_error
|
146
193
|
end
|
147
194
|
end
|
148
195
|
|
149
196
|
describe "RR stub:" do
|
150
197
|
it "stubs via inline call" do
|
151
|
-
stub(
|
152
|
-
|
198
|
+
stub(subject).to_s {"a value"}
|
199
|
+
subject.to_s.should == "a value"
|
153
200
|
end
|
154
201
|
|
155
202
|
it "allows ordering" do
|
156
|
-
stub(
|
157
|
-
stub(
|
203
|
+
stub(subject).to_s {"value 1"}.once.ordered
|
204
|
+
stub(subject).to_s {"value 2"}.once.ordered
|
158
205
|
|
159
|
-
|
160
|
-
|
206
|
+
subject.to_s.should == "value 1"
|
207
|
+
subject.to_s.should == "value 2"
|
161
208
|
end
|
162
209
|
|
163
210
|
it "stubs via block" do
|
164
|
-
stub
|
211
|
+
stub subject do |d|
|
165
212
|
d.to_s {"a value"}
|
166
213
|
d.to_sym {:crazy}
|
167
214
|
end
|
168
|
-
|
169
|
-
|
215
|
+
subject.to_s.should == "a value"
|
216
|
+
subject.to_sym.should == :crazy
|
170
217
|
end
|
171
218
|
|
172
219
|
it "stubs instance_of" do
|
@@ -177,8 +224,8 @@ describe "RR" do
|
|
177
224
|
end
|
178
225
|
|
179
226
|
it "stubs methods without letters" do
|
180
|
-
stub(
|
181
|
-
(
|
227
|
+
stub(subject).__send__(:==) {:equality}
|
228
|
+
(subject == 55).should == :equality
|
182
229
|
end
|
183
230
|
end
|
184
231
|
end
|