rr 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES +3 -0
  2. data/{README → README.rdoc} +14 -6
  3. data/Rakefile +2 -2
  4. data/lib/rr.rb +11 -3
  5. data/lib/rr/adapters/rr_methods.rb +12 -12
  6. data/lib/rr/adapters/rspec.rb +3 -3
  7. data/lib/rr/adapters/test_unit.rb +3 -3
  8. data/lib/rr/double.rb +12 -10
  9. data/lib/rr/double_creator.rb +48 -45
  10. data/lib/rr/double_definition.rb +17 -149
  11. data/lib/rr/double_definition_builder.rb +11 -11
  12. data/lib/rr/double_definition_creator.rb +156 -0
  13. data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
  14. data/lib/rr/double_injection.rb +6 -6
  15. data/lib/rr/double_matches.rb +40 -40
  16. data/lib/rr/errors/rr_error.rb +1 -1
  17. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  18. data/lib/rr/space.rb +9 -30
  19. data/spec/high_level_spec.rb +140 -143
  20. data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
  21. data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
  22. data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
  23. data/spec/rr/double/double_injection_reset_spec.rb +1 -1
  24. data/spec/rr/double/double_injection_verify_spec.rb +5 -4
  25. data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
  26. data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
  27. data/spec/rr/double_definition_spec.rb +637 -642
  28. data/spec/rr/double_spec.rb +44 -43
  29. data/spec/rr/errors/rr_error_spec.rb +6 -6
  30. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
  31. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
  32. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
  38. data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
  39. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
  40. data/spec/rr/space/space_spec.rb +372 -18
  41. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
  42. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
  43. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
  44. data/spec/spec_helper.rb +14 -3
  45. data/spec/spec_suite.rb +2 -2
  46. metadata +47 -45
  47. data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
  48. data/spec/rr/space/space_create_spec.rb +0 -268
  49. data/spec/rr/space/space_helper.rb +0 -7
  50. data/spec/rr/space/space_register_spec.rb +0 -32
  51. data/spec/rr/space/space_reset_spec.rb +0 -131
  52. data/spec/rr/space/space_verify_spec.rb +0 -181
@@ -15,8 +15,8 @@ module RR
15
15
  end
16
16
  end
17
17
 
18
- it "returns a DoubleCreator when passed no arguments" do
19
- mock.should be_instance_of(DoubleCreator)
18
+ it "returns a DoubleDefinitionCreator when passed no arguments" do
19
+ mock.should be_instance_of(DoubleDefinitionCreator)
20
20
  end
21
21
 
22
22
  it "sets up the RR mock call chain" do
@@ -36,7 +36,7 @@ module RR
36
36
  end
37
37
 
38
38
  it "raises error if passed a method name and a block" do
39
- proc do
39
+ lambda do
40
40
  mock(@object, :foobar) {}
41
41
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
42
42
  end
@@ -72,8 +72,8 @@ module RR
72
72
  end
73
73
  end
74
74
 
75
- it "returns a DoubleCreator when passed no arguments" do
76
- stub.should be_instance_of(DoubleCreator)
75
+ it "returns a DoubleDefinitionCreator when passed no arguments" do
76
+ stub.should be_instance_of(DoubleDefinitionCreator)
77
77
  end
78
78
 
79
79
  it "sets up the RR stub call chain" do
@@ -93,7 +93,7 @@ module RR
93
93
  end
94
94
 
95
95
  it "raises error if passed a method name and a block" do
96
- proc do
96
+ lambda do
97
97
  stub(@object, :foobar) {}
98
98
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
99
99
  end
@@ -125,8 +125,8 @@ module RR
125
125
  end
126
126
  end
127
127
 
128
- it "#proxy returns a DoubleCreator when passed no arguments" do
129
- proxy.should be_instance_of(DoubleCreator)
128
+ it "#proxy returns a DoubleDefinitionCreator when passed no arguments" do
129
+ proxy.should be_instance_of(DoubleDefinitionCreator)
130
130
  end
131
131
 
132
132
  it "#proxy sets up the RR proxy call chain" do
@@ -162,7 +162,7 @@ module RR
162
162
  end
163
163
 
164
164
  it "raises error if passed a method name and a block" do
165
- proc do
165
+ lambda do
166
166
  mock.proxy(@object, :foobar) {}
167
167
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
168
168
  end
@@ -198,8 +198,8 @@ module RR
198
198
  end
199
199
  end
200
200
 
201
- it "returns a DoubleCreator when passed no arguments" do
202
- stub.proxy.should be_instance_of(DoubleCreator)
201
+ it "returns a DoubleDefinitionCreator when passed no arguments" do
202
+ stub.proxy.should be_instance_of(DoubleDefinitionCreator)
203
203
  end
