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.
Files changed (110) hide show
  1. data/CHANGES +14 -0
  2. data/README.rdoc +67 -13
  3. data/Rakefile +1 -1
  4. data/lib/rr.rb +29 -9
  5. data/lib/rr/adapters/rr_methods.rb +38 -158
  6. data/lib/rr/double.rb +46 -41
  7. data/lib/rr/double_definitions/child_double_definition_creator.rb +23 -0
  8. data/lib/rr/double_definitions/double_definition.rb +212 -0
  9. data/lib/rr/double_definitions/double_definition_creator.rb +153 -0
  10. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +25 -0
  11. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +15 -0
  12. data/lib/rr/double_definitions/strategies/implementation/proxy.rb +62 -0
  13. data/lib/rr/double_definitions/strategies/implementation/reimplementation.rb +14 -0
  14. data/lib/rr/double_definitions/strategies/scope/instance.rb +15 -0
  15. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +43 -0
  16. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +15 -0
  17. data/lib/rr/double_definitions/strategies/strategy.rb +70 -0
  18. data/lib/rr/double_definitions/strategies/verification/dont_allow.rb +34 -0
  19. data/lib/rr/double_definitions/strategies/verification/mock.rb +44 -0
  20. data/lib/rr/double_definitions/strategies/verification/stub.rb +45 -0
  21. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +15 -0
  22. data/lib/rr/double_injection.rb +21 -15
  23. data/lib/rr/expectations/argument_equality_expectation.rb +2 -1
  24. data/lib/rr/space.rb +23 -22
  25. data/lib/rr/wildcard_matchers/hash_including.rb +29 -0
  26. data/lib/rr/wildcard_matchers/satisfy.rb +26 -0
  27. data/spec/high_level_spec.rb +111 -64
  28. data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +1 -1
  29. data/spec/rr/adapters/rr_methods_creator_spec.rb +99 -315
  30. data/spec/rr/adapters/rr_methods_space_spec.rb +90 -109
  31. data/spec/rr/adapters/rr_methods_spec_helper.rb +1 -1
  32. data/spec/rr/adapters/rr_methods_times_matcher_spec.rb +1 -1
  33. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +103 -0
  34. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +83 -0
  35. data/spec/rr/double_definitions/double_definition_creator_spec.rb +495 -0
  36. data/spec/rr/double_definitions/double_definition_spec.rb +1116 -0
  37. data/spec/rr/double_injection/double_injection_bind_spec.rb +111 -0
  38. data/spec/rr/double_injection/double_injection_dispatching_spec.rb +245 -0
  39. data/spec/rr/{double → double_injection}/double_injection_has_original_method_spec.rb +9 -9
  40. data/spec/rr/double_injection/double_injection_reset_spec.rb +90 -0
  41. data/spec/rr/double_injection/double_injection_spec.rb +77 -0
  42. data/spec/rr/double_injection/double_injection_verify_spec.rb +29 -0
  43. data/spec/rr/double_spec.rb +156 -136
  44. data/spec/rr/errors/rr_error_spec.rb +1 -1
  45. data/spec/rr/expectations/any_argument_expectation_spec.rb +1 -1
  46. data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +6 -30
  47. data/spec/rr/expectations/argument_equality_expectation_spec.rb +35 -18
  48. data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +22 -41
  49. data/spec/rr/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
  50. data/spec/rr/expectations/hash_including_spec.rb +17 -0
  51. data/spec/rr/expectations/satisfy_argument_equality_expectation_spec.rb +59 -0
  52. data/spec/rr/expectations/satisfy_spec.rb +14 -0
  53. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +30 -28
  54. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +55 -54
  55. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +49 -48
  56. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +9 -7
  57. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +77 -76
  58. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +58 -57
  59. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +59 -58
  60. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +25 -24
  61. data/spec/rr/rspec/rspec_adapter_spec.rb +12 -11
  62. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +10 -8
  63. data/spec/rr/rspec/rspec_usage_spec.rb +1 -1
  64. data/spec/rr/space/hash_with_object_id_key_spec.rb +1 -1
  65. data/spec/rr/space/space_spec.rb +330 -192
  66. data/spec/rr/test_unit/test_helper.rb +1 -2
  67. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -2
  68. data/spec/rr/test_unit/test_unit_integration_test.rb +1 -2
  69. data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +1 -1
  70. data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +1 -1
  71. data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +1 -1
  72. data/spec/rr/times_called_matchers/integer_matcher_spec.rb +1 -1
  73. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +1 -1
  74. data/spec/rr/times_called_matchers/range_matcher_spec.rb +1 -1
  75. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +1 -1
  76. data/spec/rr/wildcard_matchers/anything_spec.rb +24 -0
  77. data/spec/rr/wildcard_matchers/boolean_spec.rb +36 -0
  78. data/spec/rr/wildcard_matchers/duck_type_spec.rb +52 -0
  79. data/spec/rr/wildcard_matchers/is_a_spec.rb +32 -0
  80. data/spec/rr/wildcard_matchers/numeric_spec.rb +32 -0
  81. data/spec/rr/wildcard_matchers/range_spec.rb +35 -0
  82. data/spec/rr/wildcard_matchers/regexp_spec.rb +43 -0
  83. data/spec/rr_spec.rb +28 -0
  84. data/spec/spec_helper.rb +84 -0
  85. metadata +43 -29
  86. data/lib/rr/double_creator.rb +0 -271
  87. data/lib/rr/double_definition.rb +0 -179
  88. data/lib/rr/double_definition_builder.rb +0 -44
  89. data/lib/rr/double_definition_creator.rb +0 -156
  90. data/lib/rr/double_definition_creator_proxy.rb +0 -20
  91. data/spec/rr/double/double_injection_bind_spec.rb +0 -105
  92. data/spec/rr/double/double_injection_dispatching_spec.rb +0 -228
  93. data/spec/rr/double/double_injection_reset_spec.rb +0 -86
  94. data/spec/rr/double/double_injection_spec.rb +0 -72
  95. data/spec/rr/double/double_injection_verify_spec.rb +0 -24
  96. data/spec/rr/double_definition_creator_proxy_spec.rb +0 -85
  97. data/spec/rr/double_definition_creator_spec.rb +0 -496
  98. data/spec/rr/double_definition_spec.rb +0 -815
  99. data/spec/rr/expectations/anything_spec.rb +0 -14
  100. data/spec/rr/expectations/boolean_spec.rb +0 -14
  101. data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +0 -71
  102. data/spec/rr/expectations/duck_type_spec.rb +0 -14
  103. data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +0 -51
  104. data/spec/rr/expectations/is_a_spec.rb +0 -14
  105. data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +0 -47
  106. data/spec/rr/expectations/numeric_spec.rb +0 -14
  107. data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +0 -59
  108. data/spec/rr/expectations/range_spec.rb +0 -10
  109. data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +0 -72
  110. 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
