rr 0.10.10 → 0.10.11

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 (50) hide show
  1. data/CHANGES +4 -0
  2. data/VERSION.yml +1 -1
  3. data/lib/rr.rb +5 -3
  4. data/lib/rr/adapters/rr_methods.rb +5 -5
  5. data/lib/rr/blank_slate.rb +17 -0
  6. data/lib/rr/double_definitions/{child_double_definition_creator.rb → child_double_definition_create.rb} +1 -1
  7. data/lib/rr/double_definitions/double_definition.rb +13 -11
  8. data/lib/rr/double_definitions/{double_definition_creator.rb → double_definition_create.rb} +52 -43
  9. data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +26 -0
  10. data/lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb +2 -2
  11. data/lib/rr/double_definitions/strategies/scope/instance.rb +1 -1
  12. data/lib/rr/double_definitions/strategies/scope/instance_of_class.rb +6 -6
  13. data/lib/rr/double_definitions/strategies/scope/scope_strategy.rb +2 -2
  14. data/lib/rr/double_definitions/strategies/strategy.rb +15 -16
  15. data/lib/rr/double_definitions/strategies/verification/mock.rb +1 -1
  16. data/lib/rr/double_definitions/strategies/verification/stub.rb +1 -1
  17. data/lib/rr/double_definitions/strategies/verification/verification_strategy.rb +2 -2
  18. data/lib/rr/injections/double_injection.rb +59 -4
  19. data/lib/rr/injections/injection.rb +6 -0
  20. data/lib/rr/injections/method_missing_injection.rb +13 -1
  21. data/lib/rr/injections/singleton_method_added_injection.rb +14 -3
  22. data/lib/rr/method_dispatches/base_method_dispatch.rb +2 -2
  23. data/lib/rr/method_dispatches/method_missing_dispatch.rb +2 -2
  24. data/lib/rr/recorded_calls.rb +1 -1
  25. data/lib/rr/space.rb +17 -68
  26. data/lib/rr/spy_verification_proxy.rb +1 -6
  27. data/spec/rr/adapters/rr_methods_creator_spec.rb +9 -21
  28. data/spec/rr/adapters/rr_methods_space_spec.rb +10 -25
  29. data/spec/rr/double_definitions/child_double_definition_creator_spec.rb +16 -16
  30. data/spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb +87 -0
  31. data/spec/rr/double_definitions/{double_definition_creator_spec.rb → double_definition_create_spec.rb} +64 -72
  32. data/spec/rr/double_injection/double_injection_verify_spec.rb +2 -2
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +5 -29
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +7 -39
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +19 -47
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +1 -9
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +18 -64
  38. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +7 -53
  39. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +12 -56
  40. data/spec/rr/rspec/rspec_adapter_spec.rb +8 -11
  41. data/spec/rr/space/space_spec.rb +72 -212
  42. data/spec/spec_helper.rb +0 -76
  43. data/spec/spy_verification_spec.rb +1 -1
  44. metadata +8 -11
  45. data/lib/rr/double_definitions/double_definition_creator_proxy.rb +0 -37
  46. data/ruby_19_spec.rb +0 -12
  47. data/spec/rr/double_definitions/double_definition_creator_proxy_spec.rb +0 -124
  48. data/spec/rr/double_definitions/double_definition_spec.rb +0 -1168
  49. data/spec/rr/double_spec.rb +0 -361
  50. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +0 -38
data/spec/spec_helper.rb CHANGED
@@ -29,82 +29,6 @@ class Spec::ExampleGroup
29
29
  define_method(name, &implementation)
30
30
  end
31
31
  end
32
-
33
- define_method("normal strategy definition") do
34
- describe "strategy definition" do
35
- attr_reader :strategy_method_name
36
-
37
- context "when passed a subject" do
38
- it "returns a DoubleDefinitionCreatorProxy" do
39
- double = call_strategy(subject).foobar
40
- double.should be_instance_of(RR::DoubleDefinitions::DoubleDefinition)
41
- end
42
- end
43
-
44
- context "when passed a method name and a definition_eval_block" do
45
- it "raises an ArgumentError" do
46
- lambda do
47
- call_strategy(subject, :foobar) {}
48
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
49
- end
50
- end
51
- end
52
- end
53
-
54
- define_method("! strategy definition") do
55
- describe "strategy definition" do
56
- attr_reader :strategy_method_name
57
-
58
- context "when not passed a method_name argument" do
59
- it "returns a DoubleDefinitionCreatorProxy" do
60
- call_strategy.should respond_to(:__subject__)
61
- end
62
-
63
- context "when passed a definition_eval_block argument" do
64
- it "calls the definition_eval_block and passes in the DoubleDefinitionCreatorProxy" do
65
- passed_in_proxy = nil
66
- proxy = call_strategy do |proxy|
67
- passed_in_proxy = proxy
68
- end
69
-
70
- passed_in_proxy.should == proxy
71
- end
72
- end
73
- end
74
-
75
- context "when passed a method_name argument" do
76
- it "returns a DoubleDefinition" do
77
- double_definition = call_strategy(:foobar)
78
- double_definition.class.should == RR::DoubleDefinitions::DoubleDefinition
79
- end
80
-
81
- describe "the returned DoubleDefinition" do
82
- it "has #subject set to an anonymous Object" do
83
- double_definition = call_strategy(:foobar)
84
- double_definition.subject.class.should == Object
85
- end
86
- end
87
- end
88
-
89
- context "when passed a method name and a definition_eval_block" do
90
- it "raises an ArgumentError" do
91
- lambda do
92
- call_strategy(:foobar) {}
93
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
94
- end
95
- end
96
- end
97
- end
98
- end
99
-
100
- def new_double(
101
- double_injection=double_injection,
102
- double_definition=RR::DoubleDefinitions::DoubleDefinition.new(creator = RR::DoubleDefinitions::DoubleDefinitionCreator.new, subject).with_any_args.any_number_of_times
103
- )
104
- RR::Double.new(
105
- double_injection,
106
- double_definition
107
- )
108
32
  end
109
33
 
110
34
  def eigen(object)
@@ -119,7 +119,7 @@ describe RR::SpyVerification do
119
119
 
120
120
  context "when the subject is expected where there is not DoubleInjection" do
121
121
  it "raises a DoubleInjectionNotFoundError" do