204
204
 
205
205
  it "sets up the RR proxy call chain" do
@@ -219,7 +219,7 @@ module RR
219
219
  end
220
220
 
221
221
  it "raises error if passed a method name and a block" do
222
- proc do
222
+ lambda do
223
223
  stub.proxy(@object, :foobar) {}
224
224
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
225
225
  end
@@ -252,8 +252,8 @@ module RR
252
252
  end
253
253
  end
254
254
 
255
- it "returns a DoubleCreator when passed no arguments" do
256
- do_not_allow.should be_instance_of(DoubleCreator)
255
+ it "returns a DoubleDefinitionCreator when passed no arguments" do
256
+ do_not_allow.should be_instance_of(DoubleDefinitionCreator)
257
257
  end
258
258
 
259
259
  it "sets up the RR do_not_allow call chain" do
@@ -279,7 +279,7 @@ module RR
279
279
  end
280
280
 
281
281
  it "raises error if passed a method name and a block" do
282
- proc do
282
+ lambda do
283
283
  do_not_allow(@object, :foobar) {}
284
284
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
285
285
  end
@@ -290,7 +290,7 @@ module RR
290
290
  double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
291
291
  double.argument_expectation.expected_arguments.should == [1, 2]
292
292
 
293
- proc do
293
+ lambda do
294
294
  @subject.foobar(1, 2)
295
295
  end.should raise_error(Errors::TimesCalledError)
296
296
  reset
@@ -303,7 +303,7 @@ module RR
303
303
  double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
304
304
  double.argument_expectation.expected_arguments.should == [1, 2]
305
305
 
306
- proc do
306
+ lambda do
307
307
  @subject.foobar(1, 2)
308
308
  end.should raise_error(Errors::TimesCalledError)
309
309
  reset
@@ -311,13 +311,13 @@ module RR
311
311
  end
312
312
  end
313
313
 
314
- describe DoubleCreator, "#instance_of and #mock" do
314
+ describe DoubleDefinitionCreator, "#instance_of and #mock" do
315
315
  before do
316
316
  @klass = Class.new
317
317
  end
318
318
 
319
- it "returns a DoubleCreator when passed no arguments" do
320
- instance_of.instance_of.should be_instance_of(DoubleCreator)
319
+ it "returns a DoubleDefinitionCreator when passed no arguments" do
320
+ instance_of.instance_of.should be_instance_of(DoubleDefinitionCreator)
321
321
  end
322
322
 
323
323
  it "sets up the RR instance_of call chain" do
@@ -337,7 +337,7 @@ module RR
337
337
  end
338
338
 
339
339
  it "raises error if passed a method name and a block" do
340
- proc do
340
+ lambda do
341
341
  instance_of.mock(@klass, :foobar) {}
342
342
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
343
343
  end
@@ -87,8 +87,8 @@ module RR
87
87
  double1 = @space.double_injection(@object1, :foobar1)
88
88
  double2 = @space.double_injection(@object1, :foobar2)
89
89
 
90
- double1 = @space.double(double1)
91
- double2 = @space.double(double2)
90
+ double1 = Double.new(double1)
91
+ double2 = Double.new(double2)
92
92
 
93
93
  double1.ordered
94
94
  double2.ordered
@@ -22,7 +22,7 @@ module RR
22
22
  yield(a, b)
23
23
  end
24
24
  end
25
- double = @space.double(@double_injection)
25
+ double = Double.new(@double_injection)
26
26
  double.with(1, 2).implemented_by(method_fixture.method(:method_with_block))
27
27
  @object.foobar(1, 2) {|a, b| [b, a]}.should == [2, 1]
28
28
  end
@@ -30,11 +30,11 @@ module RR
30
30
 
31
31
  describe "where there are no doubles with duplicate ArgumentExpectations" do
32
32
  it "dispatches to Double that have an exact match" do
33
- double1_with_exact_match = @space.double(@double_injection)
33
+ double1_with_exact_match = Double.new(@double_injection)
34
34
  double1_with_exact_match.with(:exact_match_1).returns {:return_1}
35
- double_with_no_match = @space.double(@double_injection)
35
+ double_with_no_match = Double.new(@double_injection)
36
36
  double_with_no_match.with("nothing that matches").returns {:no_match}
37
- double2_with_exact_match = @space.double(@double_injection)
37
+ double2_with_exact_match = Double.new(@double_injection)
38
38
  double2_with_exact_match.with(:exact_match_2).returns {:return_2}
39
39
 
40
40
  @object.foobar(:exact_match_1).should == :return_1
@@ -42,9 +42,9 @@ module RR
42
42
  end