- return true
28
+ true
28
29
  end
29
30
 
30
31
  def ==(other)
@@ -1,5 +1,5 @@
1
1
  module RR
2
- # RR::Space.instance is the global state object for the RR framework.
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 object and method_name.
31
+ # in subject and method_name.
32
32
  # When a DoubleInjection is created, it binds the dispatcher to the
33
- # object.
34
- def double_injection(object, method_name)
35
- double_injection = @double_injections[object][method_name.to_sym]
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(object, method_name.to_sym)
39
- @double_injections[object][method_name.to_sym] = double_injection
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.each do |object, method_double_map|
70
- method_double_map.keys.each do |method_name|
71
- verify_double(object, method_name)
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 object and method_name.
84
- def verify_double(object, method_name)
85
- @double_injections[object][method_name].verify
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 object, method_name
88
+ reset_double subject, method_name
88
89
  end
89
90
 
90
- # Resets the DoubleInjection for the passed in object and method_name.
91
- def reset_double(object, method_name)
92
- double_injection = @double_injections[object].delete(method_name)
93
- @double_injections.delete(object) if @double_injections[object].empty?
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 |object, method_double_map|
106
+ @double_injections.each do |subject, method_double_map|
106
107
  method_double_map.keys.each do |method_name|
107
- reset_double(object, method_name)
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
@@ -1,12 +1,12 @@
1
- dir = File.dirname(__FILE__)
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
- @obj = Object.new
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(@obj).to_s {"a value"}
20
- @obj.to_s.should == "a value"
21
- lambda {@obj.to_s}.should raise_error(RR::Errors::TimesCalledError)
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(@obj).to_s {"value 1"}.ordered
26
- mock(@obj).to_s {"value 2"}.twice.ordered
27
- @obj.to_s.should == "value 1"
28
- @obj.to_s.should == "value 2"
29
- @obj.to_s.should == "value 2"
30
- lambda {@obj.to_s}.should raise_error(RR::Errors::TimesCalledError)
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 @obj do |c|
81
+ mock subject do |c|
35
82
  c.to_s {"a value"}
36
83
  c.to_sym {:crazy}
37
84
  end