122
- space.double_injection_exists?(subject, :method_that_does_not_exist).should be_false
122
+ ::RR::Injections::DoubleInjection.exists?(subject, :method_that_does_not_exist).should be_false
123
123
  lambda do
124
124
  received(subject).method_that_does_not_exist.call
125
125
  end.should raise_error(RR::Errors::SpyVerificationErrors::DoubleInjectionNotFoundError)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.10
4
+ version: 0.10.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Takita
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-25 00:00:00 -08:00
12
+ date: 2010-03-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -32,11 +32,12 @@ files:
32
32
  - lib/rr/adapters/rr_methods.rb
33
33
  - lib/rr/adapters/rspec.rb
34
34
  - lib/rr/adapters/test_unit.rb
35
+ - lib/rr/blank_slate.rb
35
36
  - lib/rr/double.rb
36
- - lib/rr/double_definitions/child_double_definition_creator.rb
37
+ - lib/rr/double_definitions/child_double_definition_create.rb
37
38
  - lib/rr/double_definitions/double_definition.rb
38
- - lib/rr/double_definitions/double_definition_creator.rb
39
- - lib/rr/double_definitions/double_definition_creator_proxy.rb
39
+ - lib/rr/double_definitions/double_definition_create.rb
40
+ - lib/rr/double_definitions/double_definition_create_blank_slate.rb
40
41
  - lib/rr/double_definitions/strategies/implementation/implementation_strategy.rb
41
42
  - lib/rr/double_definitions/strategies/implementation/proxy.rb
42
43
  - lib/rr/double_definitions/strategies/implementation/reimplementation.rb
@@ -97,7 +98,6 @@ files:
97
98
  - lib/rr/wildcard_matchers/range.rb
98
99
  - lib/rr/wildcard_matchers/regexp.rb
99
100
  - lib/rr/wildcard_matchers/satisfy.rb
100
- - ruby_19_spec.rb
101
101
  - spec/api/dont_allow/dont_allow_after_stub_spec.rb
102
102
  - spec/api/mock/mock_spec.rb
103
103
  - spec/api/proxy/proxy_spec.rb
@@ -113,12 +113,10 @@ files:
113
113
  - spec/rr/adapters/rr_methods_spec_helper.rb
114
114
  - spec/rr/adapters/rr_methods_times_matcher_spec.rb
115
115
  - spec/rr/double_definitions/child_double_definition_creator_spec.rb
116
- - spec/rr/double_definitions/double_definition_creator_proxy_spec.rb
117
- - spec/rr/double_definitions/double_definition_creator_spec.rb
118
- - spec/rr/double_definitions/double_definition_spec.rb
116
+ - spec/rr/double_definitions/double_definition_create_blank_slate_spec.rb
117
+ - spec/rr/double_definitions/double_definition_create_spec.rb
119
118
  - spec/rr/double_injection/double_injection_spec.rb
120
119
  - spec/rr/double_injection/double_injection_verify_spec.rb
121
- - spec/rr/double_spec.rb
122
120
  - spec/rr/errors/rr_error_spec.rb
123
121
  - spec/rr/expectations/any_argument_expectation_spec.rb
124
122
  - spec/rr/expectations/anything_argument_equality_expectation_spec.rb
@@ -135,7 +133,6 @@ files:
135
133
  - spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb
136
134
  - spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb
137
135
  - spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb
138
- - spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb
139
136
  - spec/rr/rspec/invocation_matcher_spec.rb
140
137
  - spec/rr/rspec/rspec_adapter_spec.rb
141
138
  - spec/rr/rspec/rspec_backtrace_tweaking_spec.rb