43
43
 
44
44
  it "dispatches to Double that have a wildcard match" do
45
- double_with_wildcard_match = @space.double(@double_injection)
45
+ double_with_wildcard_match = Double.new(@double_injection)
46
46
  double_with_wildcard_match.with_any_args.returns {:wild_card_value}
47
- double_with_no_match = @space.double(@double_injection)
47
+ double_with_no_match = Double.new(@double_injection)
48
48
  double_with_no_match.with("nothing that matches").returns {:no_match}
49
49
 
50
50
  @object.foobar(:wildcard_match_1).should == :wild_card_value
@@ -54,10 +54,10 @@ module RR
54
54
 
55
55
  describe "where there are doubles" do
56
56
  it "raises DoubleNotFoundError error when arguments do not match a double" do
57
- double_1 = @space.double(@double_injection)
57
+ double_1 = Double.new(@double_injection)
58
58
  double_1.with(1, 2)
59
59
 
60
- double_2 = @space.double(@double_injection)
60
+ double_2 = Double.new(@double_injection)
61
61
  double_2.with(3)
62
62
 
63
63
  error = nil
@@ -109,7 +109,7 @@ module RR
109
109
  end
110
110
 
111
111
  def double(*arguments, &return_value)
112
- double = @space.double(@double_injection)
112
+ double = Double.new(@double_injection)
113
113
  double.with(*arguments).any_number_of_times.returns(&return_value)
114
114
  double.should_not be_terminal
115
115
  double
@@ -145,13 +145,13 @@ module RR
145
145
 
146
146
  @object.foobar(:exact_match)
147
147
  @object.foobar(:exact_match)
148
- proc do
148
+ lambda do
149
149
  @object.foobar(:exact_match)
150
150
  end.should raise_error(Errors::TimesCalledError)
151
151
  end
152
152
 
153
153
  def double(*arguments, &return_value)
154
- double = @space.double(@double_injection)
154
+ double = Double.new(@double_injection)
155
155
  double.with(*arguments).once.returns(&return_value)
156
156
  double.should be_terminal
157
157
  double
@@ -187,13 +187,13 @@ module RR
187
187
 
188
188
  @object.foobar(:anything)
189
189
  @object.foobar(:anything)
190
- proc do
190
+ lambda do
191
191
  @object.foobar(:anything)
192
192
  end.should raise_error(Errors::TimesCalledError)
193
193
  end
194
194
 
195
195
  def double(&return_value)
196
- double = @space.double(@double_injection)
196
+ double = Double.new(@double_injection)
197
197
  double.with_any_args.once.returns(&return_value)
198
198
  double.should be_terminal
199
199
  double
@@ -207,7 +207,7 @@ module RR
207
207
  end
208
208
 
209
209
  it "executes the block" do
210
- double = @space.double(@double_injection)
210
+ double = Double.new(@double_injection)
211
211
  double.with(1, 2) {:return_value}
212
212
  @object.foobar!(1, 2).should == :return_value
213
213
  end
@@ -219,7 +219,7 @@ module RR
219
219
  end
220
220
 
221
221
  it "executes the block" do
222
- double = @space.double(@double_injection)
222
+ double = Double.new(@double_injection)
223
223
  double.with(1, 2) {:return_value}
224
224
  @object.foobar?(1, 2).should == :return_value
225
225
  end
@@ -27,7 +27,7 @@ module RR
27
27
 
28
28
  @double_injection.reset
29
29
  @object.methods.should_not include(@method_name.to_s)
30
- proc {@object.foobar}.should raise_error(NoMethodError)
30
+ lambda {@object.foobar}.should raise_error(NoMethodError)
31
31
  end
32
32
  end
33
33
 
@@ -2,8 +2,9 @@ require "spec/spec_helper"
2
2
 
3
3
  module RR
4
4
  describe DoubleInjection, "#verify" do
5
+ it_should_behave_like "Swapped Space"
5
6
  before do
6
- @space = Space.new
7
+ @space = Space.instance
7
8
  @object = Object.new
8
9
  @method_name = :foobar
9
10
  @object.methods.should_not include(@method_name.to_s)
@@ -11,13 +12,13 @@ module RR
11
12
  end
12
13
 
13
14
  it "verifies each double was met" do
14
- double = Double.new(@space, @double_injection, @space.double_definition)
15
+ double = Double.new(@double_injection, DoubleDefinition.new)
15
16
  @double_injection.register_double double
16
17
 
17
18
  double.with(1).once.returns {nil}
18
- proc {@double_injection.verify}.should raise_error(Errors::TimesCalledError)
19
+ lambda {@double_injection.verify}.should raise_error(Errors::TimesCalledError)
19
20
  @object.foobar(1)