38
- @obj.to_s.should == "a value"
39
- @obj.to_sym.should == :crazy
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(@obj).foobar(
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
- @obj.foobar(
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
- @obj.foobar(:failure)
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(@obj) == 55
112
+ mock(subject) == 55
66
113
 
67
- @obj == 55
114
+ subject == 55
68
115
  lambda do
69
- @obj == 99
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 = @obj.to_s
77
- mock.proxy(@obj).to_s
78
- @obj.to_s.should == expected_to_s_value
79
- lambda {@obj.to_s}.should raise_error
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 @obj.to_s(arg)
130
+ def subject.to_s(arg)
84
131
  "Original to_s with arg #{arg}"
85
132
  end
86
- mock.proxy(@obj).to_s(:foo).ordered
87
- mock.proxy(@obj).to_s(:bar).twice.ordered
133
+ mock.proxy(subject).to_s(:foo).ordered
134
+ mock.proxy(subject).to_s(:bar).twice.ordered
88
135
 
89
- @obj.to_s(:foo).should == "Original to_s with arg foo"
90
- @obj.to_s(:bar).should == "Original to_s with arg bar"
91
- @obj.to_s(:bar).should == "Original to_s with arg bar"
92
- lambda {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
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 @obj.to_s(arg)
143
+ def subject.to_s(arg)
97
144
  "Original to_s with arg #{arg}"
98
145
  end
99
- mock.proxy(@obj).to_s(:foo).ordered
100
- mock.proxy(@obj).to_s(:bar).twice.ordered
146
+ mock.proxy(subject).to_s(:foo).ordered
147
+ mock.proxy(subject).to_s(:bar).twice.ordered
101
148
 
102
- @obj.to_s(:foo).should == "Original to_s with arg foo"
103
- @obj.to_s(:bar).should == "Original to_s with arg bar"
104
- @obj.to_s(:bar).should == "Original to_s with arg bar"
105
- lambda {@obj.to_s(:bar)}.should raise_error(RR::Errors::TimesCalledError)
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 @obj.foobar_1(*args)
156
+ def subject.foobar_1(*args)
110
157
  :original_value_1
111
158
  end
112
159
 
113
- def @obj.foobar_2
160
+ def subject.foobar_2
114
161
  :original_value_2
115
162
  end
116
163
 
117
- mock.proxy @obj do |c|
164
+ mock.proxy subject do |c|
118
165
  c.foobar_1(1)
119
166
  c.foobar_2
120
167
  end
121
- @obj.foobar_1(1).should == :original_value_1
122
- lambda {@obj.foobar_1(:blah)}.should raise_error
168
+ subject.foobar_1(1).should == :original_value_1
169
+ lambda {subject.foobar_1(:blah)}.should raise_error
123
170
 
124
- @obj.foobar_2.should == :original_value_2
125
- lambda {@obj.foobar_2(:blah)}.should raise_error
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 @obj.foobar_1(*args)
176
+ def subject.foobar_1(*args)
130
177
  :original_value_1
131
178
  end
132
179
 
133
- def @obj.foobar_2
180
+ def subject.foobar_2
134
181
  :original_value_2
135
182
  end
136
183
 
137
- mock.proxy @obj do |c|
184
+ mock.proxy subject do |c|
138
185
  c.foobar_1(1)
139
186
  c.foobar_2
140
187
  end
141
- @obj.foobar_1(1).should == :original_value_1
142
- lambda {@obj.foobar_1(:blah)}.should raise_error
188
+ subject.foobar_1(1).should == :original_value_1
189
+ lambda {subject.foobar_1(:blah)}.should raise_error
143
190
 
144
- @obj.foobar_2.should == :original_value_2
145
- lambda {@obj.foobar_2(:blah)}.should raise_error
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(@obj).to_s {"a value"}
152
- @obj.to_s.should == "a value"
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(@obj).to_s {"value 1"}.once.ordered
157
- stub(@obj).to_s {"value 2"}.once.ordered
203
+ stub(subject).to_s {"value 1"}.once.ordered
204
+ stub(subject).to_s {"value 2"}.once.ordered
158
205
 
159
- @obj.to_s.should == "value 1"
160
- @obj.to_s.should == "value 2"
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 @obj do |d|
211
+ stub subject do |d|
165
212
  d.to_s {"a value"}
166
213
  d.to_sym {:crazy}
167
214
  end
168
- @obj.to_s.should == "a value"
169
- @obj.to_sym.should == :crazy
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(@obj).__send__(:==) {:equality}
181
- (@obj == 55).should == :equality
227
+ stub(subject).__send__(:==) {:equality}
228
+ (subject == 55).should == :equality
182
229
  end
183
230
  end
184
231
  end