@@ -1,37 +0,0 @@
1
- module RR
2
- module DoubleDefinitions
3
- class DoubleDefinitionCreatorProxy
4
- class << self
5
- def blank_slate_methods
6
- instance_methods.each do |m|
7
- unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == 'respond_to?' || m.to_s == 'method_missing' || m.to_s == 'instance_eval' || m.to_s == 'instance_exec'
8
- alias_method "__blank_slated_#{m}", m
9
- undef_method m
10
- end
11
- end
12
- end
13
- end
14
-
15
- def initialize(creator, &block) #:nodoc:
16
- @creator = creator
17
- respond_to?(:class) ? self.class.blank_slate_methods : __blank_slated_class.blank_slate_methods
18
-
19
- if block_given?
20
- if block.arity == 1
21
- yield(self)
22
- else
23
- respond_to?(:instance_eval) ? instance_eval(&block) : __blank_slated_instance_eval(&block)
24
- end
25
- end
26
- end
27
-
28
- def method_missing(method_name, *args, &block)
29
- @creator.create(method_name, *args, &block)
30
- end
31
-
32
- def __creator__
33
- @creator
34
- end
35
- end
36
- end
37
- end
data/ruby_19_spec.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'rubygems'
2
- require 'spec'
3
- require 'rr'
4
- include RR::Adapters::Rspec
5
-
6
- mock( socket = Object.new )
7
- stub(socket).bind("", 3333)
8
-
9
- stub(UDPSocket).new { socket }
10
-
11
- UDPSocket.new.bind( "", 3333 )
12
- UDPSocket.new.bind( "", 3333 )
@@ -1,124 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe DoubleDefinitionCreatorProxy do
6
- attr_reader :subject, :creator, :the_proxy
7
- it_should_behave_like "Swapped Space"
8
-
9
- before(:each) do
10
- @subject = Object.new
11
- @creator = DoubleDefinitionCreator.new
12
- creator.mock(subject)
13
- end
14
-
15
- macro("initializes proxy with passed in creator") do
16
- it "initializes proxy with passed in creator" do
17
- class << the_proxy
18
- attr_reader :creator
19
- end
20
- the_proxy.creator.should === creator
21
- end
22
- end
23
-
24
- describe ".new" do
25
- it "does not undefine object_id" do
26
- the_proxy = DoubleDefinitionCreatorProxy.new(creator)
27
- the_proxy.object_id.class.should == Fixnum
28
- end
29
-
30
- context "without block" do
31
- before do
32
- @the_proxy = DoubleDefinitionCreatorProxy.new(creator)
33
- end
34
-
35
- send "initializes proxy with passed in creator"
36
-
37
- it "clears out all methods from proxy" do
38
- proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
39
- def i_should_be_a_double
40
- end
41
- end
42
- proxy_subclass.instance_methods.map {|m| m.to_s}.should include('i_should_be_a_double')
43
-
44
- proxy = proxy_subclass.new(creator)
45
- proxy.i_should_be_a_double.should be_instance_of(DoubleDefinition)
46
- end
47
- end
48
-
49
- context "when passed a block" do
50
- macro("calls the block to define the Doubles") do
51
- send "initializes proxy with passed in creator"
52
-
53
- it "creates double_injections" do
54
- subject.foobar(1, 2).should == :one_two
55
- subject.foobar(1).should == :one
56
- subject.foobar(:something).should == :default
57
- subject.baz.should == :baz_result
58
- end
59
-
60
- it "clears out all methods from proxy" do
61
- proxy_subclass = Class.new(DoubleDefinitionCreatorProxy) do
62
- def i_should_be_a_double
63
- end
64
- end
65
- proxy_subclass.instance_methods.map {|m| m.to_s}.should include('i_should_be_a_double')
66
-
67
- proxy_subclass.new(creator) do |m|
68
- m.i_should_be_a_double.should be_instance_of(DoubleDefinition)
69
- end
70
- end
71
- end
72
-
73
- context "when the block has an arity of 1" do
74
- attr_reader :passed_in_argument
75
- before do
76
- passed_in_argument = nil
77
- block = lambda do |b|
78
- passed_in_argument = b
79
- b.foobar(1, 2) {:one_two}
80
- b.foobar(1) {:one}
81
- b.foobar.with_any_args {:default}
82
- b.baz() {:baz_result}
83
- end
84
- block.arity.should == 1
85
-
86
- @the_proxy = DoubleDefinitionCreatorProxy.new(creator, &block)
87
- @passed_in_argument = passed_in_argument
88
- end
89
-
90
- send("calls the block to define the Doubles")
91
-
92
- it "passes the self into the block" do
93
- passed_in_argument.__creator__.should == creator
94
- end
95
- end
96
-
97
- context "when the block has an arity of 0" do
98
- attr_reader :self_value
99
- before do
100
- self_value = nil
101
- block = lambda do ||
102
- self_value = self
103
- foobar(1, 2) {:one_two}
104
- foobar(1) {:one}
105
- foobar.with_any_args {:default}
106
- baz() {:baz_result}
107
- end
108
- block.arity.should == 0
109
-
110
- @the_proxy = DoubleDefinitionCreatorProxy.new(creator, &block)
111
- @self_value = self_value
112
- end
113
-
114
- send("calls the block to define the Doubles")
115
-
116
- it "evaluates the block with the context of self" do
117
- self_value.__creator__.should == creator
118
- end
119
- end
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,1168 +0,0 @@
1
- require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
2
-
3
- module RR
4
- module DoubleDefinitions
5
- describe DoubleDefinition do
6
- attr_reader :subject, :double_definition_creator, :double, :definition
7
-
8
- it_should_behave_like "Swapped Space"
9
-
10
- before do
11
- @subject = Object.new
12
- add_original_method
13
- @double_definition_creator = DoubleDefinitionCreator.new
14
- @definition = double_definition_creator.stub(subject).foobar
15
- @double = definition.double
16
- end
17
-
18
- def add_original_method
19
- def subject.foobar(a, b)
20
- :original_return_value
21
- end
22
- end
23
-
24
- describe "#root_subject" do
25
- it "returns #double_definition_creator.root_subject" do
26
- definition.root_subject.should == definition.double_definition_creator.root_subject
27
- definition.root_subject.should == subject
28
- end
29
- end
30
-
31
- describe "DefinitionConstructionMethods" do
32
- macro("DoubleDefinition where #double_definition_creator is a Reimplementation") do
33
- before do
34
- definition.double_definition_creator.implementation_strategy.class.should == Strategies::Implementation::Reimplementation
35
- call_double_injection
36
- end
37
- end
38
-
39
- macro("DoubleDefinition where #double_definition_creator is a Proxy") do
40
- before do
41
- definition.double_definition_creator.proxy
42
- definition.double_definition_creator.implementation_strategy.class.should == Strategies::Implementation::Proxy
43
- call_double_injection
44
- end
45
- end
46
-
47
- describe "#with" do
48
- macro("#with") do
49
- it "returns DoubleDefinition" do
50
- definition.with(1).should === definition
51
- end
52
-
53
- it "sets an ArgumentEqualityExpectation" do
54
- definition.should be_exact_match(1, 2)
55
- definition.should_not be_exact_match(2)
56
- end
57
- end
58
-
59
- context "when not passed a block" do
60
- before do
61
- definition.with(1, 2)
62
- subject.foobar(1, 2)
63
- end
64
-
65
- send "#with"
66
- end
67
-
68
- context "when passed a block" do
69
- def call_double_injection
70
- actual_args = nil
71
- definition.with(1, 2) do |*args|
72
- actual_args = args
73
- :new_return_value
74
- end
75
- subject.foobar(1, 2)
76
- @return_value = subject.foobar(1, 2)
77
- @args = actual_args
78
- end
79
-
80
- context "when #double_definition_creator.implementation_strategy is a Reimplementation" do
81
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
82
- send "#with"
83
-
84
- describe "#subject.method_name being called" do
85
- it "returns the return value of the block" do
86
- @return_value.should == :new_return_value
87
- @args.should == [1, 2]
88
- end
89
- end
90
- end
91
-
92
- context "when #double_definition_creator.implementation_strategy is a Proxy" do
93
- send "DoubleDefinition where #double_definition_creator is a Proxy"
94
- send "#with"
95
-
96
- describe "#subject.method_name being called" do
97
- it "returns the return value of the block" do
98
- @return_value.should == :new_return_value
99
- @args.should == [:original_return_value]
100
- end
101
- end
102
- end
103
- end
104
- end
105
-
106
- describe "#with_any_args" do
107
- macro "#with_any_args" do
108
- it "returns DoubleDefinition" do
109
- definition.with_no_args.should === definition
110
- end
111
-
112
- it "sets an AnyArgumentExpectation" do
113
- definition.should_not be_exact_match(1)
114
- definition.should be_wildcard_match(1)
115
- end
116
- end
117
-
118
- context "when not passed a block" do
119
- before do
120
- definition.with_any_args
121
- end
122
-
123
- send "#with_any_args"
124
- end
125
-
126
- context "when passed a block" do
127
- def call_double_injection
128
- actual_args = nil
129
- definition.with_any_args do |*args|
130
- actual_args = args
131
- :new_return_value
132
- end
133
- @return_value = subject.foobar(1, 2)
134
- @args = actual_args
135
- end
136
-
137
- context "when #double_definition_creator.implementation_strategy is a Reimplementation" do
138
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
139
- send "#with_any_args"
140
-
141
- describe "#subject.method_name being called" do
142
- it "returns the return value of the block" do
143
- @return_value.should == :new_return_value
144
- @args.should == [1, 2]
145
- end
146
- end
147
- end
148
-
149
- context "when #double_definition_creator.implementation_strategy is a Proxy" do
150
- send "DoubleDefinition where #double_definition_creator is a Proxy"
151
- send "#with_any_args"
152
-
153
- describe "#subject.method_name being called" do
154
- it "returns the return value of the block" do
155
- @return_value.should == :new_return_value
156
- @args.should == [:original_return_value]
157
- end
158
- end
159
- end
160
- end
161
- end
162
-
163
- describe "#with_no_args" do
164
- macro "#with_no_args" do
165
- it "returns DoubleDefinition" do
166
- definition.with_no_args.should === definition
167
- end
168
-
169
- it "sets an ArgumentEqualityExpectation with no arguments" do
170
- definition.argument_expectation.should == RR::Expectations::ArgumentEqualityExpectation.new()
171
- end
172
- end
173
-
174
- def add_original_method
175
- def subject.foobar()
176
- :original_return_value
177
- end
178
- end
179
-
180
- context "when not passed a block" do
181
- before do
182
- definition.with_no_args
183
- end
184
-
185
- send "#with_no_args"
186
- end
187
-
188
- context "when passed a block" do
189
- def call_double_injection
190
- actual_args = nil
191
- definition.with_no_args do |*args|
192
- actual_args = args
193
- :new_return_value
194
- end
195
- @return_value = subject.foobar
196
- @args = actual_args
197
- end
198
-
199
- context "when #double_definition_creator.implementation_strategy is a Reimplementation" do
200
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
201
- send "#with_no_args"
202
-
203
- describe "#subject.method_name being called" do
204
- it "returns the return value of the block" do
205
- @return_value.should == :new_return_value
206
- @args.should == []
207
- end
208
- end
209
- end
210
-
211
- context "when #double_definition_creator.implementation_strategy is a Proxy" do
212
- send "DoubleDefinition where #double_definition_creator is a Proxy"
213
- send "#with_no_args"
214
-
215
- describe "#subject.method_name being called" do
216
- it "returns the return value of the block" do
217
- @return_value.should == :new_return_value
218
- @args.should == [:original_return_value]
219
- end
220
- end
221
- end
222
- end
223
- end
224
-
225
- describe "#never" do
226
- it "returns DoubleDefinition" do
227
- definition.never.should === definition
228
- end
229
-
230
- it "sets up a Times Called Expectation with 0" do
231
- definition.with_any_args
232
- definition.never
233
- lambda {subject.foobar}.should raise_error(RR::Errors::TimesCalledError)
234
- end
235
-
236
- describe "#subject.method_name being called" do
237
- it "raises a TimesCalledError" do
238
- definition.with_any_args.never
239
- lambda {subject.foobar}.should raise_error(RR::Errors::TimesCalledError)
240
- end
241
- end
242
- end
243
-
244
- describe "#once" do
245
- macro "#once" do
246
- it "returns DoubleDefinition" do
247
- definition.once.should === definition
248
- end
249
-
250
- it "sets up a Times Called Expectation with 1" do
251
- lambda {subject.foobar}.should raise_error(RR::Errors::TimesCalledError)
252
- end
253
- end
254
-
255
- context "when not passed a block" do
256
- before do
257
- definition.with_any_args.once
258
- subject.foobar(1, 2)
259
- end
260
-
261
- send "#once"
262
- end
263
-
264
- context "when passed a block" do
265
- def call_double_injection
266
- actual_args = nil
267
- definition.with_any_args.once do |*args|
268
- actual_args = args
269
- :new_return_value
270
- end
271
- @return_value = subject.foobar(1, 2)
272
- @args = actual_args
273
- end
274
-
275
- context "with returns block_callback_strategy" do
276
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
277
- send "#once"
278
-
279
- describe "#subject.method_name being called with any arguments" do
280
- it "returns the return value of the block" do
281
- @return_value.should == :new_return_value
282
- @args.should == [1, 2]
283
- end
284
- end
285
- end
286
-
287
- context "with after_call block_callback_strategy" do
288
- send "DoubleDefinition where #double_definition_creator is a Proxy"
289
- send "#once"
290
-
291
- describe "#subject.method_name being called with any arguments" do
292
- it "returns the return value of the block" do
293
- @return_value.should == :new_return_value
294
- @args.should == [:original_return_value]
295
- end
296
- end
297
- end
298
- end
299
- end
300
-
301
- describe "#twice" do
302
- macro "#twice" do
303
- it "returns DoubleDefinition" do
304
- definition.twice.should === definition
305
- end
306
-
307
- it "sets up a Times Called Expectation with 2" do
308
- definition.twice.with_any_args
309
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
310
- end
311
- end
312
-
313
- context "when not passed a block" do
314
- before do
315
- definition.with_any_args.twice
316
- subject.foobar(1, 2)
317
- subject.foobar(1, 2)
318
- end
319
-
320
- send "#twice"
321
- end
322
-
323
- context "when passed a block" do
324
- def call_double_injection
325
- actual_args = nil
326
- definition.with_any_args.twice do |*args|
327
- actual_args = args
328
- :new_return_value
329
- end
330
- subject.foobar(1, 2)
331
- @return_value = subject.foobar(1, 2)
332
- @args = actual_args
333
- end
334
-
335
- context "with returns block_callback_strategy" do
336
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
337
- send "#twice"
338
-
339
- describe "#subject.method_name being called" do
340
- it "returns the return value of the block" do
341
- @return_value.should == :new_return_value
342
- @args.should == [1, 2]
343
- end
344
- end
345
- end
346
-
347
- context "with after_call block_callback_strategy" do
348
- send "DoubleDefinition where #double_definition_creator is a Proxy"
349
- send "#twice"
350
-
351
- describe "#subject.method_name being called" do
352
- it "returns the return value of the block" do
353
- @return_value.should == :new_return_value
354
- @args.should == [:original_return_value]
355
- end
356
- end
357
- end
358
- end
359
- end
360
-
361
- describe "#at_least" do
362
- macro "#at_least" do
363
- it "returns DoubleDefinition" do
364
- definition.with_any_args.at_least(2).should === definition
365
- end
366
-
367
- it "sets up a Times Called Expectation with 1" do
368
- definition.times_matcher.should == RR::TimesCalledMatchers::AtLeastMatcher.new(2)
369
- end
370
- end
371
-
372
- context "when not passed a block" do
373
- before do
374
- definition.with_any_args.at_least(2)
375
- subject.foobar(1, 2)
376
- end
377
-
378
- send "#at_least"
379
- end
380
-
381
- context "when passed a block" do
382
- def call_double_injection
383
- actual_args = nil
384
- definition.with_any_args.at_least(2) do |*args|
385
- actual_args = args
386
- :new_return_value
387
- end
388
- subject.foobar(1, 2)
389
- @return_value = subject.foobar(1, 2)
390
- @args = actual_args
391
- end
392
-
393
- context "with returns block_callback_strategy" do
394
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
395
- send "#at_least"
396
-
397
- describe "#subject.method_name being called" do
398
- it "returns the return value of the block" do
399
- @return_value.should == :new_return_value
400
- @args.should == [1, 2]
401
- end
402
- end
403
- end
404
-
405
- context "with after_call block_callback_strategy" do
406
- send "DoubleDefinition where #double_definition_creator is a Proxy"
407
- send "#at_least"
408
-
409
- describe "#subject.method_name being called" do
410
- it "returns the return value of the block" do
411
- @return_value.should == :new_return_value
412
- @args.should == [:original_return_value]
413
- end
414
- end
415
- end
416
- end
417
- end
418
-
419
- describe "#at_most" do
420
- macro "#at_most" do
421
- it "returns DoubleDefinition" do
422
- definition.with_any_args.at_most(2).should === definition
423
- end
424
-
425
- it "sets up a Times Called Expectation with 1" do
426
- lambda do
427
- subject.foobar
428
- end.should raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected at most 2 times.")
429
- end
430
- end
431
-
432
- context "when not passed a block" do
433
- before do
434
- definition.with_any_args.at_most(2)
435
- subject.foobar(1, 2)
436
- subject.foobar(1, 2)
437
- end
438
-
439
- send "#at_most"
440
- end
441
-
442
- context "when passed a block" do
443
- def call_double_injection
444
- actual_args = nil
445
- definition.with_any_args.at_most(2) do |*args|
446
- actual_args = args
447
- :new_return_value
448
- end
449
- subject.foobar(1, 2)
450
- @return_value = subject.foobar(1, 2)
451
- @args = actual_args
452
- end
453
-
454
- context "with returns block_callback_strategy" do
455
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
456
- send "#at_most"
457
-
458
- describe "#subject.method_name being called" do
459
- it "returns the return value of the block" do
460
- @return_value.should == :new_return_value
461
- @args.should == [1, 2]
462
- end
463
- end
464
- end
465
-
466
- context "with after_call block_callback_strategy" do
467
- send "DoubleDefinition where #double_definition_creator is a Proxy"
468
- send "#at_most"
469
-
470
- describe "#subject.method_name being called" do
471
- it "returns the return value of the block" do
472
- @return_value.should == :new_return_value
473
- @args.should == [:original_return_value]
474
- end
475
- end
476
- end
477
- end
478
- end
479
-
480
- describe "#times" do
481
- macro "#times" do
482
- it "returns DoubleDefinition" do
483
- definition.times(3).should === definition
484
- end
485
-
486
- it "sets up a Times Called Expectation with passed in times" do
487
- lambda {subject.foobar(1, 2)}.should raise_error(RR::Errors::TimesCalledError)
488
- end
489
- end
490
-
491
- context "when not passed a block" do
492
- before do
493
- definition.with(1, 2).times(3)
494
- subject.foobar(1, 2)
495
- subject.foobar(1, 2)
496
- subject.foobar(1, 2)
497
- end
498
-
499
- send "#times"
500
- end
501
-
502
- context "when passed a block" do
503
- def call_double_injection
504
- actual_args = nil
505
- definition.with(1, 2).times(3) do |*args|
506
- actual_args = args
507
- :new_return_value
508
- end
509
- subject.foobar(1, 2)
510
- subject.foobar(1, 2)
511
- @return_value = subject.foobar(1, 2)
512
- @args = actual_args
513
- end
514
-
515
- context "with returns block_callback_strategy" do
516
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
517
- send "#times"
518
-
519
- describe "#subject.method_name being called" do
520
- it "returns the return value of the block" do
521
- @return_value.should == :new_return_value
522
- @args.should == [1, 2]
523
- end
524
- end
525
- end
526
-
527
- context "with after_call block_callback_strategy" do
528
- send "DoubleDefinition where #double_definition_creator is a Proxy"
529
- send "#times"
530
-
531
- describe "#subject.method_name being called" do
532
- it "returns the return value of the block" do
533
- @return_value.should == :new_return_value
534
- @args.should == [:original_return_value]
535
- end
536
- end
537
- end
538
- end
539
- end
540
-
541
- describe "#any_number_of_times" do
542
- macro "#any_number_of_times" do
543
- it "returns DoubleDefinition" do
544
- definition.any_number_of_times.should === definition
545
- end
546
-
547
- it "sets up a Times Called Expectation with AnyTimes matcher" do
548
- definition.times_matcher.should == RR::TimesCalledMatchers::AnyTimesMatcher.new
549
- end
550
- end
551
-
552
- context "when not passed a block" do
553
- before do
554
- definition.with(1, 2).any_number_of_times
555
- subject.foobar(1, 2)
556
- end
557
-
558
- send "#any_number_of_times"
559
- end
560
-
561
- context "when passed a block" do
562
- def call_double_injection
563
- actual_args = nil
564
- definition.with(1, 2).any_number_of_times do |*args|
565
- actual_args = args
566
- :new_return_value
567
- end
568
- subject.foobar(1, 2)
569
- @return_value = subject.foobar(1, 2)
570
- @args = actual_args
571
- end
572
-
573
- context "with returns block_callback_strategy" do
574
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
575
- send "#any_number_of_times"
576
-
577
- describe "#subject.method_name being called" do
578
- it "returns the return value of the block" do
579
- @return_value.should == :new_return_value
580
- @args.should == [1, 2]
581
- end
582
- end
583
- end
584
-
585
- context "with after_call block_callback_strategy" do
586
- send "DoubleDefinition where #double_definition_creator is a Proxy"
587
- send "#any_number_of_times"
588
-
589
- describe "#subject.method_name being called" do
590
- it "returns the return value of the block" do
591
- @return_value.should == :new_return_value
592
- @args.should == [:original_return_value]
593
- end
594
- end
595
- end
596
- end
597
- end
598
-
599
- describe "#ordered" do
600
- macro "#ordered" do
601
- it "adds itself to the ordered doubles list" do
602
- definition.ordered
603
- RR::Space.instance.ordered_doubles.should include(double)
604
- end
605
-
606
- it "does not double_injection add itself" do
607
- definition.ordered
608
- RR::Space.instance.ordered_doubles.should == [double]
609
- end
610
-
611
- it "sets ordered? to true" do
612
- definition.should be_ordered
613
- end
614
-
615
- context "when there is no Double" do
616
- it "raises a DoubleDefinitionError" do
617
- definition.double = nil
618
- lambda do
619
- definition.ordered
620
- end.should raise_error(
621
- RR::Errors::DoubleDefinitionError,
622
- "Double Definitions must have a dedicated Double to be ordered. " <<
623
- "For example, using instance_of does not allow ordered to be used. " <<
624
- "proxy the class's #new method instead."
625
- )
626
- end
627
- end
628
- end
629
-
630
- context "when not passed a block" do
631
- before do
632
- definition.with(1, 2).once.ordered
633
- subject.foobar(1, 2)
634
- end
635
-
636
- send "#ordered"
637
- end
638
-
639
- context "when passed a block" do
640
- def call_double_injection
641
- actual_args = nil
642
- definition.with(1, 2).once.ordered do |*args|
643
- actual_args = args
644
- :new_return_value
645
- end
646
- @return_value = subject.foobar(1, 2)
647
- @args = actual_args
648
- end
649
-
650
- context "with returns block_callback_strategy" do
651
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
652
- send "#ordered"
653
-
654
- describe "#subject.method_name being called" do
655
- it "returns the return value of the block" do
656
- @return_value.should == :new_return_value
657
- @args.should == [1, 2]
658
- end
659
- end
660
- end
661
-
662
- context "with after_call block_callback_strategy" do
663
- send "DoubleDefinition where #double_definition_creator is a Proxy"
664
- send "#ordered"
665
-
666
- describe "#subject.method_name being called" do
667
- it "returns the return value of the block" do
668
- @return_value.should == :new_return_value
669
- @args.should == [:original_return_value]
670
- end
671
- end
672
- end
673
- end
674
- end
675
-
676
- describe "#yields" do
677
- macro "#yields" do
678
- it "returns DoubleDefinition" do
679
- definition.yields(:baz).should === definition
680
- end
681
-
682
- context "when there is a no returns value set" do
683
- it "yields the passed in argument to the call block" do
684
- @passed_in_block_arg.should == :baz
685
- end
686
- end
687
- end
688
-
689
- context "when not passed a block" do
690
- before do
691
- definition.with(1, 2).once.yields(:baz)
692
- passed_in_block_arg = nil
693
- subject.foobar(1, 2) do |arg|
694
- passed_in_block_arg = arg
695
- end
696
- @passed_in_block_arg = passed_in_block_arg
697
- end
698
-
699
- send "#yields"
700
- end
701
-
702
- context "when passed a block" do
703
- def call_double_injection
704
- actual_args = nil
705
- definition.with(1, 2).once.yields(:baz) do |*args|
706
- actual_args = args
707
- :new_return_value
708
- end
709
- passed_in_block_arg = nil
710
- @block = lambda do |arg|
711
- passed_in_block_arg = arg
712
- end
713
- @return_value = subject.foobar(1, 2, &@block)
714
- @passed_in_block_arg = passed_in_block_arg
715
-
716
- @args = actual_args
717
- end
718
-
719
- context "with returns block_callback_strategy" do
720
- send "DoubleDefinition where #double_definition_creator is a Reimplementation"
721
- send "#yields"
722
-
723
- describe "#subject.method_name being called" do
724
- it "returns the return value of the block" do
725
- @return_value.should == :new_return_value
726
- end
727
-
728
- it "passes an array of the args with the block appended as a RR::ProcFromBlock around the original block" do
729
- @args.length.should == 3
730
- @args[0..1].should == [1, 2]
731
- @args[2].should be_instance_of(RR::ProcFromBlock)
732
- @block.should == Proc.new(&@block)
733
- @args[2].should == @block
734
- end
735
- end
736
- end
737
-
738
- context "with after_call block_callback_strategy" do
739
- send "DoubleDefinition where #double_definition_creator is a Proxy"
740
- send "#yields"
741
-
742
- describe "#subject.method_name being called" do
743
- it "returns the return value of the block" do
744
- @return_value.should == :new_return_value
745
- @args.should == [:original_return_value]
746
- end
747
- end
748
- end
749
- end
750
- end
751
-
752
- describe "#after_call" do
753
- context "when passed a block" do
754
- it "returns DoubleDefinition" do
755
- definition.after_call {}.should === definition
756
- end
757
-
758
- describe "#subject.method_name being called" do
759
- it "calls the block with the return value of the implementation" do
760
- return_value = {:original => :value}
761
- definition.with_any_args.returns(return_value).after_call do |value|
762
- value[:foo] = :bar
763
- value
764
- end
765
-
766
- actual_value = subject.foobar
767
- actual_value.should === return_value
768
- actual_value.should == {:original => :value, :foo => :bar}
769
- end
770
-
771
- context "when the return value of the #after_call_proc is a DoubleDefinition" do
772
- it "returns the #subject of the DoubleDefinition" do
773
- return_value = Object.new
774
- inner_double_definition = nil
775
- definition.with_any_args.returns(return_value).after_call do |value|
776
- inner_double_definition = mock(value).inner_method(1) {:baz}
777
- end
778
-
779
- foobar_return_value = subject.foobar
780
- foobar_return_value.should == inner_double_definition.subject
781
- foobar_return_value.inner_method(1).should == :baz
782
- end
783
- end
784
-
785
- context "when the return value of the #after_call_proc is a DoubleDefinitionCreatorProxy" do
786
- it "returns the #__subject__ of the DoubleDefinitionCreatorProxy" do
787
- return_value = Object.new
788
- inner_double_proxy = nil
789
- definition.with_any_args.returns(return_value).after_call do |value|
790
- inner_double_proxy = mock(value)
791
- end
792
-
793
- foobar_return_value = subject.foobar
794
- foobar_return_value.should == inner_double_proxy.__creator__.subject
795
- end
796
- end
797
-
798
- context "when the return value of the #after_call_proc is an Object" do
799
- it "returns the return value of the #after_call_proc" do
800
- return_value = :returns_value
801
- definition.with_any_args.returns(return_value).after_call do |value|
802
- :after_call_proc
803
- end
804
-
805
- actual_value = subject.foobar
806
- actual_value.should == :after_call_proc
807
- end
808
- end
809
- end
810
- end
811
-
812
- context "when not passed a block" do
813
- it "raises an ArgumentError" do
814
- lambda do
815
- definition.after_call
816
- end.should raise_error(ArgumentError, "after_call expects a block")
817
- end
818
- end
819
- end
820
-
821
- describe "#returns" do
822
- it "returns DoubleDefinition" do
823
- definition.returns {:baz}.should === definition
824
- definition.returns(:baz).should === definition
825
- end
826
-
827
- context "when passed neither an argument nor a block" do
828
- describe "#subject.method_name being called" do
829
- it "returns nil" do
830
- definition.with_any_args.returns
831
- subject.foobar.should be_nil
832
- end
833
- end
834
- end
835
-
836
- context "when passed a block" do
837
- describe "#subject.method_name being called" do
838
- it "returns the return value of the block" do
839
- definition.with_any_args.returns {:baz}
840
- subject.foobar.should == :baz
841
- end
842
- end
843
- end
844
-
845
- context "when passed an argument" do
846
- describe "#subject.method_name being called" do
847
- it "returns the passed-in argument" do
848
- definition.returns(:baz).with_no_args
849
- subject.foobar.should == :baz
850
- end
851
- end
852
-
853
- context "when the argument is false" do
854
- describe "#subject.method_name being called" do
855
- it "returns false" do
856
- definition.returns(false).with_any_args
857
- subject.foobar.should == false
858
- end
859
- end
860
- end
861
- end
862
-
863
- context "when passed both an argument and a block" do
864
- it "raises an error" do
865
- lambda do
866
- definition.returns(:baz) {:another}
867
- end.should raise_error(ArgumentError, "returns cannot accept both an argument and a block")
868
- end
869
- end
870
- end
871
-
872
- describe "#implemented_by" do
873
- it "returns the DoubleDefinition" do
874
- definition.implemented_by(lambda{:baz}).should === definition
875
- end
876
-
877
- context "when passed a Proc" do
878
- describe "#subject.method_name being called" do
879
- it "returns the return value of the passed-in Proc" do
880
- definition.implemented_by(lambda{:baz}).with_no_args
881
- subject.foobar.should == :baz
882
- end
883
- end
884
- end
885
-
886
- context "when passed a Method" do
887
- it "sets the implementation to the passed in method" do
888
- class << subject
889
- remove_method :foobar
890
- def foobar(a, b)
891
- [b, a]
892
- end
893
- end
894
- definition.implemented_by(subject.method(:foobar))
895
- subject.foobar(1, 2).should == [2, 1]
896
- end
897
- end
898
- end
899
-
900
- describe "#verbose" do
901
- it "sets the verbose? to true" do
902
- definition.should_not be_verbose
903
- definition.verbose
904
- definition.should be_verbose
905
- end
906
- end
907
-
908
- describe "#verify_method_signature" do
909
- it "sets #verify_method_signature? to true" do
910
- definition.verify_method_signature?.should be_false
911
- definition.verify_method_signature
912
- definition.verify_method_signature?.should be_true
913
- end
914
-
915
- it "returns self" do
916
- definition.verify_method_signature.should == definition
917
- end
918
- end
919
- end
920
-
921
- describe "NestedDoubleCreationMethods" do
922
- attr_reader :child_double_definition_creator
923
- after do
924
- RR.verify(ChildDoubleDefinitionCreator)
925
- RR.verify(child_double_definition_creator)
926
- end
927
-
928
- describe "#mock" do
929
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #mock method with the passed-in arguments and block" do
930
- child_subject = Object.new
931
- child_double_definition_creator = nil
932
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
933
- mock.proxy(child_double_definition_creator).mock(child_subject, :baz)
934
- child_double_definition_creator = child_double_definition_creator
935
- end
936
-
937
- definition.mock(child_subject, :baz)
938
- @child_double_definition_creator = child_double_definition_creator
939
- end
940
- end
941
-
942
- describe "#mock!" do
943
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #mock! method with the passed-in arguments and block" do
944
- child_double_definition_creator = nil
945
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
946
- mock.proxy(child_double_definition_creator).mock!(:baz)
947
- child_double_definition_creator = child_double_definition_creator
948
- end
949
-
950
- definition.mock!(:baz)
951
- @child_double_definition_creator = child_double_definition_creator
952
- end
953
- end
954
-
955
- describe "#stub" do
956
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #stub method with the passed-in arguments and block" do
957
- child_subject = Object.new
958
- child_double_definition_creator = nil
959
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
960
- mock.proxy(child_double_definition_creator).stub(child_subject, :baz)
961
- child_double_definition_creator = child_double_definition_creator
962
- end
963
-
964
- definition.stub(child_subject, :baz)
965
- @child_double_definition_creator = child_double_definition_creator
966
- end
967
- end
968
-
969
- describe "#stub!" do
970
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #stub! method with the passed-in arguments and block" do
971
- child_double_definition_creator = nil
972
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
973
- mock.proxy(child_double_definition_creator).stub!(:baz)
974
- child_double_definition_creator = child_double_definition_creator
975
- end
976
-
977
- definition.stub!(:baz)
978
- @child_double_definition_creator = child_double_definition_creator
979
- end
980
- end
981
-
982
- describe "#dont_allow" do
983
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #dont_allow method with the passed-in arguments and block" do
984
- child_subject = Object.new
985
- child_double_definition_creator = nil
986
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
987
- mock.proxy(child_double_definition_creator).dont_allow(child_subject, :baz)
988
- child_double_definition_creator = child_double_definition_creator
989
- end
990
-
991
- definition.dont_allow(child_subject, :baz)
992
- @child_double_definition_creator = child_double_definition_creator
993
- end
994
- end
995
-
996
- describe "#dont_allow!" do
997
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #dont_allow! method with the passed-in arguments and block" do
998
- child_double_definition_creator = nil
999
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
1000
- mock.proxy(child_double_definition_creator).dont_allow!(:baz)
1001
- child_double_definition_creator = child_double_definition_creator
1002
- end
1003
-
1004
- definition.dont_allow!(:baz)
1005
- @child_double_definition_creator = child_double_definition_creator
1006
- end
1007
- end
1008
-
1009
- describe "#proxy" do
1010
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #proxy method with the passed-in arguments and block" do
1011
- child_subject = Object.new
1012
- child_double_definition_creator = nil
1013
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
1014
- mock.proxy(child_double_definition_creator).proxy(DoubleDefinitionCreator::NO_SUBJECT, nil)
1015
- child_double_definition_creator = child_double_definition_creator
1016
- end
1017
-
1018
- definition.proxy.mock(child_subject)
1019
- @child_double_definition_creator = child_double_definition_creator
1020
- end
1021
- end
1022
-
1023
- describe "#proxy!" do
1024
- it "raises a DoubleDefinitionError" do
1025
- lambda do
1026
- definition.proxy!(:baz)
1027
- end.should raise_error(RR::Errors::DoubleDefinitionError)
1028
- end
1029
- end
1030
-
1031
- describe "#strong" do
1032
- it "instantiates a ChildDoubleDefinitionCreator with self and delegates to its #strong method with the passed-in arguments and block" do
1033
- child_subject = Object.new
1034
- child_double_definition_creator = nil
1035
- mock.proxy(ChildDoubleDefinitionCreator).new(definition) do |child_double_definition_creator|
1036
- mock.proxy(child_double_definition_creator).strong(DoubleDefinitionCreator::NO_SUBJECT, nil)
1037
- child_double_definition_creator = child_double_definition_creator
1038
- end
1039
-
1040
- definition.strong.mock(child_subject)
1041
- @child_double_definition_creator = child_double_definition_creator
1042
- end
1043
- end
1044
-
1045
- describe "#strong!" do
1046
- it "raises a DoubleDefinitionError" do
1047
- lambda do
1048
- definition.strong!(:baz)
1049
- end.should raise_error(RR::Errors::DoubleDefinitionError)
1050
- end
1051
- end
1052
- end
1053
-
1054
- describe "StateQueryMethods" do
1055
- describe "#ordered?" do
1056
- it "defaults to false" do
1057
- definition.should_not be_ordered
1058
- end
1059
- end
1060
-
1061
- describe "#exact_match?" do
1062
- context "when no argument_expectation set" do
1063
- it "raises a DoubleDefinitionError" do
1064
- definition.argument_expectation = nil
1065
- lambda do
1066
- definition.exact_match?
1067
- end.should raise_error(RR::Errors::DoubleDefinitionError)
1068
- end
1069
- end
1070
-
1071
- context "when arguments are not an exact match" do
1072
- it "returns false" do
1073
- definition.with(1, 2, 3)
1074
- definition.should_not be_exact_match(1, 2)
1075
- definition.should_not be_exact_match(1)
1076
- definition.should_not be_exact_match()
1077
- definition.should_not be_exact_match("does not match")
1078
- end
1079
- end
1080
-
1081
- context "when arguments are an exact match" do
1082
- it "returns true" do
1083
- definition.with(1, 2, 3)
1084
- definition.should be_exact_match(1, 2, 3)
1085
- end
1086
- end
1087
- end
1088
-
1089
- describe "#wildcard_match?" do
1090
- context "when no #argument_expectation is set" do
1091
- it "raises a DoubleDefinitionError" do
1092
- definition.argument_expectation = nil
1093
- lambda do
1094
- definition.wildcard_match?
1095
- end.should raise_error(RR::Errors::DoubleDefinitionError)
1096
- end
1097
- end
1098
-
1099
- context "when arguments are an exact match" do
1100
- it "returns true" do
1101
- definition.with(1, 2, 3)
1102
- definition.should be_wildcard_match(1, 2, 3)
1103
- definition.should_not be_wildcard_match(1, 2)
1104
- definition.should_not be_wildcard_match(1)
1105
- definition.should_not be_wildcard_match()
1106
- definition.should_not be_wildcard_match("does not match")
1107
- end
1108
- end
1109
-
1110
- context "when with_any_args" do
1111
- it "returns true" do
1112
- definition.with_any_args
1113
-
1114
- definition.should be_wildcard_match(1, 2, 3)
1115
- definition.should be_wildcard_match(1, 2)
1116
- definition.should be_wildcard_match(1)
1117
- definition.should be_wildcard_match()
1118
- definition.should be_wildcard_match("does not match")
1119
- end
1120
- end
1121
- end
1122
-
1123
- describe "#terminal?" do
1124
- context "when times_matcher's terminal? is true" do
1125
- it "returns true" do
1126
- definition.once
1127
- definition.times_matcher.should be_terminal
1128
- definition.should be_terminal
1129
- end
1130
- end
1131
-
1132
- context "when times_matcher's terminal? is false" do
1133
- it "returns false" do
1134
- definition.any_number_of_times
1135
- definition.times_matcher.should_not be_terminal
1136
- definition.should_not be_terminal
1137
- end
1138
- end
1139
-
1140
- context "when there is not times_matcher" do
1141
- it "raises a DoubleDefinitionError" do
1142
- definition.times_matcher = nil
1143
- lambda do
1144
- definition.terminal?
1145
- end.should raise_error(RR::Errors::DoubleDefinitionError)
1146
- end
1147
- end
1148
- end
1149
-
1150
- describe "#expected_arguments" do
1151
- context "when there is a argument expectation" do
1152
- it "returns argument expectation's expected_arguments" do
1153
- definition.with(1, 2)
1154
- definition.expected_arguments.should == [1, 2]
1155
- end
1156
- end
1157
-
1158
- context "when there is no argument expectation" do
1159
- it "returns an empty array" do
1160
- definition.argument_expectation = nil
1161
- definition.expected_arguments.should == []
1162
- end
1163
- end
1164
- end
1165
- end
1166
- end
1167
- end
1168
- end