20
- proc {@double_injection.verify}.should_not raise_error
21
+ lambda {@double_injection.verify}.should_not raise_error
21
22
  end
22
23
  end
23
24
  end
@@ -1,7 +1,7 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- describe DoubleMethodProxy, "initializes proxy with passed in creator", :shared => true do
4
+ describe DoubleDefinitionCreatorProxy, "initializes proxy with passed in creator", :shared => true do
5
5
  it "initializes proxy with passed in creator" do
6
6
  class << the_proxy
7
7
  attr_reader :creator
@@ -10,23 +10,25 @@ module RR
10
10
  end
11
11
  end
12
12
 
13
- describe DoubleMethodProxy do
13
+ describe DoubleDefinitionCreatorProxy do
14
14
  attr_reader :space, :subject, :creator, :the_proxy
15
+ it_should_behave_like "Swapped Space"
16
+
15
17
  before(:each) do
16
- @space = Space.new
18
+ @space = Space.instance
17
19
  @subject = Object.new
18
- @creator = space.double_creator
20
+ @creator = DoubleDefinitionCreator.new
19
21
  creator.mock
20
22
  end
21
23
 
22
24
  describe ".new without block" do
23
- it_should_behave_like "RR::DoubleMethodProxy initializes proxy with passed in creator"
25
+ it_should_behave_like "RR::DoubleDefinitionCreatorProxy initializes proxy with passed in creator"
24
26
  before do
25
- @the_proxy = DoubleMethodProxy.new(creator, subject)
27
+ @the_proxy = DoubleDefinitionCreatorProxy.new(creator, subject)
26
28
  end
27
29
 
28
30
  it "clears out all methods from proxy" do
29
- proxy_subclass = Class.new(DoubleMethodProxy) do
31
+ proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
30
32
  def i_should_be_a_double
31
33
  end
32
34
  end
@@ -38,9 +40,9 @@ module RR
38
40
  end
39
41
 
40
42
  describe ".new with block" do
41
- it_should_behave_like "RR::DoubleMethodProxy initializes proxy with passed in creator"
43
+ it_should_behave_like "RR::DoubleDefinitionCreatorProxy initializes proxy with passed in creator"
42
44
  before do
43
- @the_proxy = DoubleMethodProxy.new(creator, subject) do |b|
45
+ @the_proxy = DoubleDefinitionCreatorProxy.new(creator, subject) do |b|
44
46
  b.foobar(1, 2) {:one_two}
45
47
  b.foobar(1) {:one}
46
48
  b.foobar.with_any_args {:default}
@@ -56,7 +58,7 @@ module RR
56
58
  end
57
59
 
58
60
  it "clears out all methods from proxy" do
59
- proxy_subclass = Class.new(DoubleMethodProxy) do
61
+ proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
60
62
  def i_should_be_a_double
61
63
  end
62
64
  end
@@ -1,30 +1,30 @@
1
1
  require "spec/spec_helper"
2
2
 
3
3
  module RR
4
- describe DoubleCreator, " strategy definition", :shared => true do
4
+ describe DoubleDefinitionCreator, " strategy definition", :shared => true do
5
5
  it "returns self when passing no args" do
6
6
  creator.__send__(method_name).should === creator
7
7
  end
8
8
 
9
- it "returns a DoubleMethodProxy when passed a subject" do
9
+ it "returns a DoubleDefinitionCreatorProxy when passed a subject" do
10
10
  double = creator.__send__(method_name, subject).foobar
11
11
  double.should be_instance_of(DoubleDefinition)
12
12
  end
13
13
 
14
- it "returns a DoubleMethodProxy when passed Kernel" do
14
+ it "returns a DoubleDefinitionCreatorProxy when passed Kernel" do
15
15
  double = creator.__send__(method_name, Kernel).foobar
16
16
  double.should be_instance_of(DoubleDefinition)
17
17
  end
18
18
 
19
19
  it "raises error if passed a method name and a block" do
20
- proc do
20
+ lambda do
21
21
  creator.__send__(method_name, subject, :foobar) {}
22
22
  end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
23
23
  end
24
24
 
25
25
  it "raises error when using mock strategy" do
26
26
  creator.mock
27
- proc do
27
+ lambda do
28
28
  creator.__send__(method_name)
29
29
  end.should raise_error(
30
30
  Errors::DoubleDefinitionError,
@@ -34,7 +34,7 @@ module RR
34
34
 
35
35
  it "raises error when using stub strategy" do
36
36
  creator.stub
37
- proc do
37
+ lambda do
38
38
  creator.__send__(method_name)
39
39
  end.should raise_error(
40
40
  Errors::DoubleDefinitionError,
@@ -44,25 +44,26 @@ module RR
44
44
 
45
45
  it "raises error when using dont_allow strategy" do
46
46
  creator.dont_allow
47
- proc do
47
+ lambda do
48
48
  creator.__send__(method_name)
49
49
  end.should raise_error(
50
- Errors::DoubleDefinitionError,
51
- "This Double already has a dont_allow strategy"
50
+ Errors::DoubleDefinitionError,
51
+ "This Double already has a dont_allow strategy"
52
52
  )
53
53
  end
54
54
  end
55
55
 
56
- describe DoubleCreator do
56
+ describe DoubleDefinitionCreator do
57
57
  attr_reader :creator, :subject, :space, :method_name
58
+ it_should_behave_like "Swapped Space"
58
59
  before(:each) do
59
- @space = Space.new
60
+ @space = Space.instance
60
61
  @subject = Object.new
61
- @creator = DoubleCreator.new(space)
62
+ @creator = DoubleDefinitionCreator.new
62
63
  end
63
64
 
64
65
  describe "#mock" do
65
- it_should_behave_like "RR::DoubleCreator strategy definition"
66
+ it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
66
67
 
67
68
  before do
68
69
  @method_name = :mock
@@ -72,19 +73,13 @@ module RR
72
73
  creates_mock_call_chain(creator.mock(subject))
73
74
  end
74
75
 
75
- it "creates a mock Double for method when passed a second argument with rr_mock" do
76
- creates_double_with_method_name(
77
- creator.mock(subject, :foobar)
78
- )
79
- end
80
-
81
76
  it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
82
77
  double = creator.mock(subject, :foobar)
83
78
  double.block_callback_strategy.should == :returns
84
79
  end
85
80
 
86
- def creates_double_with_method_name(double)
87
- double.with(1, 2) {:baz}
81
+ def creates_mock_call_chain(creator)
82
+ double = creator.foobar(1, 2) {:baz}
88
83
  double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
89
84
  double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
90
85
  double.argument_expectation.expected_arguments.should == [1, 2]
@@ -92,18 +87,32 @@ module RR
92
87
  subject.foobar(1, 2).should == :baz
93
88
  end
94
89
 
95
- def creates_mock_call_chain(creator)
96
- double = creator.foobar(1, 2) {:baz}
97
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
98
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
99
- double.argument_expectation.expected_arguments.should == [1, 2]
90
+ context "when passed a second argument" do
91
+ it "creates a mock Double for method" do
92
+ creates_double_with_method_name( creator.mock(subject, :foobar) )
93
+ end
100
94
 
101
- subject.foobar(1, 2).should == :baz
95
+ def creates_double_with_method_name(double)
96
+ double.with(1, 2) {:baz}
97
+ double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
98
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
99
+ double.argument_expectation.expected_arguments.should == [1, 2]
100
+
101
+ subject.foobar(1, 2).should == :baz
102
+ end
103
+ end
104
+
105
+ context "when passed method_name and block" do
106
+ it "raises error" do
107
+ lambda do
108
+ @creator.mock(@object, :foobar) {}
109
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
110
+ end
102
111
  end
103
112
  end
104
113
 
105
114
  describe "#stub" do
106
- it_should_behave_like "RR::DoubleCreator strategy definition"
115
+ it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
107
116
 
108
117
  before do
109
118
  @method_name = :stub
@@ -113,20 +122,22 @@ module RR
113
122
  creates_stub_call_chain(creator.stub(subject))
114
123
  end
115
124
 
116
- it "creates a stub Double for method when passed a second argument" do
117
- creates_double_with_method_name(creator.stub(subject, :foobar))
118
- end
119
-
120
125
  it "sets up the DoubleDefinition to be in returns block_callback_strategy" do
121
126
  double = creator.stub(subject, :foobar)
122
127
  double.block_callback_strategy.should == :returns
123
128
  end
124
129
 
125
- def creates_double_with_method_name(double)
126
- double.with(1, 2) {:baz}
127
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
128
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
129
- subject.foobar(1, 2).should == :baz
130
+ context "when passed a second argument" do
131
+ it "creates a stub Double for method when passed a second argument" do
132
+ creates_double_with_method_name(creator.stub(subject, :foobar))
133
+ end
134
+
135
+ def creates_double_with_method_name(double)
136
+ double.with(1, 2) {:baz}
137
+ double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
138
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
139
+ subject.foobar(1, 2).should == :baz
140
+ end
130
141
  end
131
142
 
132
143
  def creates_stub_call_chain(creator)
@@ -135,10 +146,18 @@ module RR
135
146
  double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
136
147
  subject.foobar(1, 2).should == :baz
137
148
  end
149
+
150
+ context "when passed method_name and block" do
151
+ it "raises error" do
152
+ lambda do
153
+ @creator.stub(@object, :foobar) {}
154
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
155
+ end
156
+ end
138
157
  end
139
158
 
140
159
  describe "#dont_allow" do
141
- it_should_behave_like "RR::DoubleCreator strategy definition"
160
+ it_should_behave_like "RR::DoubleDefinitionCreator strategy definition"
142
161
 
143
162
  before do
144
163
  @method_name = :dont_allow
@@ -146,7 +165,7 @@ module RR
146
165
 
147
166
  it "raises error when proxied" do
148
167
  creator.proxy
149
- proc do
168
+ lambda do
150
169
  creator.dont_allow
151
170
  end.should raise_error(
152
171
  Errors::DoubleDefinitionError,
@@ -170,33 +189,35 @@ module RR
170
189
  creates_dont_allow_call_chain(creator.dont_allow(subject))
171
190
  end
172
191
 
173
- it "creates a mock Double for method when passed a second argument" do
174
- creates_double_with_method_name(creator.dont_allow(subject, :foobar))
175
- end
176
-
177
- it "creates a mock Double for method when passed a second argument" do
178
- creates_double_with_method_name(creator.dont_call(subject, :foobar))
179
- end
192
+ context "when passed a second argument_expectation" do
193
+ it "creates a mock Double for method" do
194
+ creates_double_with_method_name(creator.dont_allow(subject, :foobar))
195
+ end
180
196
 
181
- it "creates a mock Double for method when passed a second argument" do
182
- creates_double_with_method_name(creator.do_not_allow(subject, :foobar))
183
- end
197
+ it "creates a mock Double for method" do
198
+ creates_double_with_method_name(creator.dont_call(subject, :foobar))
199
+ end
184
200
 
185
- it "creates a mock Double for method when passed a second argument" do
186
- creates_double_with_method_name(creator.dont_allow(subject, :foobar))
187
- end
201
+ it "creates a mock Double for method" do
202
+ creates_double_with_method_name(creator.do_not_allow(subject, :foobar))
203
+ end
188
204
 
189
- def creates_double_with_method_name(double)
190
- double.with(1, 2)
191
- double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
192
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
193
- double.argument_expectation.expected_arguments.should == [1, 2]
205
+ it "creates a mock Double for method" do
206
+ creates_double_with_method_name(creator.dont_allow(subject, :foobar))
207
+ end
194
208
 
195
- proc do
196
- subject.foobar(1, 2)
197
- end.should raise_error(Errors::TimesCalledError)
198
- reset
199
- nil
209
+ def creates_double_with_method_name(double)
210
+ double.with(1, 2)
211
+ double.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
212
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
213
+ double.argument_expectation.expected_arguments.should == [1, 2]
214
+
215
+ lambda do
216
+ subject.foobar(1, 2)
217
+ end.should raise_error(Errors::TimesCalledError)
218
+ reset
219
+ nil
220
+ end
200
221
  end
201
222
 
202
223
  def creates_dont_allow_call_chain(creator)
@@ -205,12 +226,20 @@ module RR
205
226
  double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
206
227
  double.argument_expectation.expected_arguments.should == [1, 2]
207
228
 
208
- proc do
229
+ lambda do
209
230
  subject.foobar(1, 2)
210
231
  end.should raise_error(Errors::TimesCalledError)
211
232
  reset
212
233
  nil
213
234
  end
235
+
236
+ context "when passed method_name and block" do
237
+ it "raises error" do
238
+ lambda do
239
+ @creator.dont_allow(@object, :foobar) {}
240
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
241
+ end
242
+ end
214
243
  end
215
244
 
216
245
  describe "(#proxy or #proxy) and #stub" do
@@ -224,7 +253,7 @@ module RR
224
253
 
225
254
  it "raises error when using dont_allow strategy" do
226
255
  creator.dont_allow
227
- proc do
256
+ lambda do
228
257
  creator.proxy
229
258
  end.should raise_error(
230
259
  Errors::DoubleDefinitionError,
@@ -246,20 +275,22 @@ module RR
246
275
  subject.foobar(1, 2).should == :baz
247
276
  end
248
277
 
249
- it "creates a proxy Double for method when passed a second argument" do
250
- double = creator.stub.proxy(subject, :foobar)
251
- double.with(1, 2) {:baz}
252
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
253
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
254
- subject.foobar(1, 2).should == :baz
255
- end
278
+ context "when passed a second argument" do
279
+ it "creates a proxy Double for method" do
280
+ double = creator.stub.proxy(subject, :foobar)
281
+ double.with(1, 2) {:baz}
282
+ double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
283
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
284
+ subject.foobar(1, 2).should == :baz
285
+ end
256
286
 
257
- it "creates a proxy Double for method when passed a second argument" do
258
- double = creator.stub.proxy(subject, :foobar)
259
- double.with(1, 2) {:baz}
260
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
261
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
262
- subject.foobar(1, 2).should == :baz
287
+ it "creates a proxy Double for method" do
288
+ double = creator.stub.proxy(subject, :foobar)
289
+ double.with(1, 2) {:baz}
290
+ double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
291
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
292
+ subject.foobar(1, 2).should == :baz
293
+ end
263
294
  end
264
295
 
265
296
  it "sets up the DoubleDefinition to be in after_call block_callback_strategy" do
@@ -275,11 +306,19 @@ module RR
275
306
  args.should == [:original_implementation_value]
276
307
  double.block_callback_strategy.should == :after_call
277
308
  end
309
+
310
+ context "when passed method_name and block" do
311
+ it "raises error" do
312
+ lambda do
313
+ @creator.proxy(@object, :foobar) {}
314
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
315
+ end
316
+ end
278
317
  end
279
318
 
280
319
  describe "#instance_of" do
281
320
  it "raises an error when not passed a class" do
282
- proc do
321
+ lambda do
283
322
  creator.instance_of(Object.new)
284
323
  end.should raise_error(ArgumentError, "instance_of only accepts class objects")
285
324
  end
@@ -292,20 +331,29 @@ module RR
292
331
  klass.new.foobar(1, 2).should == :baz
293
332
  end
294
333
 
295
- it "creates a proxy Double for method when passed a second argument" do
334
+ context "when passed a second argument" do
335
+ it "creates a proxy Double for method" do
336
+ klass = Class.new
337
+ double = creator.stub.instance_of(klass, :foobar)
338
+ double.with(1, 2) {:baz}
339
+ double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
340
+ double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
341
+ klass.new.foobar(1, 2).should == :baz
342
+ end
343
+ end
344
+
345
+ it "raises error" do
296
346
  klass = Class.new
297
- double = creator.stub.instance_of(klass, :foobar)
298
- double.with(1, 2) {:baz}
299
- double.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
300
- double.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
301
- klass.new.foobar(1, 2).should == :baz
347
+ lambda do
348
+ @creator.instance_of(klass, :foobar) {}
349
+ end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
302
350
  end
303
351
  end
304
352
 
305
- describe "#create! using no strategy" do
353
+ describe "#create using no strategy" do
306
354
  it "raises error" do
307
- proc do
308
- creator.create!(subject, :foobar, 1, 2)
355
+ lambda do
356
+ creator.create(subject, :foobar, 1, 2)
309
357
  end.should raise_error(
310
358
  Errors::DoubleDefinitionError,
311
359
  "This Double has no strategy"
@@ -313,65 +361,65 @@ module RR
313
361
  end
314
362
  end
315
363
 
316
- describe "#create! using mock strategy" do
364
+ describe "#create using mock strategy" do
317
365
  before do
318
366
  creator.mock
319
367
  end
320
368
 
321
369
  it "sets expectations on the subject" do
322
- creator.create!(subject, :foobar, 1, 2) {:baz}.twice
370
+ creator.create(subject, :foobar, 1, 2) {:baz}.twice
323
371
 
324
372
  subject.foobar(1, 2).should == :baz
325
373
  subject.foobar(1, 2).should == :baz
326
- proc {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
374
+ lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
327
375
  end
328
376
  end
329
377
 
330
- describe "#create! using stub strategy" do
378
+ describe "#create using stub strategy" do
331
379
  before do
332
380
  creator.stub
333
381
  end
334
382
 
335
383
  it "stubs the subject without any args" do
336
- creator.create!(subject, :foobar) {:baz}
384
+ creator.create(subject, :foobar) {:baz}
337
385
  subject.foobar.should == :baz
338
386
  end
339
387
 
340
388
  it "stubs the subject mapping passed in args with the output" do
341
- creator.create!(subject, :foobar, 1, 2) {:one_two}
342
- creator.create!(subject, :foobar, 1) {:one}
343
- creator.create!(subject, :foobar) {:nothing}
389
+ creator.create(subject, :foobar, 1, 2) {:one_two}
390
+ creator.create(subject, :foobar, 1) {:one}
391
+ creator.create(subject, :foobar) {:nothing}
344
392
  subject.foobar.should == :nothing
345
393
  subject.foobar(1).should == :one
346
394
  subject.foobar(1, 2).should == :one_two
347
395
  end
348
396
  end
349
397
 
350
- describe "#create! using dont_allow strategy" do
398
+ describe "#create using dont_allow strategy" do
351
399
  before do
352
400
  creator.dont_allow
353
401
  end
354
402
 
355
403
  it "sets expectation for method to never be called with any arguments when on arguments passed in" do
356
- creator.create!(subject, :foobar)
357
- proc {subject.foobar}.should raise_error(Errors::TimesCalledError)
358
- proc {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
404
+ creator.create(subject, :foobar)
405
+ lambda {subject.foobar}.should raise_error(Errors::TimesCalledError)
406
+ lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
359
407
  end
360
408
 
361
409
  it "sets expectation for method to never be called with passed in arguments" do
362
- creator.create!(subject, :foobar, 1, 2)
363
- proc {subject.foobar}.should raise_error(Errors::DoubleNotFoundError)
364
- proc {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
410
+ creator.create(subject, :foobar, 1, 2)
411
+ lambda {subject.foobar}.should raise_error(Errors::DoubleNotFoundError)
412
+ lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
365
413
  end
366
414
 
367
415
  it "sets expectation for method to never be called with no arguments when with_no_args is set" do
368
- creator.create!(subject, :foobar).with_no_args
369
- proc {subject.foobar}.should raise_error(Errors::TimesCalledError)
370
- proc {subject.foobar(1, 2)}.should raise_error(Errors::DoubleNotFoundError)
416
+ creator.create(subject, :foobar).with_no_args
417
+ lambda {subject.foobar}.should raise_error(Errors::TimesCalledError)
418
+ lambda {subject.foobar(1, 2)}.should raise_error(Errors::DoubleNotFoundError)
371
419
  end
372
420
  end
373
421
 
374
- describe "#create! using mock strategy with proxy" do
422
+ describe "#create using mock strategy with proxy" do
375
423
  before do
376
424
  creator.mock
377
425
  creator.proxy
@@ -381,21 +429,18 @@ module RR
381
429
  def subject.foobar(*args)
382
430
  ; :baz;
383
431
  end
384
- creator.create!(subject, :foobar, 1, 2).twice
432
+ creator.create(subject, :foobar, 1, 2).twice
385
433
  subject.foobar(1, 2).should == :baz
386
434
  subject.foobar(1, 2).should == :baz
387
- proc {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
435
+ lambda {subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
388
436
  end
389
437
 
390
438
  it "sets after_call on the double when passed a block" do
391
439
  real_value = Object.new
392
- (
393
- class << subject;
394
- self;
395
- end).class_eval do
440
+ (class << subject; self; end).class_eval do
396
441
  define_method(:foobar) {real_value}
397
442
  end
398
- creator.create!(subject, :foobar, 1, 2) do |value|
443
+ creator.create(subject, :foobar, 1, 2) do |value|
399
444
  mock(value).a_method {99}
400
445
  value
401
446
  end
@@ -406,7 +451,7 @@ module RR
406
451
  end
407
452
  end
408
453
 
409
- describe "#create! using stub strategy with proxy" do
454
+ describe "#create using stub strategy with proxy" do
410
455
  before do
411
456
  creator.stub
412
457
  creator.proxy
@@ -414,19 +459,19 @@ module RR
414
459
 
415
460
  it "sets up a double with passed in arguments" do
416
461
  def subject.foobar(*args)
417
- ; :baz;
462
+ :baz
418
463
  end
419
- creator.create!(subject, :foobar, 1, 2)
420
- proc do
464
+ creator.create(subject, :foobar, 1, 2)
465
+ lambda do
421
466
  subject.foobar
422
467
  end.should raise_error(Errors::DoubleNotFoundError)
423
468
  end
424
469
 
425
470
  it "sets expectations on the subject while calling the original method" do
426
471
  def subject.foobar(*args)
427
- ; :baz;
472
+ :baz
428
473
  end
429
- creator.create!(subject, :foobar, 1, 2) {:new_value}
474
+ creator.create(subject, :foobar, 1, 2) {:new_value}
430
475
  10.times do
431
476
  subject.foobar(1, 2).should == :new_value
432
477
  end
@@ -434,13 +479,10 @@ module RR
434
479
 
435
480
  it "sets after_call on the double when passed a block" do
436
481
  real_value = Object.new
437
- (
438
- class << subject;
439
- self;
440
- end).class_eval do
482
+ (class << subject; self; end).class_eval do
441
483
  define_method(:foobar) {real_value}
442
484
  end
443
- creator.create!(subject, :foobar, 1, 2) do |value|
485
+ creator.create(subject, :foobar, 1, 2) do |value|
444
486
  mock(value).a_method {99}
445
487
  value
446
488
  end